encoding

package
v2.0.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilRegistry      = errors.New("encoding: registry is nil")
	ErrNilCodec         = errors.New("encoding: codec is nil")
	ErrEmptyContentType = errors.New("encoding: content type is empty")
	ErrCodecNotFound    = errors.New("encoding: codec not found")
	ErrRegistryNotFound = errors.New("encoding: registry not found in context")
)

Functions

func WithRegistry

func WithRegistry(ctx context.Context, registry *Registry) context.Context

WithRegistry adds registry to context.

Types

type Codec

type Codec interface {
	ContentType() string
	Encoder
	Decoder
}

Codec combines encoder and decoder capabilities.

func CodecFrom

func CodecFrom(ctx context.Context, contentType string) (Codec, error)

CodecFrom resolves codec by content type from registry in context.

type CodecRegistrar

type CodecRegistrar interface {
	Register(codec Codec) error
}

Registry stores codecs by content type.

type Decoder

type Decoder interface {
	Decode(data []byte) (runtime.Value, error)
	DecodeWith() DecoderConfigurer
}

Decoder converts bytes into runtime values.

func DecoderFrom

func DecoderFrom(ctx context.Context, contentType string) (Decoder, error)

DecoderFrom resolves decoder by content type from registry in context.

type DecoderConfigurer

type DecoderConfigurer interface {
	PreHook(PreDecoderHook) DecoderConfigurer
	PostHook(PostDecoderHook) DecoderConfigurer
	Decoder() Decoder
}

type Encoder

type Encoder interface {
	Encode(value runtime.Value) ([]byte, error)
	EncodeWith() EncoderConfigurer
}

Encoder converts runtime values into bytes.

func EncoderFrom

func EncoderFrom(ctx context.Context, contentType string) (Encoder, error)

EncoderFrom resolves encoder by content type from registry in context.

type EncoderConfigurer

type EncoderConfigurer interface {
	PreHook(PreEncoderHook) EncoderConfigurer
	PostHook(PostEncoderHook) EncoderConfigurer
	Encoder() Encoder
}

type PostDecoderHook

type PostDecoderHook func(data []byte, err error) error

type PostEncoderHook

type PostEncoderHook func(value runtime.Value, err error) error

type PreDecoderHook

type PreDecoderHook func(data []byte) error

type PreEncoderHook

type PreEncoderHook func(value runtime.Value) error

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry stores codecs by content type.

func NewEmptyRegistry

func NewEmptyRegistry() *Registry

NewEmptyRegistry creates a registry without predefined codecs.

func NewRegistry

func NewRegistry(codecs ...Codec) *Registry

NewRegistry creates a registry seeded with the provided codecs.

func RegistryFrom

func RegistryFrom(ctx context.Context) (*Registry, error)

RegistryFrom gets registry from context.

func (*Registry) Clone

func (r *Registry) Clone() *Registry

func (*Registry) Codec

func (r *Registry) Codec(contentType string) (Codec, error)

Codec returns a codec for the content type.

func (*Registry) Decoder

func (r *Registry) Decoder(contentType string) (Decoder, error)

Decoder returns a decoder for the content type.

func (*Registry) Encoder

func (r *Registry) Encoder(contentType string) (Encoder, error)

Encoder returns an encoder for the content type.

func (*Registry) Register

func (r *Registry) Register(codec Codec) error

Register stores a full codec for the content type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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