binary

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const EmptyObject = 0x80

EmptyObject is written when an object would otherwise be empty.

Variables

View Source
var ErrFieldsOutOfOrder = errors.New("fields are out of order")

ErrFieldsOutOfOrder is returned when an out of order field is encountered.

View Source
var ErrInvalidFieldNumber = errors.New("field number is invalid")

ErrInvalidFieldNumber is returned when an invalid field number is encountered.

Functions

func Marshal

func Marshal(v any) ([]byte, error)

func Unmarshal

func Unmarshal(b []byte, v any) error

Types

type Decoder

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

func NewDecoder

func NewDecoder(rd io.Reader, opts ...Option) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(v any) error

func (*Decoder) DecodeBool

func (d *Decoder) DecodeBool() (bool, error)

func (*Decoder) DecodeBytes

func (d *Decoder) DecodeBytes() ([]byte, error)

func (*Decoder) DecodeFloat

func (d *Decoder) DecodeFloat() (float64, error)

func (*Decoder) DecodeHash

func (d *Decoder) DecodeHash() ([32]byte, error)

func (*Decoder) DecodeInt

func (d *Decoder) DecodeInt() (int64, error)

func (*Decoder) DecodeString

func (d *Decoder) DecodeString() (string, error)

func (*Decoder) DecodeUint

func (d *Decoder) DecodeUint() (uint64, error)

func (*Decoder) DecodeValue

func (d *Decoder) DecodeValue(v encoding.BinaryUnmarshaler) error

func (*Decoder) DecodeValueV2

func (d *Decoder) DecodeValueV2(v Unmarshaller) error

func (*Decoder) EndObject

func (d *Decoder) EndObject() error

func (*Decoder) Field

func (d *Decoder) Field() (uint, error)

func (*Decoder) InField

func (d *Decoder) InField() bool

InField returns true if the decoder just read a field ID.

This is a hack and somewhat exposes the internal state of the decoder, but I can't think of a cleaner way of handling arrays (given that changing the encoding isn't an option).

func (*Decoder) Pool

func (s *Decoder) Pool() *Pool

func (*Decoder) StartObject

func (d *Decoder) StartObject() error

type Encoder

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

func NewEncoder

func NewEncoder(w io.Writer, opts ...Option) *Encoder

func (*Encoder) Context

func (e *Encoder) Context() *traverse.Context[reflect.Value]

func (*Encoder) Done

func (e *Encoder) Done() error

func (*Encoder) Encode

func (e *Encoder) Encode(v any) error

func (*Encoder) EncodeBool

func (e *Encoder) EncodeBool(v bool) error

func (*Encoder) EncodeBytes

func (e *Encoder) EncodeBytes(v []byte) error

func (*Encoder) EncodeField

func (e *Encoder) EncodeField(n uint, v any) error

func (*Encoder) EncodeFloat

func (e *Encoder) EncodeFloat(v float64) error

func (*Encoder) EncodeHash

func (e *Encoder) EncodeHash(v *[32]byte) error

func (*Encoder) EncodeInt

func (e *Encoder) EncodeInt(v int64) error

func (*Encoder) EncodeString

func (e *Encoder) EncodeString(v string) error

func (*Encoder) EncodeUint

func (e *Encoder) EncodeUint(v uint64) error

func (*Encoder) EncodeValue

func (e *Encoder) EncodeValue(v encoding.BinaryMarshaler) error

func (*Encoder) EncodeValueV2

func (e *Encoder) EncodeValueV2(v Marshaller) error

func (*Encoder) EndObject

func (e *Encoder) EndObject() error

func (*Encoder) Field

func (e *Encoder) Field(n uint) error

func (*Encoder) InField

func (e *Encoder) InField() bool

InField returns true if the decoder just read a field ID.

This is a hack and somewhat exposes the internal state of the decoder, but I can't think of a cleaner way of handling arrays (given that changing the encoding isn't an option).

func (*Encoder) Pool

func (e *Encoder) Pool() *Pool

func (*Encoder) RepeatLastField

func (e *Encoder) RepeatLastField() error

func (*Encoder) Reset

func (e *Encoder) Reset(w io.Writer, opts ...Option)

func (*Encoder) StartObject

func (e *Encoder) StartObject() error

type Marshaller

type Marshaller interface {
	MarshalBinaryV2(*Encoder) error
}

type Option

type Option func(o *options)

func WithContext

func WithContext(ctx *traverse.Context[reflect.Value]) Option

func WithPool

func WithPool(pool *Pool) Option

type Pool

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

func NewPool

func NewPool() *Pool

type Unmarshaller

type Unmarshaller interface {
	UnmarshalBinaryV2(*Decoder) error
}

Jump to

Keyboard shortcuts

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