Documentation ¶
Index ¶
- func CopyStruct(input interface{}, output interface{}) error
- type BufferPool
- type CompressorEntry
- type Encoder
- func (e *Encoder) Decode(namespace string, input []byte, object interface{}, reclaimInput bool) error
- func (e *Encoder) DecodeAccountCoin(b []byte, accountCoin *types.AccountCoin, reclaimInput bool) error
- func (e *Encoder) DecodeAccountCurrency(b []byte, accountCurrency *types.AccountCurrency, reclaimInput bool) error
- func (e *Encoder) DecodeRaw(namespace string, input []byte) ([]byte, error)
- func (e *Encoder) Encode(namespace string, object interface{}) ([]byte, error)
- func (e *Encoder) EncodeAccountCoin(accountCoin *types.AccountCoin) ([]byte, error)
- func (e *Encoder) EncodeAccountCurrency(accountCurrency *types.AccountCurrency) ([]byte, error)
- func (e *Encoder) EncodeRaw(namespace string, input []byte) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyStruct ¶
func CopyStruct(input interface{}, output interface{}) error
CopyStruct performs a deep copy of an entire struct using its JSON representation.
Types ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool contains a sync.Pool of *bytes.Buffer.
func (*BufferPool) Get ¶
func (p *BufferPool) Get() *bytes.Buffer
Get returns a new or reused *bytes.Buffer.
func (*BufferPool) Put ¶
func (p *BufferPool) Put(buffer *bytes.Buffer)
Put resets the provided *bytes.Buffer and stores it in the pool for reuse.
func (*BufferPool) PutByteSlice ¶
func (p *BufferPool) PutByteSlice(buffer []byte)
PutByteSlice creates a *bytes.Buffer from the provided []byte and stores it in the pool for reuse.
type CompressorEntry ¶
CompressorEntry is used to initialize a dictionary compression. All DictionaryPaths are loaded from disk at initialization.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder handles the encoding/decoding of structs and the compression/decompression of data using zstd. Optionally, the caller can provide a map of dicts on initialization that can be used by zstd. You can read more about these "dicts" here: https://github.com/facebook/zstd#the-case-for-small-data-compression.
NOTE: If you change these dicts, you will not be able to decode previously encoded data. For many users, providing no dicts is sufficient!
func NewEncoder ¶
func NewEncoder( entries []*CompressorEntry, pool *BufferPool, compress bool, ) (*Encoder, error)
NewEncoder returns a new *Encoder. The dicts provided should contain k:v of namespace:zstd dict.
func (*Encoder) Decode ¶
func (e *Encoder) Decode( namespace string, input []byte, object interface{}, reclaimInput bool, ) error
Decode attempts to decompress the object and will use a dict if one exists for the namespace.
func (*Encoder) DecodeAccountCoin ¶
func (e *Encoder) DecodeAccountCoin( b []byte, accountCoin *types.AccountCoin, reclaimInput bool, ) error
DecodeAccountCoin decodes an AccountCoin and optionally reclaims the memory associated with the input.
func (*Encoder) DecodeAccountCurrency ¶ added in v0.6.5
func (e *Encoder) DecodeAccountCurrency( b []byte, accountCurrency *types.AccountCurrency, reclaimInput bool, ) error
DecodeAccountCurrency decodes an AccountCurrency and optionally reclaims the memory associated with the input.
func (*Encoder) DecodeRaw ¶
DecodeRaw only decompresses an input, leaving decoding to the caller. This is particularly useful for training a compressor.
func (*Encoder) Encode ¶
Encode attempts to compress the object and will use a dict if one exists for the namespace.
func (*Encoder) EncodeAccountCoin ¶
func (e *Encoder) EncodeAccountCoin( accountCoin *types.AccountCoin, ) ([]byte, error)
EncodeAccountCoin is used to encode an *AccountCoin using the scheme (on the happy path): accountAddress|coinIdentifier|amountValue|amountCurrencySymbol| amountCurrencyDecimals
And the following scheme on the unhappy path: accountAddress|coinIdentifier|amountValue|amountCurrencySymbol| amountCurrencyDecimals|accountMetadata|subAccountAddress| subAccountMetadata|amountMetadata|currencyMetadata
In both cases, the | character is represented by the unicodeRecordSeparator rune.
func (*Encoder) EncodeAccountCurrency ¶ added in v0.6.5
func (e *Encoder) EncodeAccountCurrency( accountCurrency *types.AccountCurrency, ) ([]byte, error)
EncodeAccountCurrency is used to encode an AccountCurrency using the scheme (on the happy path): accountAddress|currencySymbol|currencyDecimals
And the following scheme on the unhappy path: accountAddress|currencySymbol|currencyDecimals|accountMetadata| subAccountAddress|subAccountMetadata|currencyMetadata
In both cases, the | character is represented by the unicodeRecordSeparator rune.