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 ¶
var BlobMarshaler = DefaultMarshaler
BlobMarshaler is used for blob payloads. It defaults to DefaultMarshaler but can be overridden.
var DefaultMarshaler = NewMarshaler()
DefaultMarshaler is the package-wide default marshaler using JSON encoding.
Functions ¶
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 ¶
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.