codec

package
v1.5.0-alpha.4-nomain Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrShortRead = errors.New("decode from buffer: not all bytes were consumed")

Functions

func Decode

func Decode(buf []byte, value Decodable) error

Decode value from a byte buffer.

func DecodeByteSlice

func DecodeByteSlice(r io.Reader) ([]byte, int, error)

DecodeByteSlice decodes []string from an io.Reader.

func DecodeCompact16

func DecodeCompact16(r io.Reader) (uint16, int, error)

DecodeCompact16 decodes uint16 from an io.Reader.

func DecodeFrom

func DecodeFrom(r io.Reader, value Decodable) (int, error)

DecodeFrom decodes a value using data from a reader stream.

func DecodeLen added in v1.4.1

func DecodeLen(r io.Reader) (uint32, int, error)

DecodeLen decodes a length value from an io.Reader.

func DecodeSlice

func DecodeSlice[V any, H scale.DecodablePtr[V]](buf []byte) ([]V, error)

DecodeSlice decodes slice from a buffer.

func DecodeSliceFromReader added in v1.4.3

func DecodeSliceFromReader[V any, H scale.DecodablePtr[V]](r io.Reader) ([]V, error)

DecodeSliceFromReader accepts a reader and decodes slice with a length prefix.

func DecodeStringSlice

func DecodeStringSlice(r io.Reader) ([]string, int, error)

DecodeStringSlice decodes []string from an io.Reader.

func DecodeStringWithLimit added in v1.4.1

func DecodeStringWithLimit(r io.Reader, limit uint32) (string, int, error)

DecodeStringWithLimit decodes a string from an io.Reader, limiting the maximum length.

func Encode

func Encode(value Encodable) ([]byte, error)

Encode value to a byte buffer.

func EncodeByteSlice

func EncodeByteSlice(w io.Writer, value []byte) (int, error)

EncodeByteSlice encodes []string to an io.Writer.

func EncodeCompact16

func EncodeCompact16(w io.Writer, value uint16) (int, error)

EncodeCompact16 encodes uint16 to an io.Writer.

func EncodeLen added in v1.4.1

func EncodeLen(w io.Writer, value uint32) (int, error)

EncodeLen encodes a length value to an io.Writer.

func EncodeSlice

func EncodeSlice[V any, H scale.EncodablePtr[V]](value []V) ([]byte, error)

EncodeSlice encodes slice with a length prefix.

func EncodeStringSlice

func EncodeStringSlice(w io.Writer, value []string) (int, error)

EncodeStringSlice encodes []string to an io.Writer.

func EncodeTo

func EncodeTo(w io.Writer, value Encodable) (int, error)

EncodeTo encodes value to a writer stream.

func MustDecode

func MustDecode(buf []byte, value Decodable)

func MustDecodeSliceFromReader added in v1.4.3

func MustDecodeSliceFromReader[V any, H scale.DecodablePtr[V]](r io.Reader) []V

MustDecodeSliceFromReader decodes slice with a length prefix or panics on error.

func MustEncode

func MustEncode(value Encodable) []byte

func MustEncodeSlice added in v1.4.3

func MustEncodeSlice[V any, H scale.EncodablePtr[V]](value []V) []byte

MustEncodeSlice encodes slice with a length prefix or panics on error.

func MustEncodeTo added in v1.1.4

func MustEncodeTo(w io.Writer, value Encodable)

func ReadSlice added in v1.4.1

func ReadSlice[V any, H scale.DecodablePtr[V]](r io.Reader) ([]V, int, error)

EncodeCompact16 encodes uint16 to a buffer. ReadSlice decodes slice from am io.Reader.

Types

type Decodable

type Decodable = scale.Decodable

Decodable is an interface that must be implemented bya struct to be decoded.

type Encodable

type Encodable = scale.Encodable

Encodable is an interface that must be implemented by a struct to be encoded.

Jump to

Keyboard shortcuts

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