codec

package
v0.0.3 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 Bytes added in v0.0.3

type Bytes struct{}

func (Bytes) Decode added in v0.0.3

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

func (Bytes) Encode added in v0.0.3

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

type CBOR added in v0.0.3

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

func MustCBOR added in v0.0.3

func MustCBOR[V any](deterministic bool) CBOR[V]

MustCBOR is a convenience helper that panics on construction error.

func NewCBOR added in v0.0.3

func NewCBOR[V any](deterministic bool) (CBOR[V], error)

NewCBOR 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 (CBOR[V]) Decode added in v0.0.3

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

func (CBOR[V]) Encode added in v0.0.3

func (c CBOR[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 JSON added in v0.0.3

type JSON[V any] struct{}

func (JSON[V]) Decode added in v0.0.3

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

func (JSON[V]) Encode added in v0.0.3

func (JSON[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 Msgpack added in v0.0.3

type Msgpack[V any] struct{}

func (Msgpack[V]) Decode added in v0.0.3

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

func (Msgpack[V]) Encode added in v0.0.3

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

type Protobuf added in v0.0.3

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

func NewProtobuf added in v0.0.3

func NewProtobuf[T proto.Message](ctor func() T) Protobuf[T]

func (Protobuf[T]) Decode added in v0.0.3

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

func (Protobuf[T]) Encode added in v0.0.3

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

type String added in v0.0.3

type String struct{}

For string payloads

func (String) Decode added in v0.0.3

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

func (String) Encode added in v0.0.3

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

Jump to

Keyboard shortcuts

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