Documentation
¶
Overview ¶
Package store provides default implementations for stores.Store.
It exposes a Store type to pack JSON values in memory.
An additional ConcurrentStore implementation supports concurrent access using ConcurrentStore.Get and [ConcurrentStore.Put].
The VerbatimStore implements stores.VerbatimStore, to allow users to keep non-significant blank space and reconstruct JSON documents verbatim.
Index ¶
- Constants
- func RedeemStore(s *Store)
- type CompressionOption
- type ConcurrentStore
- func (s *ConcurrentStore) Get(h stores.Handle) values.Value
- func (s *ConcurrentStore) Len() int
- func (s *ConcurrentStore) PutToken(tok token.T) stores.Handle
- func (s *ConcurrentStore) PutValue(v values.Value) stores.Handle
- func (s *ConcurrentStore) WriteTo(writer writers.StoreWriter, h stores.Handle)
- type Option
- type Store
- func (s *Store) Get(h stores.Handle) values.Value
- func (s *Store) Len() int
- func (s Store) MarshalBinary() ([]byte, error)
- func (s *Store) PutBool(b bool) stores.Handle
- func (s *Store) PutNull() stores.Handle
- func (s *Store) PutToken(tok token.T) stores.Handle
- func (s *Store) PutValue(v values.Value) stores.Handle
- func (s *Store) Reset()
- func (s *Store) UnmarshalBinary(data []byte) error
- func (s *Store) WriteTo(writer writers.StoreWriter, h stores.Handle)
- type VerbatimStore
- func (s *VerbatimStore) Get(h stores.Handle) values.Value
- func (s *VerbatimStore) GetVerbatim(h stores.VerbatimHandle) values.VerbatimValue
- func (s *VerbatimStore) PutBlanks(blanks []byte) stores.Handle
- func (s *VerbatimStore) PutVerbatimToken(tok token.VT) stores.VerbatimHandle
- func (s *VerbatimStore) PutVerbatimValue(v values.VerbatimValue) stores.VerbatimHandle
- func (s *VerbatimStore) Reset()
- func (s *VerbatimStore) WriteTo(writer writers.StoreWriter, h stores.Handle)
Constants ¶
const ErrStore storeError = "json document store error"
Variables ¶
This section is empty.
Functions ¶
func RedeemStore ¶
func RedeemStore(s *Store)
RedeemStore redeems a previously borrowed Store to the pool.
Types ¶
type CompressionOption ¶
type CompressionOption = func(*compressionOptions)
CompressionOption alter default settings from string compression inside the Store.
func WithCompressionLevel ¶
func WithCompressionLevel(level int) CompressionOption
func WithCompressionThreshold ¶
func WithCompressionThreshold(threshold int) CompressionOption
type ConcurrentStore ¶
type ConcurrentStore struct {
*Store
// contains filtered or unexported fields
}
ConcurrentStore is a stores.Store just like Store and may be used concurrently.
Concurrency ¶
It safe to retrieve values concurrently with store.Get, and have several go routines storing content concurrently.
Although it is safe to use store.WriteTo concurrently, it should not be used that way, as the result is not deterministic.
func NewConcurrent ¶
func NewConcurrent(opts ...Option) *ConcurrentStore
func (*ConcurrentStore) Get ¶
func (s *ConcurrentStore) Get(h stores.Handle) values.Value
Get a values.Value from a stores.Handle.
func (*ConcurrentStore) Len ¶
func (s *ConcurrentStore) Len() int
Len returns the current size in bytes of the inner memory arena.
func (*ConcurrentStore) PutToken ¶
func (s *ConcurrentStore) PutToken(tok token.T) stores.Handle
PutToken puts a value inside a token.T and returns its stores.Handle for later retrieval.
func (*ConcurrentStore) PutValue ¶
func (s *ConcurrentStore) PutValue(v values.Value) stores.Handle
PutValue puts a values.Value and returns its stores.Handle for later retrieval.
func (*ConcurrentStore) WriteTo ¶
func (s *ConcurrentStore) WriteTo(writer writers.StoreWriter, h stores.Handle)
WriteTo writes the value pointed to be the stores.Handle to a JSON writers.StoreWriter.
This avoids unnessary allocations when transferring the value to the writer.
type Option ¶
type Option = func(*options)
Option alters the default settings of a store (Store, ConcurrentStore or VerbatimStore).
func WithArenaSize ¶
WithArenaSize sets the initial capacity of the inner arena that stores large values.
func WithBytesFactory ¶
WithBytesFactory affects how Get allocates the returned buffer.
func WithCompressionOptions ¶
func WithCompressionOptions(opts ...CompressionOption) Option
func WithEnableCompression ¶
WithEnableCompression enables compression of long strings in the Store.
Compression is enabled by default and uses the DEFLATE compression method implemented by the standard library package compress/flate.
By default, compression kicks in for strings longer than 128 bytes.
The default compression level is [flate.DefaultCompression), which corresponds to a compression level of 6.
Compression may be disabled or altered using WithCompressionOptions with some CompressionOption s.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the default implementation for stores.Store.
It acts an in-memory store for JSON values, with an emphasis on compactness.
Concurrency ¶
It safe to retrieve values concurrently with store.Get, but it is unsafe to have several go routines storing content concurrently.
store.WriteTo should not be used concurrently.
func BorrowStore ¶
BorrowStore borrows a new or recycled Store from the pool.
func (*Store) Get ¶
Get a values.Value from a stores.Handle.
func (Store) MarshalBinary ¶
func (*Store) PutNull ¶
PutNull is a shorthand for putting a null value. The returned stores.Handle is always 0.
func (*Store) PutToken ¶
PutToken puts a value inside a token.T and returns its stores.Handle for later retrieval.
func (*Store) PutValue ¶
PutValue puts a values.Value and returns its stores.Handle for later retrieval.
func (*Store) Reset ¶
func (s *Store) Reset()
Reset the Store to its initial state.
This is useful to recycle Store s from a memory pool.
Implements pools.Resettable.
func (*Store) UnmarshalBinary ¶
func (*Store) WriteTo ¶
func (s *Store) WriteTo(writer writers.StoreWriter, h stores.Handle)
WriteTo writes the value pointed to be the stores.Handle to a JSON writers.StoreWriter.
This avoids unnessary buffering when transferring the value down to the writer.
type VerbatimStore ¶
type VerbatimStore struct {
*Store
// contains filtered or unexported fields
}
VerbatimStore is like Store, but with the ability to store and retrieve non-significant blank space, such as indentation, space before commas, line feeds, etc.
This stores.VerbatimStore is designed to hold and reconstruct verbatim JSON documents. It not safe to use concurrently.
JSON blanks ¶
Valid blank space characters in JSON are: blank, tab, carriageReturn and lineFeed.
The generalized notion of blank space in unicode does not apply (e.g. with unicode property "WSpace = Y") and should result in invalid tokens when parsing your JSON.
func NewVerbatim ¶
func NewVerbatim(opts ...Option) *VerbatimStore
func (*VerbatimStore) Get ¶
func (s *VerbatimStore) Get(h stores.Handle) values.Value
Get a values.Value from a stores.Handle.
func (*VerbatimStore) GetVerbatim ¶
func (s *VerbatimStore) GetVerbatim(h stores.VerbatimHandle) values.VerbatimValue
func (*VerbatimStore) PutVerbatimToken ¶
func (s *VerbatimStore) PutVerbatimToken(tok token.VT) stores.VerbatimHandle
func (*VerbatimStore) PutVerbatimValue ¶
func (s *VerbatimStore) PutVerbatimValue(v values.VerbatimValue) stores.VerbatimHandle
func (*VerbatimStore) Reset ¶
func (s *VerbatimStore) Reset()
Reset the store so it can be recycled. Implements pools.Resettable.
func (*VerbatimStore) WriteTo ¶
func (s *VerbatimStore) WriteTo(writer writers.StoreWriter, h stores.Handle)