encoding

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 25 Imported by: 9

Documentation

Index

Constants

View Source
const EmptyObject = 0x80

EmptyObject is written when an object would otherwise be empty.

View Source
const MaxValueSize = 1 << 24

Variables

View Source
var ErrFieldsOutOfOrder = errors.New("fields are out of order")
View Source
var ErrInvalidFieldNumber = errors.New("field number is invalid")

ErrInvalidFieldNumber is returned when an invalid field number is encountered.

View Source
var ErrMalformedBigInt = errors.New("invalid big integer string")
View Source
var ErrNotEnoughData = errors.New("not enough data")
View Source
var ErrOverflow = errors.New("overflow")

Functions

func AnyFromJSON

func AnyFromJSON(v interface{}) (interface{}, error)

AnyFromJSON converts v to a duration if it appears to be a duration. AnyFromJSON never returns an error.

func AnyToJSON

func AnyToJSON(v interface{}) interface{}

func BigintCopy

func BigintCopy(v *big.Int) *big.Int

func BigintFromJSON

func BigintFromJSON(s *string) (*big.Int, error)

func BigintToJSON

func BigintToJSON(b *big.Int) *string

func BytesCopy

func BytesCopy(v []byte) []byte

func BytesFromJSON

func BytesFromJSON(s *string) ([]byte, error)

func BytesToJSON

func BytesToJSON(v []byte) *string

func Cast added in v1.1.0

func Cast[U, V any](v V, err error) (U, error)

func ChainFromJSON

func ChainFromJSON(s *string) (*[32]byte, error)

func ChainToJSON

func ChainToJSON(v *[32]byte) *string

func Copy added in v1.1.0

func Copy[T any, PT interface{ *T }](m *Machine[PT], v PT) PT

Copy constructs a value, copying all of the fields of an existing value.

func DurationFromJSON

func DurationFromJSON(v interface{}) (time.Duration, error)

func DurationToJSON

func DurationToJSON(v time.Duration) interface{}

func EnumWidgetFor added in v1.4.1

func EnumWidgetFor[U enumGet, V enumSet[U]]() widget.Widget[V]

func FromaddressToBytes added in v1.4.0

func FromaddressToBytes(address string) ([]byte, error)

func FromboolToBytes added in v1.4.0

func FromboolToBytes(b bool) ([]byte, error)

func Frombytes32ToBytes added in v1.4.0

func Frombytes32ToBytes(value string) ([]byte, error)

func FrombytesToBytes added in v1.4.0

func FrombytesToBytes(value string) ([]byte, error)

func FromfloatToBytes added in v1.4.0

func FromfloatToBytes(value float64) ([]byte, error)

FromfloatToBytes eip712 doesn't officially support floats, but we need to provide this for the code generator

func Fromint64ToBytes added in v1.4.0

func Fromint64ToBytes(n int64) ([]byte, error)

func FromstringToBytes added in v1.4.0

func FromstringToBytes(s string) ([]byte, error)

func Fromuint256ToBytes added in v1.4.0

func Fromuint256ToBytes(s string) ([]byte, error)

func Fromuint64ToBytes added in v1.4.0

func Fromuint64ToBytes(n uint64) ([]byte, error)

func Hash added in v1.3.0

func Hash(m BinaryValue) [32]byte

func MarshalBytes added in v1.1.0

func MarshalBytes(v []byte) []byte

func MarshalHash added in v1.1.0

func MarshalHash(v *[32]byte) []byte

func MarshalInt added in v1.1.0

func MarshalInt(v int64) []byte

func MarshalString added in v1.1.0

func MarshalString(s string) []byte

func MarshalUint added in v1.1.0

func MarshalUint(v uint64) []byte

func RegisterTypeDefinition added in v1.4.0

func RegisterTypeDefinition(tf *[]*TypeField, name string, aliases ...string)

func RegisterUnion added in v1.4.0

func RegisterUnion[T any, R any](op Func[T, R])

func SetPtr added in v1.1.0

func SetPtr(value, target interface{}) (err error)

SetPtr sets *target = value. If value cannot be assigned to *target and value has an Unwrap() method that returns a single value, SetPtr will retry with Unwrap()'s return value, recursively.

func SplitDuration

func SplitDuration(d time.Duration) (sec, ns uint64)

func UnmarshalBytes added in v1.1.0

func UnmarshalBytes(b []byte) ([]byte, error)

func UnmarshalHash added in v1.1.0

func UnmarshalHash(b []byte) ([32]byte, error)

func UnmarshalInt added in v1.1.0

func UnmarshalInt(b []byte) (int64, error)

func UnmarshalString added in v1.1.0

func UnmarshalString(b []byte) (string, error)

func UnmarshalUint added in v1.1.0

func UnmarshalUint(b []byte) (uint64, error)

Types

type Accessor added in v1.1.0

type Accessor[V any] interface {
	// IsEmpty checks if the field is empty.
	IsEmpty(V) bool

	// CopyTo copies the field from the source to the destination.
	CopyTo(dst, src V)

	// Equal checks if V's field and U's field are equal.
	Equal(v, u V) bool

	// WriteTo writes the value's field to the writer.
	WriteTo(w *Writer, n uint, v V)

	// ReadField reads the value's field from the reader.
	ReadFrom(r *Reader, n uint, v V) bool

	// ToJSON writes the value's field as JSON to the builder.
	ToJSON(w *bytes.Buffer, v V) error

	// FromJSON reads the value's field as JSON.
	FromJSON(b []byte, v V) error
}

Accessor implements various functions for a value's field.

type BigIntField added in v1.1.0

type BigIntField[V any] func(v V) *big.Int

BigIntField is an Accessor for a value's big int field.

func (BigIntField[V]) CopyTo added in v1.1.0

func (f BigIntField[V]) CopyTo(dst, src V)

func (BigIntField[V]) Equal added in v1.1.0

func (f BigIntField[V]) Equal(v, u V) bool

func (BigIntField[V]) FromJSON added in v1.1.0

func (f BigIntField[V]) FromJSON(b []byte, v V) error

func (BigIntField[V]) IsEmpty added in v1.1.0

func (f BigIntField[V]) IsEmpty(v V) bool

func (BigIntField[V]) ReadFrom added in v1.1.0

