Documentation
¶
Overview ¶
Package codecs is provides an interface to encode and decode content types to and from byte sequences.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownMimeType happens when you request a codec for a unknown mime type. ErrUnknownMimeType = errors.New("unknown mime type given") // ErrUnknownValueType happens when you give a golang type to a codec that doesn't understand it. ErrUnknownValueType = errors.New("unknown golang type given") )
var ( // ErrNoFileMarshaler happens when we haven't found a marshaler for the given file. ErrNoFileMarshaler = errors.New("no marshaler for the given file found") )
var Plugins = container.NewMap[string, Marshaler]() //nolint:gochecknoglobals
Plugins is the registry for codec plugins.
Functions ¶
Types ¶
type DecoderFunc ¶
DecoderFunc adapts an decoder function into Decoder.
func (DecoderFunc) Decode ¶
func (f DecoderFunc) Decode(v any) error
Decode delegates invocations to the underlying function itself.
type EncoderFunc ¶
EncoderFunc adapts an encoder function into Encoder.
func (EncoderFunc) Encode ¶
func (f EncoderFunc) Encode(v any) error
Encode delegates invocations to the underlying function itself.
type Map ¶
Map is an alias for an codec map. Common keys to use here are either the plugin name or mime types.
type Marshaler ¶
type Marshaler interface {
// Encode encodes "v" into byte sequence.
Encode(v any) ([]byte, error)
// Decode decodes "data" into "v".
// "v" must be a pointer value.
Decode(data []byte, v any) error
// NewDecoder returns a Decoder which reads byte sequence from "r".
NewDecoder(r io.Reader) Decoder
// NewEncoder returns an Encoder which writes bytes sequence into "w".
NewEncoder(w io.Writer) Encoder
// Encodes returns if this codec is able to encode the given type.
Encodes(v any) bool
// Decodes returns if this codec is able to decode the given type.
Decodes(v any) bool
// ContentTypes returns the list of content types this codec is able to
// output.
ContentTypes() []string
// String returns the codec name.
String() string
// Exts returns the common file extensions for this encoder.
Exts() []string
}
Marshaler is able to encode/decode a content type to/from a byte sequence.
func GetDecoder ¶ added in v0.1.0
GetDecoder returns a decoder codec for a mime and golang type.
func GetEncoder ¶ added in v0.1.0
GetEncoder returns a encoder codec for a mime and golang type.