codec

package
v1.12.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: BSD-3-Clause Imports: 5 Imported by: 180

Documentation

Index

Constants

View Source
const (
	VersionSize = wrappers.ShortLen
)

Variables

View Source
var (
	ErrUnsupportedType           = errors.New("unsupported type")
	ErrMaxSliceLenExceeded       = errors.New("max slice length exceeded")
	ErrDoesNotImplementInterface = errors.New("does not implement interface")
	ErrUnexportedField           = errors.New("unexported field")
	ErrMarshalZeroLength         = errors.New("can't marshal zero length value")
	ErrUnmarshalZeroLength       = errors.New("can't unmarshal zero length value")
)
View Source
var (
	ErrUnknownVersion    = errors.New("unknown codec version")
	ErrMarshalNil        = errors.New("can't marshal nil pointer or interface")
	ErrUnmarshalNil      = errors.New("can't unmarshal nil")
	ErrUnmarshalTooBig   = errors.New("byte array exceeds maximum length")
	ErrCantPackVersion   = errors.New("couldn't pack codec version")
	ErrCantUnpackVersion = errors.New("couldn't unpack codec version")
	ErrDuplicatedVersion = errors.New("duplicated codec version")
	ErrExtraSpace        = errors.New("trailing buffer space")
)
View Source
var ErrDuplicateType = errors.New("duplicate type registration")

Functions

This section is empty.

Types

type Codec

type Codec interface {
	MarshalInto(interface{}, *wrappers.Packer) error
	UnmarshalFrom(*wrappers.Packer, interface{}) error

	// Returns the size, in bytes, of [value] when it's marshaled
	Size(value interface{}) (int, error)
}

Codec marshals and unmarshals

type GeneralCodec

type GeneralCodec interface {
	Codec
	Registry
}

GeneralCodec marshals and unmarshals structs including interfaces

type Manager

type Manager interface {
	// Associate the given codec with the given version ID
	RegisterCodec(version uint16, codec Codec) error

	// Size returns the size, in bytes, of [value] when it's marshaled
	// using the codec with the given version.
	// RegisterCodec must have been called with that version.
	// If [value] is nil, returns [ErrMarshalNil]
	Size(version uint16, value interface{}) (int, error)

	// Marshal the given value using the codec with the given version.
	// RegisterCodec must have been called with that version.
	Marshal(version uint16, source interface{}) (destination []byte, err error)

	// Unmarshal the given bytes into the given destination. [destination] must
	// be a pointer or an interface. Returns the version of the codec that
	// produces the given bytes.
	Unmarshal(source []byte, destination interface{}) (version uint16, err error)
}

Manager describes the functionality for managing codec versions.

func NewDefaultManager

func NewDefaultManager() Manager

NewDefaultManager returns a new codec manager.

func NewManager

func NewManager(maxSize int) Manager

NewManager returns a new codec manager.

type Registry

type Registry interface {
	RegisterType(interface{}) error
}

Registry registers new types that can be marshaled into

Directories

Path Synopsis
Package codecmock is a generated GoMock package.
Package codecmock is a generated GoMock package.
Package codectest provides a test suite for testing codec implementations.
Package codectest provides a test suite for testing codec implementations.

Jump to

Keyboard shortcuts

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