func (f BigIntField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (BigIntField[V]) ToJSON added in v1.1.0

func (f BigIntField[V]) ToJSON(w *bytes.Buffer, v V) error

func (BigIntField[V]) WriteTo added in v1.1.0

func (f BigIntField[V]) WriteTo(w *Writer, n uint, v V)

type BigIntPtrField added in v1.1.0

type BigIntPtrField[V any] func(v V) **big.Int

BigIntPtrField is an Accessor for a value's big int pointer field.

func (BigIntPtrField[V]) CopyTo added in v1.1.0

func (f BigIntPtrField[V]) CopyTo(dst, src V)

func (BigIntPtrField[V]) Equal added in v1.1.0

func (f BigIntPtrField[V]) Equal(v, u V) bool

func (BigIntPtrField[V]) FromJSON added in v1.1.0

func (f BigIntPtrField[V]) FromJSON(b []byte, v V) error

func (BigIntPtrField[V]) IsEmpty added in v1.1.0

func (f BigIntPtrField[V]) IsEmpty(v V) bool

func (BigIntPtrField[V]) ReadFrom added in v1.1.0

func (f BigIntPtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (BigIntPtrField[V]) ToJSON added in v1.1.0

func (f BigIntPtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (BigIntPtrField[V]) WriteTo added in v1.1.0

func (f BigIntPtrField[V]) WriteTo(w *Writer, n uint, v V)

type BinaryValue

type BinaryValue interface {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	CopyAsInterface() interface{}
	UnmarshalBinaryFrom(io.Reader) error
}

type BoolField added in v1.1.0

type BoolField[V any] func(v V) *bool

BoolField is an Accessor for a value's bool field.

func (BoolField[V]) CopyTo added in v1.1.0

func (f BoolField[V]) CopyTo(dst, src V)

func (BoolField[V]) Equal added in v1.1.0

func (f BoolField[V]) Equal(v, u V) bool

func (BoolField[V]) FromJSON added in v1.1.0

func (f BoolField[V]) FromJSON(b []byte, v V) error

func (BoolField[V]) IsEmpty added in v1.1.0

func (f BoolField[V]) IsEmpty(v V) bool

func (BoolField[V]) ReadFrom added in v1.1.0

func (f BoolField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (BoolField[V]) ToJSON added in v1.1.0

func (f BoolField[V]) ToJSON(w *bytes.Buffer, v V) error

func (BoolField[V]) WriteTo added in v1.1.0

func (f BoolField[V]) WriteTo(w *Writer, n uint, v V)

type BoolPtrField added in v1.1.0

type BoolPtrField[V any] func(v V) **bool

BoolPtrField is an Accessor for a value's bool pointer field.

func (BoolPtrField[V]) CopyTo added in v1.1.0

func (f BoolPtrField[V]) CopyTo(dst, src V)

func (BoolPtrField[V]) Equal added in v1.1.0

func (f BoolPtrField[V]) Equal(v, u V) bool

func (BoolPtrField[V]) FromJSON added in v1.1.0

func (f BoolPtrField[V]) FromJSON(b []byte, v V) error

func (BoolPtrField[V]) IsEmpty added in v1.1.0

func (f BoolPtrField[V]) IsEmpty(v V) bool

func (BoolPtrField[V]) ReadFrom added in v1.1.0

func (f BoolPtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (BoolPtrField[V]) ToJSON added in v1.1.0

func (f BoolPtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (BoolPtrField[V]) WriteTo added in v1.1.0

func (f BoolPtrField[V]) WriteTo(w *Writer, n uint, v V)

type BytesField added in v1.1.0

type BytesField[V any] func(v V) *[]byte

BytesField is an Accessor for a value's []byte field.

func (BytesField[V]) CopyTo added in v1.1.0

func (f BytesField[V]) CopyTo(dst, src V)

func (BytesField[V]) Equal added in v1.1.0

func (f BytesField[V]) Equal(v, u V) bool

func (BytesField[V]) FromJSON added in v1.1.0

func (f BytesField[V]) FromJSON(b []byte, v V) error

func (BytesField[V]) IsEmpty added in v1.1.0

func (f BytesField[V]) IsEmpty(v V) bool

func (BytesField[V]) ReadFrom added in v1.1.0

func (f BytesField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (BytesField[V]) ToJSON added in v1.1.0

func (f BytesField[V]) ToJSON(w *bytes.Buffer, v V) error

func (BytesField[V]) WriteTo added in v1.1.0

func (f BytesField[V]) WriteTo(w *Writer, n uint, v V)

type BytesPtrField added in v1.1.0

type BytesPtrField[V any] func(v V) **[]byte

BytesPtrField is an Accessor for a value's []byte pointer field.

func (BytesPtrField[V]) CopyTo added in v1.1.0

func (f BytesPtrField[V]) CopyTo(dst, src V)

func (BytesPtrField[V]) Equal added in v1.1.0

func (f BytesPtrField[V]) Equal(v, u V) bool

func (BytesPtrField[V]) FromJSON added in v1.1.0

func (f BytesPtrField[V]) FromJSON(b []byte, v V) error

func (BytesPtrField[V]) IsEmpty added in v1.1.0

func (f BytesPtrField[V]) IsEmpty(v V) bool

func (BytesPtrField[V]) ReadFrom added in v1.1.0

func (f BytesPtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (BytesPtrField[V]) ToJSON added in v1.1.0

func (f BytesPtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (BytesPtrField[V]) WriteTo added in v1.1.0

func (f BytesPtrField[V]) WriteTo(w *Writer, n uint, v V)

type BytesReader added in v1.1.0

type BytesReader interface {
	io.Reader
	io.ByteScanner
}

type Duration added in v1.4.0

type Duration time.Duration

func (Duration) Copy added in v1.4.0

func (u Duration) Copy() *Duration

func (Duration) Equal added in v1.4.0

func (u Duration) Equal(v *Duration) bool

func (Duration) Get added in v1.4.0

func (u Duration) Get() time.Duration

func (Duration) MarshalBinary added in v1.4.0

func (u Duration) MarshalBinary() ([]byte, error)

func (Duration) MarshalBinaryV2 added in v1.4.0

func (u Duration) MarshalBinaryV2(e *binary.Encoder) error

func (Duration) MarshalJSON added in v1.4.0

func (u Duration) MarshalJSON() ([]byte, error)

func (Duration) MarshalJSONV2 added in v1.4.0

func (u Duration) MarshalJSONV2(e *json.Encoder) error

func (*Duration) Set added in v1.4.0

func (u *Duration) Set(v time.Duration)

func (Duration) String added in v1.4.0

func (u Duration) String() string

func (*Duration) UnmarshalBinary added in v1.4.0

func (u *Duration) UnmarshalBinary(b []byte) error

func (*Duration) UnmarshalBinaryV2 added in v1.4.0

func (u *Duration) UnmarshalBinaryV2(d *binary.Decoder) error

func (*Duration) UnmarshalJSON added in v1.4.0

func (u *Duration) UnmarshalJSON(b []byte) error

func (*Duration) UnmarshalJSONV2 added in v1.4.0

func (u *Duration) UnmarshalJSONV2(d *json.Decoder) error

type DurationField added in v1.1.0

type DurationField[V any] func(v V) *time.Duration

DurationField is an Accessor for a value's duration field.

func (DurationField[V]) CopyTo added in v1.1.0

func (f DurationField[V]) CopyTo(dst, src V)

func (DurationField[V]) Equal added in v1.1.0

func (f DurationField[V]) Equal(v, u V) bool

func (DurationField[V]) FromJSON added in v1.1.0

func (f DurationField[V]) FromJSON(b []byte, v V) error

func (DurationField[V]) IsEmpty added in v1.1.0

func (f DurationField[V]) IsEmpty(v V) bool

func (DurationField[V]) ReadFrom added in v1.1.0

func (f DurationField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (DurationField[V]) ToJSON added in v1.1.0

func (f DurationField[V]) ToJSON(w *bytes.Buffer, v V) error

func (DurationField[V]) WriteTo added in v1.1.0

func (f DurationField[V]) WriteTo(w *Writer, n uint, v V)

type DurationFields

type DurationFields struct {
	Seconds     uint64 `json:"seconds,omitempty"`
	Nanoseconds uint64 `json:"nanoseconds,omitempty"`
}

type DurationPtrField added in v1.1.0

type DurationPtrField[V any] func(v V) **time.Duration

DurationPtrField is an Accessor for a value's Duration pointer field.

func (DurationPtrField[V]) CopyTo added in v1.1.0

func (f DurationPtrField[V]) CopyTo(dst, src V)

func (DurationPtrField[V]) Equal added in v1.1.0

func (f DurationPtrField[V]) Equal(v, u V) bool

func (DurationPtrField[V]) FromJSON added in v1.1.0

func (f DurationPtrField[V]) FromJSON(b []byte, v V) error

func (DurationPtrField[V]) IsEmpty added in v1.1.0

func (f DurationPtrField[V]) IsEmpty(v V) bool

func (DurationPtrField[V]) ReadFrom added in v1.1.0

func (f DurationPtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (DurationPtrField[V]) ToJSON added in v1.1.0

func (f DurationPtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (DurationPtrField[V]) WriteTo added in v1.1.0

func (f DurationPtrField[V]) WriteTo(w *Writer, n uint, v V)

type EIP712Call added in v1.4.0

type EIP712Call struct {
	Types       map[string][]*TypeField `json:"types"`
	PrimaryType string                  `json:"primaryType"`
	Domain      EIP712Domain            `json:"domain"`
	Message     eipResolvedValue        `json:"message"`
}

Construct the wallet RPC call

func NewEIP712Call added in v1.4.0

func NewEIP712Call(value any, chainID *big.Int, typ EIP712Resolver) (*EIP712Call, error)

func (*EIP712Call) Hash added in v1.4.0

func (c *EIP712Call) Hash() ([]byte, error)

type EIP712Domain added in v1.4.0

type EIP712Domain struct {
	Name    string   `json:"name,omitempty" form:"name" query:"name" validate:"required"`
	Version string   `json:"version,omitempty" form:"version" query:"version" validate:"required"`
	ChainId *big.Int `json:"chainId,omitempty" form:"chainId" query:"chainId" validate:"required"`
}

func (*EIP712Domain) MarshalJSON added in v1.4.0

func (v *EIP712Domain) MarshalJSON() ([]byte, error)

func (*EIP712Domain) UnmarshalJSON added in v1.4.0

func (v *EIP712Domain) UnmarshalJSON(data []byte) error

type EIP712Resolver added in v1.4.0

type EIP712Resolver interface {
	Resolve(any) (eipResolvedValue, error)
}

type Enum added in v1.4.0

type Enum interface {
	SetEnumValue(id uint64) bool
	String() string
}

type EnumField added in v1.1.0

type EnumField[V any, U enumSet[W], W enumGet] func(v V) *W

EnumField is an Accessor for a value's enum field.

func (EnumField[V, U, W]) CopyTo added in v1.1.0

func (f EnumField[V, U, W]) CopyTo(dst, src V)

func (EnumField[V, U, W]) Equal added in v1.1.0

func (f EnumField[V, U, W]) Equal(v, u V) bool

func (EnumField[V, U, W]) FromJSON added in v1.1.0

func (f EnumField[V, U, W]) FromJSON(b []byte, v V) error

func (EnumField[V, U, W]) IsEmpty added in v1.1.0

func (f EnumField[V, U, W]) IsEmpty(v V) bool

func (EnumField[V, U, W]) ReadFrom added in v1.1.0

func (f EnumField[V, U, W]) ReadFrom(r *Reader, n uint, v V) bool

func (EnumField[V, U, W]) ToJSON added in v1.1.0

func (f EnumField[V, U, W]) ToJSON(w *bytes.Buffer, v V) error

func (EnumField[V, U, W]) WriteTo added in v1.1.0

func (f EnumField[V, U, W]) WriteTo(w *Writer, n uint, v V)

type EnumPtrField added in v1.1.0

type EnumPtrField[V any, U enumSet[W], W enumGet] func(v V) **W

EnumPtrField is an Accessor for a value's enum pointer field.

func (EnumPtrField[V, U, W]) CopyTo added in v1.1.0

func (f EnumPtrField[V, U, W]) CopyTo(dst, src V)

func (EnumPtrField[V, U, W]) Equal added in v1.1.0

func (f EnumPtrField[V, U, W]) Equal(v, u V) bool

func (EnumPtrField[V, U, W]) FromJSON added in v1.1.0

func (f EnumPtrField[V, U, W]) FromJSON(b []byte, v V) error

func (EnumPtrField[V, U, W]) IsEmpty added in v1.1.0

func (f EnumPtrField[V, U, W]) IsEmpty(v V) bool

func (EnumPtrField[V, U, W]) ReadFrom added in v1.1.0

func (f EnumPtrField[V, U, W]) ReadFrom(r *Reader, n uint, v V) bool

func (EnumPtrField[V, U, W]) ToJSON added in v1.1.0

func (f EnumPtrField[V, U, W]) ToJSON(w *bytes.Buffer, v V) error

func (EnumPtrField[V, U, W]) WriteTo added in v1.1.0

func (f EnumPtrField[V, U, W]) WriteTo(w *Writer, n uint, v V)

type EnumValueGetter

type EnumValueGetter interface {
	GetEnumValue() uint64
}

type EnumValueSetter

type EnumValueSetter interface {
	SetEnumValue(uint64) bool
}

type EnumWidget added in v1.4.1

type EnumWidget[V enumSet[U], U enumGet] struct{}

EnumWidget is a widget.Widget for EnumValueGetter and EnumValueSetter types.

func (EnumWidget[V, U]) CopyTo added in v1.4.1

func (EnumWidget[V, U]) CopyTo(dst, src V)

func (EnumWidget[V, U]) Empty added in v1.4.1

func (EnumWidget[V, U]) Empty(v V) bool

func (EnumWidget[V, U]) Equal added in v1.4.1

func (EnumWidget[V, U]) Equal(a, b V) bool

func (EnumWidget[V, U]) IsNil added in v1.4.1

func (EnumWidget[V, U]) IsNil(v V) bool

func (EnumWidget[V, U]) MarshalBinary added in v1.4.1

func (EnumWidget[V, U]) MarshalBinary(e *binary.Encoder, v V) error

func (EnumWidget[V, U]) MarshalJSON added in v1.4.1

func (EnumWidget[V, U]) MarshalJSON(e *json.Encoder, v V) error

func (EnumWidget[V, U]) UnmarshalBinary added in v1.4.1

func (EnumWidget[V, U]) UnmarshalBinary(d *binary.Decoder, v V) error

func (EnumWidget[V, U]) UnmarshalJSON added in v1.4.1

func (EnumWidget[V, U]) UnmarshalJSON(d *json.Decoder, v V) error

type Error

type Error struct {
	E error
}

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type Field added in v1.1.0

type Field[V any] struct {
	Accessor[V]
	Name      string
	OmitEmpty bool
	Required  bool
	Number    uint
	Binary    bool
}

Field is a named accessor for a field of V.

func (*Field[V]) ReadFrom added in v1.1.0

func (f *Field[V]) ReadFrom(r *Reader, v V)

func (*Field[V]) ToJSON added in v1.1.0

func (f *Field[V]) ToJSON(w *bytes.Buffer, v V) error

ToJSON writes the value's field (including the name) as JSON to the builder, unless OmitEmpty is false and the field is empty.

func (*Field[V]) WriteTo added in v1.1.0

func (f *Field[V]) WriteTo(w *Writer, v V)

WriteTo writes the value's field to the writer, unless OmitEmpty is false and the field is empty.

type FloatField added in v1.1.0

type FloatField[V any] func(v V) *float64

FloatField is an Accessor for a value's float64 field.

func (FloatField[V]) CopyTo added in v1.1.0

func (f FloatField[V]) CopyTo(dst, src V)

func (FloatField[V]) Equal added in v1.1.0

func (f FloatField[V]) Equal(v, u V) bool

func (FloatField[V]) FromJSON added in v1.1.0

func (f FloatField[V]) FromJSON(b []byte, v V) error

func (FloatField[V]) IsEmpty added in v1.1.0

func (f FloatField[V]) IsEmpty(v V) bool

func (FloatField[V]) ReadFrom added in v1.1.0

func (f FloatField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (FloatField[V]) ToJSON added in v1.1.0

func (f FloatField[V]) ToJSON(w *bytes.Buffer, v V) error

func (FloatField[V]) WriteTo added in v1.1.0

func (f FloatField[V]) WriteTo(w *Writer, n uint, v V)

type FloatPtrField added in v1.1.0

type FloatPtrField[V any] func(v V) **float64

FloatPtrField is an Accessor for a value's float64 pointer field.

func (FloatPtrField[V]) CopyTo added in v1.1.0

func (f FloatPtrField[V]) CopyTo(dst, src V)

func (FloatPtrField[V]) Equal added in v1.1.0

func (f FloatPtrField[V]) Equal(v, u V) bool

func (FloatPtrField[V]) FromJSON added in v1.1.0

func (f FloatPtrField[V]) FromJSON(b []byte, v V) error

func (FloatPtrField[V]) IsEmpty added in v1.1.0

func (f FloatPtrField[V]) IsEmpty(v V) bool

func (FloatPtrField[V]) ReadFrom added in v1.1.0

func (f FloatPtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (FloatPtrField[V]) ToJSON added in v1.1.0

func (f FloatPtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (FloatPtrField[V]) WriteTo added in v1.1.0

func (f FloatPtrField[V]) WriteTo(w *Writer, n uint, v V)

type Func added in v1.4.0

type Func[T any, R any] func(T) (R, error)

type HashField added in v1.1.0

type HashField[V any] func(v V) *[32]byte

HashField is an Accessor for a value's [32]byte field.

func (HashField[V]) CopyTo added in v1.1.0

func (f HashField[V]) CopyTo(dst, src V)

func (HashField[V]) Equal added in v1.1.0

func (f HashField[V]) Equal(v, u V) bool

func (HashField[V]) FromJSON added in v1.1.0

func (f HashField[V]) FromJSON(b []byte, v V) error

func (HashField[V]) IsEmpty added in v1.1.0

func (f HashField[V]) IsEmpty(v V) bool

func (HashField[V]) ReadFrom added in v1.1.0

func (f HashField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (HashField[V]) ToJSON added in v1.1.0

func (f HashField[V]) ToJSON(w *bytes.Buffer, v V) error

func (HashField[V]) WriteTo added in v1.1.0

func (f HashField[V]) WriteTo(w *Writer, n uint, v V)

type HashPtrField added in v1.1.0

type HashPtrField[V any] func(v V) **[32]byte

HashPtrField is an Accessor for a value's [32]byte pointer field.

func (HashPtrField[V]) CopyTo added in v1.1.0

func (f HashPtrField[V]) CopyTo(dst, src V)

func (HashPtrField[V]) Equal added in v1.1.0

func (f HashPtrField[V]) Equal(v, u V) bool

func (HashPtrField[V]) FromJSON added in v1.1.0

func (f HashPtrField[V]) FromJSON(b []byte, v V) error

func (HashPtrField[V]) IsEmpty added in v1.1.0

func (f HashPtrField[V]) IsEmpty(v V) bool

func (HashPtrField[V]) ReadFrom added in v1.1.0

func (f HashPtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (HashPtrField[V]) ToJSON added in v1.1.0

func (f HashPtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (HashPtrField[V]) WriteTo added in v1.1.0

func (f HashPtrField[V]) WriteTo(w *Writer, n uint, v V)

type IntField added in v1.1.0

type IntField[V any] func(v V) *int64

IntField is an Accessor for a value's int64 field.

func (IntField[V]) CopyTo added in v1.1.0

func (f IntField[V]) CopyTo(dst, src V)

func (IntField[V]) Equal added in v1.1.0

func (f IntField[V]) Equal(v, u V) bool

func (IntField[V]) FromJSON added in v1.1.0

func (f IntField[V]) FromJSON(b []byte, v V) error

func (IntField[V]) IsEmpty added in v1.1.0

func (f IntField[V]) IsEmpty(v V) bool

func (IntField[V]) ReadFrom added in v1.1.0

func (f IntField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (IntField[V]) ToJSON added in v1.1.0

func (f IntField[V]) ToJSON(w *bytes.Buffer, v V) error

func (IntField[V]) WriteTo added in v1.1.0

func (f IntField[V]) WriteTo(w *Writer, n uint, v V)

type IntPtrField added in v1.1.0

type IntPtrField[V any] func(v V) **int64

IntPtrField is an Accessor for a value's int64 pointer field.

func (IntPtrField[V]) CopyTo added in v1.1.0

func (f IntPtrField[V]) CopyTo(dst, src V)

func (IntPtrField[V]) Equal added in v1.1.0

func (f IntPtrField[V]) Equal(v, u V) bool

func (IntPtrField[V]) FromJSON added in v1.1.0

func (f IntPtrField[V]) FromJSON(b []byte, v V) error

func (IntPtrField[V]) IsEmpty added in v1.1.0

func (f IntPtrField[V]) IsEmpty(v V) bool

func (IntPtrField[V]) ReadFrom added in v1.1.0

func (f IntPtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (IntPtrField[V]) ToJSON added in v1.1.0

func (f IntPtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (IntPtrField[V]) WriteTo added in v1.1.0

func (f IntPtrField[V]) WriteTo(w *Writer, n uint, v V)

type JsonList

type JsonList[T any] []T

JsonList attempts to unmarshal JSON into a slice of T and falls back to unmarshalling it into a single value of type T. Thus, fields of type JsonList can be unmarshaled from a single value or a list.

func (*JsonList[T]) UnmarshalJSON

func (j *JsonList[T]) UnmarshalJSON(data []byte) error

type JsonUnmarshalListWith

type JsonUnmarshalListWith[T any] struct {
	Value []T
	Func  func([]byte) (T, error)
}

JsonUnmarshalListWith combines the functionality of JsonList and JsonUnmarshalWith, using the given function to unmarshal JSON into a slice of T and falls back to unmarshalling it into a single value of type T.

func (*JsonUnmarshalListWith[T]) MarshalJSON

func (j *JsonUnmarshalListWith[T]) MarshalJSON() ([]byte, error)

func (*JsonUnmarshalListWith[T]) UnmarshalJSON

func (j *JsonUnmarshalListWith[T]) UnmarshalJSON(data []byte) error

type JsonUnmarshalWith

type JsonUnmarshalWith[T any] struct {
	Value T
	Func  func([]byte) (T, error)
}

JsonUnmarshalWith uses the given function to unmarshal JSON into a value of type T.

func (*JsonUnmarshalWith[T]) MarshalJSON

func (j *JsonUnmarshalWith[T]) MarshalJSON() ([]byte, error)

func (*JsonUnmarshalWith[T]) UnmarshalJSON

func (j *JsonUnmarshalWith[T]) UnmarshalJSON(data []byte) error

type Machine added in v1.1.0

type Machine[T any] struct {
	// Fields is a list of accessors for all of the field's types.
	Fields []*Field[T]

	// ExtraData returns the value's extra data field.
	ExtraData func(v T) *[]byte

	// Seen returns the value's seen fields field.
	Seen func(v T) *[]bool
}

Machine is an encoder machine that knows how to encode all the fields of a type.

func (*Machine[T]) Equal added in v1.1.0

func (m *Machine[T]) Equal(v, u T) bool

Equal checks if V and U's fields are equal.

func (*Machine[T]) FromJSON added in v1.1.0

func (m *Machine[T]) FromJSON(b []byte, v T) error

FromJSON reads the value's fields as JSON from bytes.

func (*Machine[T]) IsValid added in v1.1.0

func (m *Machine[T]) IsValid(v T) error

IsValid checks if the value's fields are valid.

func (*Machine[T]) JSONMarshal added in v1.1.0

func (m *Machine[T]) JSONMarshal(v T) ([]byte, error)

func (*Machine[T]) JSONUnmarshal added in v1.1.0

func (m *Machine[T]) JSONUnmarshal(b []byte, v T) error

func (*Machine[T]) MarshalBinary added in v1.1.0

func (m *Machine[T]) MarshalBinary(v T) ([]byte, error)

MarshalBinary marshals the value's fields to binary.

func (*Machine[T]) ReadFrom added in v1.1.0

func (m *Machine[T]) ReadFrom(r *Reader, v T)

ReadFrom reads the value's fields from binary.

func (*Machine[T]) ToJSON added in v1.1.0

func (m *Machine[T]) ToJSON(w *bytes.Buffer, v T) error

ToJSON writes the value's fields as JSON to the builder.

func (*Machine[T]) Unmarshal added in v1.1.0

func (m *Machine[T]) Unmarshal(b []byte, v T) error

Unmarshal unmarshals a value from binary.

func (*Machine[T]) UnmarshalFrom added in v1.1.0

func (m *Machine[T]) UnmarshalFrom(rd io.Reader, v T) error

UnmarshalFrom unmarshals a value from a reader.

func (*Machine[T]) WriteTo added in v1.1.0

func (m *Machine[T]) WriteTo(w *Writer, v T)

WriteTo writes the value's fields to the writer.

type ReadOnlyAccessor added in v1.1.0

type ReadOnlyAccessor[V, U any, A valueAccessor[U]] func(V) U

func (ReadOnlyAccessor[V, U, A]) CopyTo added in v1.1.0

func (f ReadOnlyAccessor[V, U, A]) CopyTo(dst, src V)

func (ReadOnlyAccessor[V, U, A]) Equal added in v1.1.0

func (f ReadOnlyAccessor[V, U, A]) Equal(v, u V) bool

func (ReadOnlyAccessor[V, U, A]) FromJSON added in v1.1.0

func (f ReadOnlyAccessor[V, U, A]) FromJSON(b []byte, v V) error

func (ReadOnlyAccessor[V, U, A]) IsEmpty added in v1.1.0

func (f ReadOnlyAccessor[V, U, A]) IsEmpty(v V) bool

func (ReadOnlyAccessor[V, U, A]) ReadFrom added in v1.1.0

func (f ReadOnlyAccessor[V, U, A]) ReadFrom(r *Reader, n uint, v V) bool

func (ReadOnlyAccessor[V, U, A]) ToJSON added in v1.1.0

func (f ReadOnlyAccessor[V, U, A]) ToJSON(w *bytes.Buffer, v V) error

func (ReadOnlyAccessor[V, U, A]) WriteTo added in v1.1.0

func (f ReadOnlyAccessor[V, U, A]) WriteTo(w *Writer, n uint, v V)

type Reader

type Reader struct {
	IgnoreSizeLimit bool
	// contains filtered or unexported fields
}

func NewReader

func NewReader(r io.Reader) *Reader

func (*Reader) IsEmpty added in v1.1.0

func (r *Reader) IsEmpty() bool

IsEmpty returns true if the object is empty. IsEmpty will always return false if called prior to any other Read method.

func (*Reader) ReadAll

func (r *Reader) ReadAll() ([]byte, error)

ReadAll reads the entire value from the current position

func (*Reader) ReadBigInt

func (r *Reader) ReadBigInt(n uint) (*big.Int, bool)

ReadBigInt reads the value as a big-endian byte slice.

func (*Reader) ReadBool

func (r *Reader) ReadBool(n uint) (bool, bool)

ReadBool reads the value as a varint-encoded unsigned integer. An error is recorded if the value is not 0 or 1.

func (*Reader) ReadBytes

func (r *Reader) ReadBytes(n uint) ([]byte, bool)

ReadBytes reads the length of the value as a varint-encoded unsigned integer followed by the value.

func (*Reader) ReadDuration

func (r *Reader) ReadDuration(n uint) (time.Duration, bool)

ReadDuration reads the value as seconds and nanoseconds, each as a varint-encoded unsigned integer.

func (*Reader) ReadEnum

func (r *Reader) ReadEnum(n uint, v EnumValueSetter) bool

func (*Reader) ReadFloat

func (r *Reader) ReadFloat(n uint) (float64, bool)

ReadFloat reads the value as a varint-encoded unsigned integer.

func (*Reader) ReadHash

func (r *Reader) ReadHash(n uint) (*[32]byte, bool)

ReadHash reads 32 bytes.

func (*Reader) ReadHash2 added in v1.1.0

func (r *Reader) ReadHash2(n uint) ([32]byte, bool)

func (*Reader) ReadInt

func (r *Reader) ReadInt(n uint) (int64, bool)

ReadInt reads the value as a varint-encoded signed integer.

func (*Reader) ReadString

func (r *Reader) ReadString(n uint) (string, bool)

ReadString reads the length of the value as a varint-encoded unsigned integer followed by the value.

func (*Reader) ReadTime

func (r *Reader) ReadTime(n uint) (time.Time, bool)

ReadTime reads the value as a varint-encoded UTC Unix timestamp (signed).

func (*Reader) ReadTxid

func (r *Reader) ReadTxid(n uint) (*url.TxID, bool)

ReadTxid reads the value as a transaction ID.

func (*Reader) ReadUint

func (r *Reader) ReadUint(n uint) (uint64, bool)

ReadUint reads the value as a varint-encoded unsigned integer.

func (*Reader) ReadUrl

func (r *Reader) ReadUrl(n uint) (*url.URL, bool)

ReadUrl reads the value as a URL.

func (*Reader) ReadValue

func (r *Reader) ReadValue(n uint, unmarshal func(io.Reader) error) bool

ReadValue reads the value as a byte slice and unmarshals it.

func (*Reader) Reset

func (r *Reader) Reset(fieldNames []string) (seen []bool, err error)

Reset returns a list of seen fields and an error, if one occurred, and resets the reader.

If a list of field names is provided, the error will be formatted as "field <name>: <err>".

type SliceField added in v1.1.0

type SliceField[V, U any, A sliceIndexAccessor[U]] func(v V) *[]U

SliceField is an Accessor for a value's slice field.

func (SliceField[V, U, A]) CopyTo added in v1.1.0

func (f SliceField[V, U, A]) CopyTo(dst, src V)

func (SliceField[V, U, A]) Equal added in v1.1.0

func (f SliceField[V, U, A]) Equal(v, u V) bool

func (SliceField[V, U, A]) FromJSON added in v1.1.0

func (f SliceField[V, U, A]) FromJSON(b []byte, v V) error

func (SliceField[V, U, A]) IsEmpty added in v1.1.0

func (f SliceField[V, U, A]) IsEmpty(v V) bool

func (SliceField[V, U, A]) ReadFrom added in v1.1.0

func (f SliceField[V, U, A]) ReadFrom(r *Reader, n uint, v V) bool

func (SliceField[V, U, A]) ToJSON added in v1.1.0

func (f SliceField[V, U, A]) ToJSON(w *bytes.Buffer, v V) error

func (SliceField[V, U, A]) WriteTo added in v1.1.0

func (f SliceField[V, U, A]) WriteTo(w *Writer, n uint, v V)

type SliceIndex added in v1.1.0

type SliceIndex[U any] struct {
	S []U
	I int
}

SliceIndex is a slice and an index.

type StringField added in v1.1.0

type StringField[V any] func(v V) *string

StringField is an Accessor for a value's string field.

func (StringField[V]) CopyTo added in v1.1.0

func (f StringField[V]) CopyTo(dst, src V)

func (StringField[V]) Equal added in v1.1.0

func (f StringField[V]) Equal(v, u V) bool

func (StringField[V]) FromJSON added in v1.1.0

func (f StringField[V]) FromJSON(b []byte, v V) error

func (StringField[V]) IsEmpty added in v1.1.0

func (f StringField[V]) IsEmpty(v V) bool

func (StringField[V]) ReadFrom added in v1.1.0

func (f StringField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (StringField[V]) ToJSON added in v1.1.0

func (f StringField[V]) ToJSON(w *bytes.Buffer, v V) error

func (StringField[V]) WriteTo added in v1.1.0

func (f StringField[V]) WriteTo(w *Writer, n uint, v V)

type StringPtrField added in v1.1.0

type StringPtrField[V any] func(v V) **string

StringPtrField is an Accessor for a value's string pointer field.

func (StringPtrField[V]) CopyTo added in v1.1.0

func (f StringPtrField[V]) CopyTo(dst, src V)

func (StringPtrField[V]) Equal added in v1.1.0

func (f StringPtrField[V]) Equal(v, u V) bool

func (StringPtrField[V]) FromJSON added in v1.1.0

func (f StringPtrField[V]) FromJSON(b []byte, v V) error

func (StringPtrField[V]) IsEmpty added in v1.1.0

func (f StringPtrField[V]) IsEmpty(v V) bool

func (StringPtrField[V]) ReadFrom added in v1.1.0

func (f StringPtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (StringPtrField[V]) ToJSON added in v1.1.0

func (f StringPtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (StringPtrField[V]) WriteTo added in v1.1.0

func (f StringPtrField[V]) WriteTo(w *Writer, n uint, v V)

type StructField added in v1.1.0

type StructField[V any, U structPtr[W], W any] func(v V) U

StructField is an Accessor for a value's struct field.

func (StructField[V, U, W]) CopyTo added in v1.1.0

func (f StructField[V, U, W]) CopyTo(dst, src V)

func (StructField[V, U, W]) Equal added in v1.1.0

func (f StructField[V, U, W]) Equal(v, u V) bool

func (StructField[V, U, W]) FromJSON added in v1.1.0

func (f StructField[V, U, W]) FromJSON(b []byte, v V) error

func (StructField[V, U, W]) IsEmpty added in v1.1.0

func (f StructField[V, U, W]) IsEmpty(v V) bool

func (StructField[V, U, W]) ReadFrom added in v1.1.0

func (f StructField[V, U, W]) ReadFrom(r *Reader, n uint, v V) bool

func (StructField[V, U, W]) ToJSON added in v1.1.0

func (f StructField[V, U, W]) ToJSON(w *bytes.Buffer, v V) error

func (StructField[V, U, W]) WriteTo added in v1.1.0

func (f StructField[V, U, W]) WriteTo(w *Writer, n uint, v V)

type StructPtrField added in v1.1.0

type StructPtrField[V any, U structPtr[W], W any] func(v V) *U

StructPtrField is an Accessor for a value's struct pointer field.

func (StructPtrField[V, U, W]) CopyTo added in v1.1.0

func (f StructPtrField[V, U, W]) CopyTo(dst, src V)

func (StructPtrField[V, U, W]) Equal added in v1.1.0

func (f StructPtrField[V, U, W]) Equal(v, u V) bool

func (StructPtrField[V, U, W]) FromJSON added in v1.1.0

func (f StructPtrField[V, U, W]) FromJSON(b []byte, v V) error

func (StructPtrField[V, U, W]) IsEmpty added in v1.1.0

func (f StructPtrField[V, U, W]) IsEmpty(v V) bool

func (StructPtrField[V, U, W]) ReadFrom added in v1.1.0

func (f StructPtrField[V, U, W]) ReadFrom(r *Reader, n uint, v V) bool

func (StructPtrField[V, U, W]) ToJSON added in v1.1.0

func (f StructPtrField[V, U, W]) ToJSON(w *bytes.Buffer, v V) error

func (StructPtrField[V, U, W]) WriteTo added in v1.1.0

func (f StructPtrField[V, U, W]) WriteTo(w *Writer, n uint, v V)

type Time added in v1.4.0

type Time time.Time

func (*Time) Copy added in v1.4.0

func (u *Time) Copy() *Time

func (*Time) Equal added in v1.4.0

func (u *Time) Equal(v *Time) bool

func (Time) Get added in v1.4.0

func (u Time) Get() time.Time

func (*Time) MarshalBinary added in v1.4.0

func (u *Time) MarshalBinary() ([]byte, error)

func (*Time) MarshalBinaryV2 added in v1.4.0

func (u *Time) MarshalBinaryV2(e *binary.Encoder) error

func (*Time) MarshalJSON added in v1.4.0

func (u *Time) MarshalJSON() ([]byte, error)

func (*Time) MarshalJSONV2 added in v1.4.0

func (u *Time) MarshalJSONV2(e *json.Encoder) error

func (*Time) Set added in v1.4.0

func (u *Time) Set(v time.Time)

func (*Time) String added in v1.4.0

func (u *Time) String() string

func (*Time) UnmarshalBinary added in v1.4.0

func (u *Time) UnmarshalBinary(b []byte) error

func (*Time) UnmarshalBinaryV2 added in v1.4.0

func (u *Time) UnmarshalBinaryV2(d *binary.Decoder) error

func (*Time) UnmarshalJSON added in v1.4.0

func (u *Time) UnmarshalJSON(b []byte) error

func (*Time) UnmarshalJSONV2 added in v1.4.0

func (u *Time) UnmarshalJSONV2(d *json.Decoder) error

type TimeField added in v1.1.0

type TimeField[V any] func(v V) *time.Time

TimeField is an Accessor for a value's time.Time field.

func (TimeField[V]) CopyTo added in v1.1.0

func (f TimeField[V]) CopyTo(dst, src V)

func (TimeField[V]) Equal added in v1.1.0

func (f TimeField[V]) Equal(v, u V) bool

func (TimeField[V]) FromJSON added in v1.1.0

func (f TimeField[V]) FromJSON(b []byte, v V) error

func (TimeField[V]) IsEmpty added in v1.1.0

func (f TimeField[V]) IsEmpty(v V) bool

func (TimeField[V]) ReadFrom added in v1.1.0

func (f TimeField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (TimeField[V]) ToJSON added in v1.1.0

func (f TimeField[V]) ToJSON(w *bytes.Buffer, v V) error

func (TimeField[V]) WriteTo added in v1.1.0

func (f TimeField[V]) WriteTo(w *Writer, n uint, v V)

type TimePtrField added in v1.1.0

type TimePtrField[V any] func(v V) **time.Time

TimePtrField is an Accessor for a value's time.Time pointer field.

func (TimePtrField[V]) CopyTo added in v1.1.0

func (f TimePtrField[V]) CopyTo(dst, src V)

func (TimePtrField[V]) Equal added in v1.1.0

func (f TimePtrField[V]) Equal(v, u V) bool

func (TimePtrField[V]) FromJSON added in v1.1.0

func (f TimePtrField[V]) FromJSON(b []byte, v V) error

func (TimePtrField[V]) IsEmpty added in v1.1.0

func (f TimePtrField[V]) IsEmpty(v V) bool

func (TimePtrField[V]) ReadFrom added in v1.1.0

func (f TimePtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (TimePtrField[V]) ToJSON added in v1.1.0

func (f TimePtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (TimePtrField[V]) WriteTo added in v1.1.0

func (f TimePtrField[V]) WriteTo(w *Writer, n uint, v V)

type TxIDField added in v1.1.0

type TxIDField[V any] func(v V) *url.TxID

TxIDField is an Accessor for a value's TxID field.

func (TxIDField[V]) CopyTo added in v1.1.0

func (f TxIDField[V]) CopyTo(dst, src V)

func (TxIDField[V]) Equal added in v1.1.0

func (f TxIDField[V]) Equal(v, u V) bool

func (TxIDField[V]) FromJSON added in v1.1.0

func (f TxIDField[V]) FromJSON(b []byte, v V) error

func (TxIDField[V]) IsEmpty added in v1.1.0

func (f TxIDField[V]) IsEmpty(v V) bool

func (TxIDField[V]) ReadFrom added in v1.1.0

func (f TxIDField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (TxIDField[V]) ToJSON added in v1.1.0

func (f TxIDField[V]) ToJSON(w *bytes.Buffer, v V) error

func (TxIDField[V]) WriteTo added in v1.1.0

func (f TxIDField[V]) WriteTo(w *Writer, n uint, v V)

type TxIDPtrField added in v1.1.0

type TxIDPtrField[V any] func(v V) **url.TxID

TxIDPtrField is an Accessor for a value's TxID pointer field.

func (TxIDPtrField[V]) CopyTo added in v1.1.0

func (f TxIDPtrField[V]) CopyTo(dst, src V)

func (TxIDPtrField[V]) Equal added in v1.1.0

func (f TxIDPtrField[V]) Equal(v, u V) bool

func (TxIDPtrField[V]) FromJSON added in v1.1.0

func (f TxIDPtrField[V]) FromJSON(b []byte, v V) error

func (TxIDPtrField[V]) IsEmpty added in v1.1.0

func (f TxIDPtrField[V]) IsEmpty(v V) bool

func (TxIDPtrField[V]) ReadFrom added in v1.1.0

func (f TxIDPtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (TxIDPtrField[V]) ToJSON added in v1.1.0

func (f TxIDPtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (TxIDPtrField[V]) WriteTo added in v1.1.0

func (f TxIDPtrField[V]) WriteTo(w *Writer, n uint, v V)

type TypeDefinition added in v1.4.0

type TypeDefinition struct {
	Name   string
	Fields *[]*TypeField
}

func (*TypeDefinition) Resolve added in v1.4.0

func (td *TypeDefinition) Resolve(v any) (eipResolvedValue, error)

type TypeField added in v1.4.0

type TypeField struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

func NewTypeField added in v1.4.0

func NewTypeField(n string, tp string) *TypeField

type TypeSet added in v1.4.0

type TypeSet map[string][]*TypeField

func (TypeSet) AddField added in v1.4.0

func (s TypeSet) AddField(base, name, typ string)

type UintField added in v1.1.0

type UintField[V any] func(v V) *uint64

UintField is an Accessor for a value's uint64 field.

func (UintField[V]) CopyTo added in v1.1.0

func (f UintField[V]) CopyTo(dst, src V)

func (UintField[V]) Equal added in v1.1.0

func (f UintField[V]) Equal(v, u V) bool

func (UintField[V]) FromJSON added in v1.1.0

func (f UintField[V]) FromJSON(b []byte, v V) error

func (UintField[V]) IsEmpty added in v1.1.0

func (f UintField[V]) IsEmpty(v V) bool

func (UintField[V]) ReadFrom added in v1.1.0

func (f UintField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (UintField[V]) ToJSON added in v1.1.0

func (f UintField[V]) ToJSON(w *bytes.Buffer, v V) error

func (UintField[V]) WriteTo added in v1.1.0

func (f UintField[V]) WriteTo(w *Writer, n uint, v V)

type UintPtrField added in v1.1.0

type UintPtrField[V any] func(v V) **uint64

UintPtrField is an Accessor for a value's uint64 pointer field.

func (UintPtrField[V]) CopyTo added in v1.1.0

func (f UintPtrField[V]) CopyTo(dst, src V)

func (UintPtrField[V]) Equal added in v1.1.0

func (f UintPtrField[V]) Equal(v, u V) bool

func (UintPtrField[V]) FromJSON added in v1.1.0

func (f UintPtrField[V]) FromJSON(b []byte, v V) error

func (UintPtrField[V]) IsEmpty added in v1.1.0

func (f UintPtrField[V]) IsEmpty(v V) bool

func (UintPtrField[V]) ReadFrom added in v1.1.0

func (f UintPtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (UintPtrField[V]) ToJSON added in v1.1.0

func (f UintPtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (UintPtrField[V]) WriteTo added in v1.1.0

func (f UintPtrField[V]) WriteTo(w *Writer, n uint, v V)

type UnionRegistry added in v1.1.0

type UnionRegistry[T interface {
	comparable
	EnumValueGetter
}, V interface {
	Type() T
	UnionValue
}] struct {
	// contains filtered or unexported fields
}

func (*UnionRegistry[T, V]) Equal added in v1.1.0

func (r *UnionRegistry[T, V]) Equal(u, v V) bool

func (*UnionRegistry[T, V]) New added in v1.1.0

func (r *UnionRegistry[T, V]) New(typ T) (V, bool)

func (*UnionRegistry[T, V]) Register added in v1.1.0

func (r *UnionRegistry[T, V]) Register(str string, new func() V, equal func(V, V) bool) error

func (*UnionRegistry[T, V]) TypeByName added in v1.1.0

func (r *UnionRegistry[T, V]) TypeByName(s string) (T, bool)

func (*UnionRegistry[T, V]) TypeByValue added in v1.1.0

func (r *UnionRegistry[T, V]) TypeByValue(v uint64) (T, bool)

func (*UnionRegistry[T, V]) TypeName added in v1.1.0

func (r *UnionRegistry[T, V]) TypeName(typ T) (string, bool)

type UnionValue added in v1.1.0

type UnionValue interface {
	BinaryValue
	UnmarshalFieldsFrom(reader *Reader) error
}

type UrlField added in v1.1.0

type UrlField[V any] func(v V) *url.URL

UrlField is an Accessor for a value's Url field.

func (UrlField[V]) CopyTo added in v1.1.0

func (f UrlField[V]) CopyTo(dst, src V)

func (UrlField[V]) Equal added in v1.1.0

func (f UrlField[V]) Equal(v, u V) bool

func (UrlField[V]) FromJSON added in v1.1.0

func (f UrlField[V]) FromJSON(b []byte, v V) error

func (UrlField[V]) IsEmpty added in v1.1.0

func (f UrlField[V]) IsEmpty(v V) bool

func (UrlField[V]) ReadFrom added in v1.1.0

func (f UrlField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (UrlField[V]) ToJSON added in v1.1.0

func (f UrlField[V]) ToJSON(w *bytes.Buffer, v V) error

func (UrlField[V]) WriteTo added in v1.1.0

func (f UrlField[V]) WriteTo(w *Writer, n uint, v V)

type UrlPtrField added in v1.1.0

type UrlPtrField[V any] func(v V) **url.URL

UrlPtrField is an Accessor for a value's Url pointer field.

func (UrlPtrField[V]) CopyTo added in v1.1.0

func (f UrlPtrField[V]) CopyTo(dst, src V)

func (UrlPtrField[V]) Equal added in v1.1.0

func (f UrlPtrField[V]) Equal(v, u V) bool

func (UrlPtrField[V]) FromJSON added in v1.1.0

func (f UrlPtrField[V]) FromJSON(b []byte, v V) error

func (UrlPtrField[V]) IsEmpty added in v1.1.0

func (f UrlPtrField[V]) IsEmpty(v V) bool

func (UrlPtrField[V]) ReadFrom added in v1.1.0

func (f UrlPtrField[V]) ReadFrom(r *Reader, n uint, v V) bool

func (UrlPtrField[V]) ToJSON added in v1.1.0

func (f UrlPtrField[V]) ToJSON(w *bytes.Buffer, v V) error

func (UrlPtrField[V]) WriteTo added in v1.1.0

func (f UrlPtrField[V]) WriteTo(w *Writer, n uint, v V)

type Writer

type Writer struct {
	IgnoreSizeLimit bool
	// contains filtered or unexported fields
}

A Writer is used to binary-encode a struct and write it to a io.Writer.

If any attempt to write fails, all subsequent write methods are no-ops until Err is called.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter creates a new Writer.

func (*Writer) Reset

func (w *Writer) Reset(fieldNames []string) (written int, lastField uint, err error)

Reset returns the total number of bytes written, the last field written, and an error, if one occurred, and resets the writer.

If a list of field names is provided, the error will be formatted as "field <name>: <err>".

func (*Writer) WriteBigInt

func (w *Writer) WriteBigInt(n uint, v *big.Int)

WriteBigInt writes the value as a big-endian byte slice.

func (*Writer) WriteBool

func (w *Writer) WriteBool(n uint, v bool)

WriteBool writes the value as a varint-encoded unsigned integer.

func (*Writer) WriteBytes

func (w *Writer) WriteBytes(n uint, v []byte)

WriteBytes writes the length of the value as a varint-encoded unsigned integer followed by the value.

func (*Writer) WriteDuration

func (w *Writer) WriteDuration(n uint, v time.Duration)

WriteDuration writes the value as seconds and nanoseconds, each as a varint-encoded unsigned integer.

func (*Writer) WriteEnum

func (w *Writer) WriteEnum(n uint, v EnumValueGetter)

WriteEnum writes the value as a varint-encoded unsigned integer.

func (*Writer) WriteFloat

func (w *Writer) WriteFloat(n uint, v float64)

WriteFloat writes the value as a IEEE 754 encoded floating point number.

func (*Writer) WriteHash

func (w *Writer) WriteHash(n uint, v *[32]byte)

WriteHash writes the value without modification.

func (*Writer) WriteInt

func (w *Writer) WriteInt(n uint, v int64)

WriteInt writes the value as a varint-encoded signed integer.

func (*Writer) WriteString

func (w *Writer) WriteString(n uint, v string)

WriteString writes the length of the value as a varint-encoded unsigned integer followed by the value.

func (*Writer) WriteTime

func (w *Writer) WriteTime(n uint, v time.Time)

WriteTime writes the value as a varint-encoded UTC Unix timestamp (signed).

func (*Writer) WriteTxid

func (w *Writer) WriteTxid(n uint, v *url.TxID)

WriteTxid writes the value as a string.

func (*Writer) WriteUint

func (w *Writer) WriteUint(n uint, v uint64)

WriteUint writes the value as a varint-encoded unsigned integer.

func (*Writer) WriteUrl

func (w *Writer) WriteUrl(n uint, v *url.URL)

WriteUrl writes the value as a string.

func (*Writer) WriteValue

func (w *Writer) WriteValue(n uint, marshal func() ([]byte, error))

WriteValue marshals the value and writes it as a byte slice.

Jump to

Keyboard shortcuts

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