codec

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BytesCodec

type BytesCodec struct{}

func (BytesCodec) Decode

func (BytesCodec) Decode(b []byte) ([]byte, error)

func (BytesCodec) Encode

func (BytesCodec) Encode(b []byte) ([]byte, error)

type CBORCodec

type CBORCodec[V any] struct {
	// contains filtered or unexported fields
}

func MustCBORCodec

func MustCBORCodec[V any](deterministic bool) CBORCodec[V]

MustCBORCodec is a convenience helper that panics on construction error.

func NewCBORCodec

func NewCBORCodec[V any](deterministic bool) (CBORCodec[V], error)

NewCBORCodec creates a CBOR codec. * if deterministic == true, it uses Core Deterministic Encoding (RFC 8949). * Otherwise, it uses PreferredUnsortedEncOptions (sensible defaults). Also sets time encoding to RFC3339Nano.

func (CBORCodec[V]) Decode

func (c CBORCodec[V]) Decode(b []byte) (V, error)

func (CBORCodec[V]) Encode

func (c CBORCodec[V]) Encode(v V) ([]byte, error)

type Codec

type Codec[V any] interface {
	Encode(V) ([]byte, error)
	Decode([]byte) (V, error)
}

Codec encodes/decodes values V to []byte for storage.

type JSONCodec

type JSONCodec[V any] struct{}

func (JSONCodec[V]) Decode

func (JSONCodec[V]) Decode(b []byte) (V, error)

func (JSONCodec[V]) Encode

func (JSONCodec[V]) Encode(v V) ([]byte, error)

type LimitCodec

type LimitCodec[V any] struct {
	Inner interface {
		Encode(V) ([]byte, error)
		Decode([]byte) (V, error)
	}
	MaxDecode int // bytes
}

func (LimitCodec[V]) Decode

func (c LimitCodec[V]) Decode(b []byte) (V, error)

func (LimitCodec[V]) Encode

func (c LimitCodec[V]) Encode(v V) ([]byte, error)

type MsgpackCodec

type MsgpackCodec[V any] struct{}

func (MsgpackCodec[V]) Decode

func (MsgpackCodec[V]) Decode(b []byte) (V, error)

func (MsgpackCodec[V]) Encode

func (MsgpackCodec[V]) Encode(v V) ([]byte, error)

type ProtobufCodec

type ProtobufCodec[T proto.Message] struct {
	// contains filtered or unexported fields
}

func NewProtobufCodec

func NewProtobufCodec[T proto.Message](ctor func() T) ProtobufCodec[T]

func (ProtobufCodec[T]) Decode

func (c ProtobufCodec[T]) Decode(b []byte) (T, error)

func (ProtobufCodec[T]) Encode

func (c ProtobufCodec[T]) Encode(v T) ([]byte, error)

type StringCodec

type StringCodec struct{}

For string payloads

func (StringCodec) Decode

func (StringCodec) Decode(b []byte) (string, error)

func (StringCodec) Encode

func (StringCodec) Encode(s string) ([]byte, error)

Jump to

Keyboard shortcuts

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