codec

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveSchemaID

func ResolveSchemaID(t reflect.Type) string

ResolveSchemaID returns the schema ID for a type. If the type implements VangoSchema, uses that; otherwise uses the fully-qualified Go type name.

func ResolveSchemaIDForValue

func ResolveSchemaIDForValue(v any) string

ResolveSchemaIDForValue returns the schema ID for a value.

func SetDefault

func SetDefault(c Codec)

SetDefault sets the default codec (useful for tests).

Types

type Codec

type Codec interface {
	ID() CodecID
	Version() CodecVersion
	Encode(v any) ([]byte, error)
	Decode(data []byte, v any) error
}

Codec encodes and decodes values.

func Default

func Default() Codec

Default returns the default codec (cbor:v1).

func NewCBORCodec

func NewCBORCodec() Codec

NewCBORCodec creates the default CBOR codec. VersionV2 preserves nil container semantics (nil != empty) and therefore intentionally changes persisted fingerprints, requiring cold deploy handling.

func NewJSONCodec

func NewJSONCodec() Codec

NewJSONCodec creates a JSON codec.

type CodecID

type CodecID string

CodecID identifies the serialization format.

const (
	CodecCBOR CodecID = "cbor"
	CodecJSON CodecID = "json"
)

type CodecVersion

type CodecVersion string

CodecVersion tracks format changes within a codec.

const (
	VersionV1 CodecVersion = "v1"
	VersionV2 CodecVersion = "v2"
)

type Fingerprint

type Fingerprint [32]byte

Fingerprint uniquely identifies a type's serialization format. It is computed as SHA256(CodecID + ":" + CodecVersion + ":" + SchemaID).

func ComputeFingerprint

func ComputeFingerprint(codecID CodecID, version CodecVersion, schemaID string) Fingerprint

ComputeFingerprint calculates a fingerprint for a type.

func ParseFingerprint

func ParseFingerprint(s string) (Fingerprint, error)

ParseFingerprint parses a fingerprint string. Accepts "fp:v1:<hex>" where <hex> is 64 lowercase hex chars.

func (Fingerprint) String

func (f Fingerprint) String() string

String returns the hex representation with prefix.

type VangoSchema

type VangoSchema interface {
	VangoSchemaID() string
}

VangoSchema allows types to provide explicit schema identifiers. This is recommended for persisted state to survive type renames.

Jump to

Keyboard shortcuts

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