encoder

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

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 NewBufferPool

func NewBufferPool() *BufferPool

NewBufferPool returns a new *BufferPool.

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

type CompressorEntry struct {
	Namespace      string
	DictionaryPath string
}

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

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

func (e *Encoder) DecodeRaw(namespace string, input []byte) ([]byte, error)

DecodeRaw only decompresses an input, leaving decoding to the caller. This is particularly useful for training a compressor.

func (*Encoder) Encode

func (e *Encoder) Encode(namespace string, object interface{}) ([]byte, error)

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

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.

func (*Encoder) EncodeRaw

func (e *Encoder) EncodeRaw(namespace string, input []byte) ([]byte, error)

EncodeRaw only compresses an input, leaving encoding to the caller. This is particularly useful for training a compressor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL