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 ¶
View Source
var ( // ErrNoFileMarshaler happens when we haven't found a marshaler for the given file. ErrNoFileMarshaler = errors.New("no marshaler for the given file found") )
View Source
var Plugins = container.NewMap[Marshaler]() //nolint:gochecknoglobals
Plugins is the registry for codec plugins.
Functions ¶
This section is empty.
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 { // Marshal marshals "v" into byte sequence. Marshal(v any) ([]byte, error) // Unmarshal unmarshals "data" into "v". // "v" must be a pointer value. Unmarshal(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 // ContentTypes returns the list of content types this marshaller is able to // handle. 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.
Click to show internal directories.
Click to hide internal directories.