encodings

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeEach

func DecodeEach(encoded []byte, into reflect.Value, numElements int, tc TypeCodec) (any, []byte, error)

func EncodeEach

func EncodeEach(value reflect.Value, into []byte, tc TypeCodec) ([]byte, error)

func IndirectIfPointer

func IndirectIfPointer(value reflect.Value) (reflect.Value, error)

func SafeDecode

func SafeDecode[T interface{}](raw []byte, size int, call func([]byte) T) (T, []byte, error)

Types

type Builder

type Builder interface {
	Bool() TypeCodec
	Int8() TypeCodec
	Int16() TypeCodec
	Int32() TypeCodec
	Int64() TypeCodec
	Uint8() TypeCodec
	Uint16() TypeCodec
	Uint32() TypeCodec
	Uint64() TypeCodec
	String(maxLen uint) (TypeCodec, error)
	Float32() TypeCodec
	Float64() TypeCodec
	OracleID() TypeCodec
	Int(bytes uint) (TypeCodec, error)
	Uint(bytes uint) (TypeCodec, error)
	BigInt(bytes uint, signed bool) (TypeCodec, error)
}

type CodecFromTypeCodec

type CodecFromTypeCodec map[string]TypeCodec

CodecFromTypeCodec maps TypeCodec to types.RemoteCodec, using the key as the itemType If the TypeCodec is a TopLevelCodec, GetMaxEncodingSize and GetMaxDecodingSize will call SizeAtTopLevel instead of Size.

func (CodecFromTypeCodec) CreateType

func (c CodecFromTypeCodec) CreateType(itemType string, _ bool) (any, error)

func (CodecFromTypeCodec) Decode

func (c CodecFromTypeCodec) Decode(_ context.Context, raw []byte, into any, itemType string) error

func (CodecFromTypeCodec) Encode

func (c CodecFromTypeCodec) Encode(_ context.Context, item any, itemType string) ([]byte, error)

func (CodecFromTypeCodec) GetMaxDecodingSize

func (c CodecFromTypeCodec) GetMaxDecodingSize(ctx context.Context, n int, itemType string) (int, error)

func (CodecFromTypeCodec) GetMaxEncodingSize

func (c CodecFromTypeCodec) GetMaxEncodingSize(_ context.Context, n int, itemType string) (int, error)

type Empty

type Empty struct{}

func (Empty) Decode

func (Empty) Decode(encoded []byte) (any, []byte, error)

func (Empty) Encode

func (Empty) Encode(_ any, into []byte) ([]byte, error)

func (Empty) FixedSize

func (Empty) FixedSize() (int, error)

func (Empty) GetType

func (Empty) GetType() reflect.Type

func (Empty) Size

func (Empty) Size(numItems int) (int, error)

type LenientCodecFromTypeCodec

type LenientCodecFromTypeCodec map[string]TypeCodec

LenientCodecFromTypeCodec works like CodecFromTypeCodec but allows for extra bits at the end

func (LenientCodecFromTypeCodec) CreateType

func (c LenientCodecFromTypeCodec) CreateType(itemType string, forEncoding bool) (any, error)

func (LenientCodecFromTypeCodec) Decode

func (c LenientCodecFromTypeCodec) Decode(ctx context.Context, raw []byte, into any, itemType string) error

func (LenientCodecFromTypeCodec) Encode

func (c LenientCodecFromTypeCodec) Encode(ctx context.Context, item any, itemType string) ([]byte, error)

func (LenientCodecFromTypeCodec) GetMaxDecodingSize

func (c LenientCodecFromTypeCodec) GetMaxDecodingSize(ctx context.Context, n int, itemType string) (int, error)

func (LenientCodecFromTypeCodec) GetMaxEncodingSize

func (c LenientCodecFromTypeCodec) GetMaxEncodingSize(ctx context.Context, n int, itemType string) (int, error)

type NamedTypeCodec

type NamedTypeCodec struct {
	Name  string
	Codec TypeCodec
}

type NotNilPointer

type NotNilPointer struct {
	Elm TypeCodec
}

func (*NotNilPointer) Decode

func (n *NotNilPointer) Decode(encoded []byte) (any, []byte, error)

func (*NotNilPointer) Encode

func (n *NotNilPointer) Encode(value any, into []byte) ([]byte, error)

func (*NotNilPointer) FixedSize

func (n *NotNilPointer) FixedSize() (int, error)

func (*NotNilPointer) GetType

func (n *NotNilPointer) GetType() reflect.Type

func (*NotNilPointer) Size

func (n *NotNilPointer) Size(numItems int) (int, error)

type TopLevelCodec

type TopLevelCodec interface {
	TypeCodec
	SizeAtTopLevel(numItems int) (int, error)
}

TopLevelCodec is a TypeCodec that can be encoded at the top level of a report. This allows each member to be called with Size(numItems) when SiteAtTopLevel(numItems) is called.

func NewStructCodec

func NewStructCodec(fields []NamedTypeCodec) (c TopLevelCodec, err error)

NewStructCodec creates a codec that encodes fields with the given names and codecs in-order. Note: To verify fields are not defaulted, Codecs with non-pointer types in fields will be wrapped with encodings.NotNilPointer

type TypeCodec

type TypeCodec interface {
	Encode(value any, into []byte) ([]byte, error)
	Decode(encoded []byte) (any, []byte, error)
	GetType() reflect.Type

	// Size returns the size of the encoded value in bytes if there are N reports.
	// As such, any nested elements should be called with FixedSize to determine their size, unless it's implicit how
	// how many nested items there will be.
	// As an example, a struct { A: []int } should return the size of numItems ints, but a struct { A: [][]int }
	// should return an error, as each report could have a different number of elements in their slice.
	Size(numItems int) (int, error)

	// FixedSize returns the size of the encoded value, without providing a count of elements.
	// If a count of elements is required to know the size, an error must be returned.
	FixedSize() (int, error)
}

func NewArray

func NewArray(numElements int, underlying TypeCodec) (TypeCodec, error)

func NewSlice

func NewSlice(field, size TypeCodec) (TypeCodec, error)

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

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