encoding

package
v2.0.3-beta1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptionNoneTag byte = 0
	OptionSomeTag byte = 1
)
View Source
const BoolSerializedLength = 1
View Source
const U16SerializedLength = 2
View Source
const U32SerializedLength = 4
View Source
const U64SerializedLength = 8
View Source
const U8SerializedLength = 1

Variables

View Source
var (
	ErrEmptyBytesSource      = errors.New("empty bytes source")
	ErrInvalidBytesStructure = errors.New("invalid bytes structure")
)

Functions

func BytesSerializedLength

func BytesSerializedLength(val []byte) int

func StringSerializedLength

func StringSerializedLength(val string) int

Types

type BoolFromBytesDecoder

type BoolFromBytesDecoder struct{}

func NewBoolFromBytesDecoder

func NewBoolFromBytesDecoder() *BoolFromBytesDecoder

func (*BoolFromBytesDecoder) FromBytes

func (addr *BoolFromBytesDecoder) FromBytes(bytes []byte) (bool, []byte, error)

type BoolToBytesEncoder

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

func NewBoolToBytesEncoder

func NewBoolToBytesEncoder(val bool) BoolToBytesEncoder

func (BoolToBytesEncoder) Bytes

func (enc BoolToBytesEncoder) Bytes() ([]byte, error)

type BytesToBytesEncoder

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

func NewBytesToBytesEncoder

func NewBytesToBytesEncoder(val []byte) BytesToBytesEncoder

func (BytesToBytesEncoder) Bytes

func (enc BytesToBytesEncoder) Bytes() ([]byte, error)

type FromBytes

type FromBytes[T any] interface {
	FromBytes([]byte) (T, []byte, error)
}

type Option

type Option[T any] struct {
	Some *T
	None bool
}

func (Option[T]) IsSome

func (o Option[T]) IsSome() bool

type OptionFromBytesDecoder

type OptionFromBytesDecoder[T any, D FromBytes[T]] struct {
	Decoder D
}

func (*OptionFromBytesDecoder[T, D]) FromBytes

func (o *OptionFromBytesDecoder[T, D]) FromBytes(data []byte) (Option[T], []byte, error)

type SliceFromBytesDecoder

type SliceFromBytesDecoder[T any, D FromBytes[T]] struct {
	Decoder D
}

func (*SliceFromBytesDecoder[T, D]) FromBytes

func (d *SliceFromBytesDecoder[T, D]) FromBytes(inputBytes []byte) ([]T, []byte, error)

FromBytes decodes a slice of type T using the FromBytes interface

type SliceToBytesEncoder

type SliceToBytesEncoder[E ToBytes] struct {
	// contains filtered or unexported fields
}

func NewSliceToBytesEncoder

func NewSliceToBytesEncoder[E ToBytes](values []E) *SliceToBytesEncoder[E]

func (*SliceToBytesEncoder[E]) Bytes

func (enc *SliceToBytesEncoder[E]) Bytes() ([]byte, error)

type StringFromBytesDecoder

type StringFromBytesDecoder struct{}

func (*StringFromBytesDecoder) FromBytes

func (dec *StringFromBytesDecoder) FromBytes(bytes []byte) (string, []byte, error)

type StringToBytesEncoder

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

func NewStringToBytesEncoder

func NewStringToBytesEncoder(val string) StringToBytesEncoder

func (StringToBytesEncoder) Bytes

func (enc StringToBytesEncoder) Bytes() ([]byte, error)

type ToBytes

type ToBytes interface {
	Bytes() ([]byte, error)
	SerializedLength() int
}

type U16FromBytesDecoder

type U16FromBytesDecoder struct{}

func (*U16FromBytesDecoder) FromBytes

func (addr *U16FromBytesDecoder) FromBytes(inputBytes []byte) (uint16, []byte, error)

FromBytes function to deserialize a u16 from bytes

type U32FromBytesDecoder

type U32FromBytesDecoder struct{}

func NewU32FromBytesDecoder

func NewU32FromBytesDecoder() *U32FromBytesDecoder

func (*U32FromBytesDecoder) FromBytes

func (addr *U32FromBytesDecoder) FromBytes(inputBytes []byte) (uint32, []byte, error)

type U32ToBytesEncoder

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

func NewU32ToBytesEncoder

func NewU32ToBytesEncoder(val uint32) U32ToBytesEncoder

func (U32ToBytesEncoder) Bytes

func (enc U32ToBytesEncoder) Bytes() ([]byte, error)

type U64FromBytesDecoder

type U64FromBytesDecoder struct{}

func (*U64FromBytesDecoder) FromBytes

func (addr *U64FromBytesDecoder) FromBytes(bytes []byte) (uint64, []byte, error)

FromBytes deserializes a uint64 from a byte slice.

type U64ToBytesEncoder

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

func NewU64ToBytesEncoder

func NewU64ToBytesEncoder(val uint64) U64ToBytesEncoder

func (U64ToBytesEncoder) Bytes

func (enc U64ToBytesEncoder) Bytes() ([]byte, error)

type U8FromBytesDecoder

type U8FromBytesDecoder struct{}

func (*U8FromBytesDecoder) FromBytes

func (addr *U8FromBytesDecoder) FromBytes(inputBytes []byte) (uint8, []byte, error)

Jump to

Keyboard shortcuts

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