codec

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package codec provides serialization codecs for KV values.

Codecs handle the marshalling and unmarshalling of Go types to and from byte slices for storage in KV backends. The default codec is JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec interface {
	// Encode serializes v into bytes.
	Encode(v any) ([]byte, error)

	// Decode deserializes data into v. v must be a pointer.
	Decode(data []byte, v any) error

	// Name returns the codec identifier (e.g., "json", "msgpack", "protobuf").
	Name() string
}

Codec serializes and deserializes values for KV storage.

func JSON

func JSON() Codec

JSON returns a codec that uses encoding/json for serialization. This is the default codec used by the Store when none is specified.

func MsgPack

func MsgPack() Codec

MsgPack returns a codec that uses MessagePack for serialization. MsgPack is more compact than JSON and faster to encode/decode.

type Gob

type Gob struct{}

Gob implements Codec using Go's gob encoding. Types must be registered with gob.Register if they are interface values.

func (Gob) Decode

func (Gob) Decode(data []byte, v any) error

Decode deserialises data into v using gob encoding.

func (Gob) Encode

func (Gob) Encode(v any) ([]byte, error)

Encode serialises v using gob encoding.

func (Gob) Name

func (Gob) Name() string

Name returns the codec name.

type Protobuf

type Protobuf struct{}

Protobuf implements Codec using Protocol Buffers. Values must implement proto.Message.

func (Protobuf) Decode

func (Protobuf) Decode(data []byte, v any) error

Decode deserialises data into v using Protocol Buffers.

func (Protobuf) Encode

func (Protobuf) Encode(v any) ([]byte, error)

Encode serialises v using Protocol Buffers.

func (Protobuf) Name

func (Protobuf) Name() string

Name returns the codec name.

Jump to

Keyboard shortcuts

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