Documentation ¶
Index ¶
- func DecodeEach(encoded []byte, into reflect.Value, numElements int, tc TypeCodec) (any, []byte, error)
- func EncodeEach(value reflect.Value, into []byte, tc TypeCodec) ([]byte, error)
- func IndirectIfPointer(value reflect.Value) (reflect.Value, error)
- func SafeDecode[T interface{}](raw []byte, size int, call func([]byte) T) (T, []byte, error)
- type Builder
- type CodecFromTypeCodec
- func (c CodecFromTypeCodec) CreateType(itemType string, _ bool) (any, error)
- func (c CodecFromTypeCodec) Decode(_ context.Context, raw []byte, into any, itemType string) error
- func (c CodecFromTypeCodec) Encode(_ context.Context, item any, itemType string) ([]byte, error)
- func (c CodecFromTypeCodec) GetMaxDecodingSize(ctx context.Context, n int, itemType string) (int, error)
- func (c CodecFromTypeCodec) GetMaxEncodingSize(_ context.Context, n int, itemType string) (int, error)
- type Empty
- type LenientCodecFromTypeCodec
- func (c LenientCodecFromTypeCodec) CreateType(itemType string, forEncoding bool) (any, error)
- func (c LenientCodecFromTypeCodec) Decode(ctx context.Context, raw []byte, into any, itemType string) error
- func (c LenientCodecFromTypeCodec) Encode(ctx context.Context, item any, itemType string) ([]byte, error)
- func (c LenientCodecFromTypeCodec) GetMaxDecodingSize(ctx context.Context, n int, itemType string) (int, error)
- func (c LenientCodecFromTypeCodec) GetMaxEncodingSize(ctx context.Context, n int, itemType string) (int, error)
- type NamedTypeCodec
- type NotNilPointer
- type TopLevelCodec
- type TypeCodec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeEach ¶
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 ¶
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) GetMaxDecodingSize ¶
func (CodecFromTypeCodec) GetMaxEncodingSize ¶
type LenientCodecFromTypeCodec ¶
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) GetMaxDecodingSize ¶
func (LenientCodecFromTypeCodec) GetMaxEncodingSize ¶
type NamedTypeCodec ¶
type NotNilPointer ¶
type NotNilPointer struct {
Elm TypeCodec
}
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
type TopLevelCodec ¶
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) }