codec

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: BSD-3-Clause Imports: 6 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 IndentStyle added in v0.18.0

type IndentStyle int

IndentStyle identifies the whitespace character used for indentation.

const (
	// IndentSpace indents using space characters. This is the default.
	IndentSpace IndentStyle = iota

	// IndentTab indents using tab characters.
	IndentTab
)

The available indent styles

func (IndentStyle) MarshalText added in v0.18.0

func (s IndentStyle) MarshalText() ([]byte, error)

MarshalText provides the textual representation

func (IndentStyle) String added in v0.18.0

func (s IndentStyle) String() string

String returns the name of the indent style.

func (*IndentStyle) UnmarshalText added in v0.18.0

func (s *IndentStyle) UnmarshalText(b []byte) error

UnmarshalText converts the textual representation. In addition to the canonical values "space" and "tab", the common misspellings "spaces" and "tabs" are also accepted.

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

NewJSONCodec creates a codec support JSON

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.

func EscapeHTML added in v0.18.0

func EscapeHTML() Option

EscapeHTML affects marshaling and generates escaped HTML within JSON. For other codecs, this option generates an error.

func WithIndent added in v0.18.0

func WithIndent(indent string) Option

WithIndent affects marshaling and sets the string used for each level of indentation in the encoded output.

func WithIndentStyleSize added in v0.18.0

func WithIndentStyleSize(style IndentStyle, size int) Option

WithIndentStyleSize sets the indent based on style and style

type Options added in v0.15.0

type Options struct {
	DisallowUnknownFields bool        `mapstructure:"disallow_unknown_fields"`
	IndentSize            int         `mapstructure:"indent_size"`
	IndentStyle           IndentStyle `mapstructure:"indent_style"`
	EscapeHTML            bool        `mapstructure:"escape_html"`
}

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
Package toml provides the TOML codec
Package toml provides the TOML codec

Jump to

Keyboard shortcuts

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