encoding

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 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 (
	// 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
)
View Source
const Version = uint16(0)

Version captures the maximum version of encoding that this code supports in other words this code encodes the data with the latest version and can only decode data with version smaller or equal to this value bumping this number prevents older versions of the code to deal with the newer version of data codes should be updated with backward compatibility if needed

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) (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 DecodePath

func DecodePath(encodedPath []byte) (ledger.Path, error)

DecodePath constructs a path value using an encoded byte slice

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) (*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) []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 EncodePath

func EncodePath(p ledger.Path) []byte

EncodePath encodes a path 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) 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