serialization

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package serialization provides persisted payload codecs and compatibility fingerprints.

Index

Constants

View Source
const JSONCodecVersion = "json/v1"

JSONCodecVersion identifies the persisted format produced by JSONCodec.

View Source
const (
	// PayloadWarningThreshold is the encoded size above which Cord reports a large payload.
	PayloadWarningThreshold = 256 * 1024
)

Variables

This section is empty.

Functions

func SignatureFingerprint

func SignatureFingerprint(inputFingerprints []string, outputFingerprint string) string

SignatureFingerprint hashes ordered input and output type fingerprints.

func TypeFingerprint

func TypeFingerprint(valueType reflect.Type, codecVersion string) (string, error)

TypeFingerprint hashes a Go type identity together with its codec version. Generic instantiations are rejected because reflection does not expose their type arguments with enough package information to identify them canonically.

Types

type JSONCodec

type JSONCodec[T any] struct{}

JSONCodec encodes and decodes one non-interface Go type using encoding/json. Its zero value is ready to use.

func NewJSONCodec

func NewJSONCodec[T any]() (JSONCodec[T], error)

NewJSONCodec creates a typed JSON codec. It rejects T when its reachable structure contains an interface because encoding/json cannot preserve arbitrary dynamic Go types, integer widths, or typed nil values when decoding an interface.

func (JSONCodec[T]) Decode

func (codec JSONCodec[T]) Decode(payload []byte) (T, error)

Decode deserializes payload directly into T.

func (JSONCodec[T]) Encode

func (codec JSONCodec[T]) Encode(value T) ([]byte, error)

Encode serializes value without truncating the resulting payload.

func (JSONCodec[T]) TypeFingerprint

func (codec JSONCodec[T]) TypeFingerprint() (string, error)

TypeFingerprint returns the codec-specific fingerprint for T. It computes the value lazily, so a zero-value JSONCodec never yields an empty fingerprint.

type PayloadDiagnostic

type PayloadDiagnostic struct {
	Size      int
	Threshold int
}

PayloadDiagnostic describes an unusually large encoded payload without exposing its contents.

func DiagnosePayload

func DiagnosePayload(payload []byte) (PayloadDiagnostic, bool)

DiagnosePayload reports whether payload exceeds the recommended warning threshold.

Jump to

Keyboard shortcuts

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