encoding

package
v0.26.17-access-fix-dy... Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package encoding provides byte serialization and deserialization of trie and ledger structs.

Index

Constants

View Source
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.

View Source
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

func CheckType(rawInput []byte, expectedType uint8) (rest []byte, err error)

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

func CheckVersion(rawInput []byte, maxVersion uint16) (rest []byte, version uint16, err error)

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 DecodeKey

func DecodeKey(encodedKey []byte) (*ledger.Key, error)

DecodeKey constructs a key from an encoded key part

func DecodeKeyPart

func DecodeKeyPart(encodedKeyPart []byte) (*ledger.KeyPart, error)

DecodeKeyPart constructs a key part from an encoded key part

func DecodePayload

func DecodePayload(encodedPayload []byte) (*ledger.Payload, error)

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

func DecodeTrieProof(encodedProof []byte) (*ledger.TrieProof, error)

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

func DecodeValue(encodedValue []byte) (ledger.Value, error)

DecodeValue constructs a ledger value using an encoded byte slice

func EncodeAndAppendPayloadWithoutPrefix added in v0.25.0

func EncodeAndAppendPayloadWithoutPrefix(buffer []byte, p *ledger.Payload, version uint16) []byte

EncodeAndAppendPayloadWithoutPrefix encodes a ledger payload without prefix (version and type) and appends to buffer. If payload is nil, unmodified buffer is returned.

func EncodeKey

func EncodeKey(k *ledger.Key) []byte

EncodeKey encodes a key into a byte slice

func EncodeKeyPart

func EncodeKeyPart(kp *ledger.KeyPart) []byte

EncodeKeyPart encodes a key part into a byte slice

func EncodePayload

func EncodePayload(p *ledger.Payload) []byte

EncodePayload encodes a ledger payload

func EncodeTrieBatchProof

func EncodeTrieBatchProof(bp *ledger.TrieBatchProof) []byte

EncodeTrieBatchProof encodes a batch proof into a byte slice

func EncodeTrieProof

func EncodeTrieProof(p *ledger.TrieProof) []byte

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

func EncodeValue(v ledger.Value) []byte

EncodeValue encodes a value into a byte slice

func EncodedPayloadLengthWithoutPrefix added in v0.25.0

func EncodedPayloadLengthWithoutPrefix(p *ledger.Payload, version uint16) int

Types

type Type

type Type uint8

Type capture the type of encoded entity (e.g. State, Key, Value, Path)

func (Type) String

func (e Type) String() string

Jump to

Keyboard shortcuts

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