encoding

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrDecoderNotFound is returned when there is no decoder registered for a format.
	ErrDecoderNotFound = encodingError("decoder not found for this format")

	// ErrDecoderFormatAlreadyRegistered is returned when an decoder is already registered for a format.
	ErrDecoderFormatAlreadyRegistered = encodingError("decoder already registered for this format")
)
View Source
const (
	// ErrEncoderNotFound is returned when there is no encoder registered for a format.
	ErrEncoderNotFound = encodingError("encoder not found for this format")

	// ErrEncoderFormatAlreadyRegistered is returned when an encoder is already registered for a format.
	ErrEncoderFormatAlreadyRegistered = encodingError("encoder already registered for this format")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder interface {
	Decode(b []byte, v map[string]interface{}) error
}

Decoder decodes the contents of b into v. It's primarily used for decoding contents of a file into a map[string]interface{}.

type DecoderRegistry

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

DecoderRegistry can choose an appropriate Decoder based on the provided format.

func NewDecoderRegistry

func NewDecoderRegistry() *DecoderRegistry

NewDecoderRegistry returns a new, initialized DecoderRegistry.

func (*DecoderRegistry) Decode

func (e *DecoderRegistry) Decode(format string, b []byte, v map[string]interface{}) error

Decode calls the underlying Decoder based on the format.

func (*DecoderRegistry) RegisterDecoder

func (e *DecoderRegistry) RegisterDecoder(format string, enc Decoder) error

RegisterDecoder registers a Decoder for a format. Registering a Decoder for an already existing format is not supported.

type Encoder

type Encoder interface {
	Encode(v map[string]interface{}) ([]byte, error)
}

Encoder encodes the contents of v into a byte representation. It's primarily used for encoding a map[string]interface{} into a file format.

type EncoderRegistry

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

EncoderRegistry can choose an appropriate Encoder based on the provided format.

func NewEncoderRegistry

func NewEncoderRegistry() *EncoderRegistry

NewEncoderRegistry returns a new, initialized EncoderRegistry.

func (*EncoderRegistry) Encode

func (e *EncoderRegistry) Encode(format string, v map[string]interface{}) ([]byte, error)

func (*EncoderRegistry) RegisterEncoder

func (e *EncoderRegistry) RegisterEncoder(format string, enc Encoder) error

RegisterEncoder registers an Encoder for a format. Registering a Encoder for an already existing format is not supported.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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