encoding

package
v1.8.8-0...-6a25a8b Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package encoding provides pluggable marshal/unmarshal helpers used by SOP. JSON is the default, and helpers can pass through []byte values without copying.

Index

Constants

This section is empty.

Variables

View Source
var BlobMarshaler = DefaultMarshaler

BlobMarshaler is used for blob payloads. It defaults to DefaultMarshaler but can be overridden.

View Source
var DefaultMarshaler = NewMarshaler()

DefaultMarshaler is the package-wide default marshaler using JSON encoding.

Functions

func Marshal

func Marshal[T any](v T) ([]byte, error)

Marshal is a generic helper that marshals values and passes through byte slices without copying.

func Unmarshal

func Unmarshal[T any](ba []byte, v *T) error

Unmarshal is a generic helper that unmarshals values and passes through byte slices without copying.

Types

type HandleEncoder

type HandleEncoder struct{}

HandleEncoder encodes and decodes sop.Handle values to and from compact byte representations.

func NewHandleMarshaler

func NewHandleMarshaler() *HandleEncoder

NewHandleMarshaler returns a new HandleEncoder.

func (HandleEncoder) Marshal

func (he HandleEncoder) Marshal(v sop.Handle, buffer []byte) ([]byte, error)

Marshal encodes a Handle into the provided buffer and returns the resulting bytes.

func (HandleEncoder) Unmarshal

func (he HandleEncoder) Unmarshal(data []byte, target *sop.Handle) error

Unmarshal decodes data into the target Handle.

func (HandleEncoder) UnmarshalLogicalID

func (he HandleEncoder) UnmarshalLogicalID(data []byte) (sop.UUID, error)

UnmarshalLogicalID decodes only the logical UUID from an encoded Handle buffer.

type Marshaler

type Marshaler interface {
	// Marshal encodes any object to a byte slice.
	Marshal(v any) ([]byte, error)
	// Unmarshal decodes data back into the provided object pointer.
	Unmarshal(data []byte, v any) error
}

Marshaler defines methods to marshal/unmarshal values to/from byte slices.

func NewMarshaler

func NewMarshaler() Marshaler

NewMarshaler returns a Marshaler implemented with the standard library JSON package. JSON is chosen as default for its streaming capabilities useful for large value payloads.

Jump to

Keyboard shortcuts

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