Documentation ¶
Overview ¶
Package encoding provides byte serialization and deserialization of trie and ledger structs.
Index ¶
- Constants
- func CheckType(rawInput []byte, expectedType uint8) (rest []byte, err error)
- func CheckVersion(rawInput []byte, maxVersion uint16) (rest []byte, version uint16, err error)
- func DecodeKey(encodedKey []byte) (*ledger.Key, error)
- func DecodeKeyPart(encodedKeyPart []byte) (*ledger.KeyPart, error)
- func DecodePayload(encodedPayload []byte) (*ledger.Payload, error)
- func DecodePayloadWithoutPrefix(encodedPayload []byte, zeroCopy bool, version uint16) (*ledger.Payload, error)
- func DecodeTrieBatchProof(encodedBatchProof []byte) (*ledger.TrieBatchProof, error)
- func DecodeTrieProof(encodedProof []byte) (*ledger.TrieProof, error)
- func DecodeTrieUpdate(encodedTrieUpdate []byte) (*ledger.TrieUpdate, error)
- func DecodeValue(encodedValue []byte) (ledger.Value, error)
- func EncodeAndAppendPayloadWithoutPrefix(buffer []byte, p *ledger.Payload, version uint16) []byte
- func EncodeKey(k *ledger.Key) []byte
- func EncodeKeyPart(kp *ledger.KeyPart) []byte
- func EncodePayload(p *ledger.Payload) []byte
- func EncodeTrieBatchProof(bp *ledger.TrieBatchProof) []byte
- func EncodeTrieProof(p *ledger.TrieProof) []byte
- func EncodeTrieUpdate(t *ledger.TrieUpdate) []byte
- func EncodeValue(v ledger.Value) []byte
- func EncodedPayloadLengthWithoutPrefix(p *ledger.Payload, version uint16) int
- type Type
Constants ¶
const ( PayloadVersion = uint16(1) TrieUpdateVersion = uint16(0) // Use payload version 0 encoding TrieProofVersion = uint16(0) // Use payload version 0 encoding TrieBatchProofVersion = uint16(0) // Use payload version 0 encoding )
Versions capture the maximum version of encoding this code supports. I.e. this code encodes data with the latest version and only decodes data with version smaller or equal to these versions. Bumping a version number prevents older versions of code from handling the newer version of data. New code handling new data version should be updated to also support backward compatibility if needed.
const ( // TypeUnknown - unknown type TypeUnknown = iota // TypeState - type for State TypeState // TypeKeyPart - type for KeyParts (a subset of key) TypeKeyPart // TypeKey - type for Keys (unique identifier to reference a location in ledger) TypeKey // TypeValue - type for Ledger Values TypeValue // TypePath - type for Paths (trie storage location of a key value pair) TypePath // TypePayload - type for Payloads (stored at trie nodes including key value pair ) TypePayload // TypeProof type for Proofs // (all data needed to verify a key value pair at specific state) TypeProof // TypeBatchProof - type for BatchProofs TypeBatchProof // TypeQuery - type for ledger query TypeQuery // TypeUpdate - type for ledger update TypeUpdate // TypeTrieUpdate - type for trie update TypeTrieUpdate )
Variables ¶
This section is empty.
Functions ¶
func CheckType ¶
CheckType extracts encoding byte from a raw encoded message checks it against expected type and returns the rest of rawInput (excluding type byte)
func CheckVersion ¶
CheckVersion extracts encoding bytes from a raw encoded message checks it against the supported versions and returns the rest of rawInput (excluding encDecVersion bytes)
func DecodeKeyPart ¶
DecodeKeyPart constructs a key part from an encoded key part
func DecodePayload ¶
DecodePayload construct a payload from an encoded byte slice
func DecodePayloadWithoutPrefix ¶ added in v0.25.0
func DecodePayloadWithoutPrefix(encodedPayload []byte, zeroCopy bool, version uint16) (*ledger.Payload, error)
DecodePayloadWithoutPrefix constructs a payload from encoded byte slice without prefix (version and type). If zeroCopy is true, returned payload references data in encodedPayload. Otherwise, it is copied.
func DecodeTrieBatchProof ¶
func DecodeTrieBatchProof(encodedBatchProof []byte) (*ledger.TrieBatchProof, error)
DecodeTrieBatchProof constructs a batch proof from an encoded byte slice
func DecodeTrieProof ¶
DecodeTrieProof construct a proof from an encoded byte slice
func DecodeTrieUpdate ¶
func DecodeTrieUpdate(encodedTrieUpdate []byte) (*ledger.TrieUpdate, error)
DecodeTrieUpdate construct a trie update from an encoded byte slice
func DecodeValue ¶
DecodeValue constructs a ledger value using an encoded byte slice
func EncodeAndAppendPayloadWithoutPrefix ¶ added in v0.25.0
EncodeAndAppendPayloadWithoutPrefix encodes a ledger payload without prefix (version and type) and appends to buffer. If payload is nil, unmodified buffer is returned.
func EncodeKeyPart ¶
EncodeKeyPart encodes a key part into a byte slice
func EncodePayload ¶
EncodePayload encodes a ledger payload
func EncodeTrieBatchProof ¶
func EncodeTrieBatchProof(bp *ledger.TrieBatchProof) []byte
EncodeTrieBatchProof encodes a batch proof into a byte slice
func EncodeTrieProof ¶
EncodeTrieProof encodes the content of a proof into a byte slice
func EncodeTrieUpdate ¶
func EncodeTrieUpdate(t *ledger.TrieUpdate) []byte
EncodeTrieUpdate encodes a trie update struct
func EncodeValue ¶
EncodeValue encodes a value into a byte slice