scale

package
v2.0.0-...-042c2b7 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

nolint

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decodeable

type Decodeable interface {
	// ParityDecode populates this structure from a stream (overwriting the current contents), return false on failure
	Decode(decoder Decoder) error
}

Decodeable is an interface that defines a custom encoding rules for a data type. Should be defined for pointers to structs. See OptionBool for an example implementation.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder is a wraper around a Reader that allows decoding data items from a stream.

func NewDecoder

func NewDecoder(reader io.Reader) *Decoder

func (Decoder) Decode

func (pd Decoder) Decode(target interface{}) error

Decode takes a pointer to a decodable value and populates it from the stream.

func (Decoder) DecodeIntoReflectValue

func (pd Decoder) DecodeIntoReflectValue(target reflect.Value) error

DecodeIntoReflectValue populates a writable reflect.Value from the stream

func (Decoder) DecodeOption

func (pd Decoder) DecodeOption(hasValue *bool, valuePointer interface{}) error

DecodeOption decodes a optionally available value into a boolean presence field and a value.

func (Decoder) DecodeUintCompact

func (pd Decoder) DecodeUintCompact() (*big.Int, error)

DecodeUintCompact decodes a compact-encoded integer. See EncodeUintCompact method.

func (Decoder) Read

func (pd Decoder) Read(bytes []byte) error

Read reads bytes from a stream into a buffer

func (Decoder) ReadOneByte

func (pd Decoder) ReadOneByte() (byte, error)

ReadOneByte reads a next byte from the stream. Named so to avoid a linter warning about a clash with io.ByteReader.ReadByte

type Encodeable

type Encodeable interface {
	// ParityEncode encodes and write this structure into a stream
	Encode(encoder Encoder) error
}

Encodeable is an interface that defines a custom encoding rules for a data type. Should be defined for structs (not pointers to them). See OptionBool for an example implementation.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder is a wrapper around a Writer that allows encoding data items to a stream. Allows passing encoding options

func NewEncoder

func NewEncoder(writer io.Writer) *Encoder

func (Encoder) Encode

func (pe Encoder) Encode(value interface{}) error

Encode a value to the stream.

func (Encoder) EncodeOption

func (pe Encoder) EncodeOption(hasValue bool, value interface{}) error

EncodeOption stores optionally present value to the stream.

func (Encoder) EncodeUintCompact

func (pe Encoder) EncodeUintCompact(v big.Int) error

EncodeUintCompact writes an unsigned integer to the stream using the compact encoding. A typical usage is storing the length of a collection. Definition of compact encoding: 0b00 00 00 00 / 00 00 00 00 / 00 00 00 00 / 00 00 00 00

xx xx xx 00															(0 ... 2**6 - 1)		(u8)
yL yL yL 01 / yH yH yH yL												(2**6 ... 2**14 - 1)	(u8, u16)  low LH high
zL zL zL 10 / zM zM zM zL / zM zM zM zM / zH zH zH zM					(2**14 ... 2**30 - 1)	(u16, u32)  low LMMH high
nn nn nn 11 [ / zz zz zz zz ]{4 + n}									(2**30 ... 2**536 - 1)	(u32, u64, u128, U256, U512, U520) straight LE-encoded

Rust implementation: see impl<'a> Encode for CompactRef<'a, u64>

func (Encoder) PushByte

func (pe Encoder) PushByte(b byte) error

PushByte writes a single byte to an encoder.

func (Encoder) Write

func (pe Encoder) Write(bytes []byte) error

Write several bytes to the encoder.

Jump to

Keyboard shortcuts

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