codec

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package codec provides a model and conventions for marshaling and unmarshaling values to and from their encodings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec struct {
	Interface
}

Codec provides a wrapper around the basic interface to facilitate common codec operations

func (Codec) Marshal

func (c Codec) Marshal(v any) ([]byte, error)

Marshal returns the encoding of v.

func (Codec) Unmarshal

func (c Codec) Unmarshal(data []byte, v any) error

Unmarshal parses the encoded data and stores the result in the value pointed to by v.

type Interface added in v0.11.0

type Interface interface {
	MarshalWrite(w io.Writer, in any) error
	UnmarshalRead(r io.Reader, out any) error
}

Interface defines the interface for reading and writing from data

func NewJSONCodec

func NewJSONCodec() Interface

func WithOptions added in v0.14.1

func WithOptions(i Interface, opts ...Option) (Interface, error)

WithOptions applies options to the given codec

type Option added in v0.14.1

type Option interface {
	// contains filtered or unexported methods
}

Option implements options for codecs

func DisallowUnknownFields added in v0.14.1

func DisallowUnknownFields() Option

DisallowUnknownFields affects unmarshaling and prevents unknown fields from being specified.

type Options added in v0.15.0

type Options struct {
	DisallowUnknownFields bool `mapstructure:"disallow_unknown_fields"`
}

Options represents all currently available codec options as data. It implements Option and can be decomposed into a list of individual options.

func (Options) List added in v0.15.0

func (o Options) List() []Option

List returns the individual Option values corresponding to the fields set on o.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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