encoders

package
v9.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CSV = &csvEncoder{}

CSV holds a csv encoder instance implementing Marshaller.

View Source
var JSON = &jsonEncoder{}

JSON holds a json encoder instance implementing Marshaller.

View Source
var ProtoText = &protoTextEncoder{}

ProtoText holds a proto text encoder instance implementing Marshaller.

View Source
var RAW = &rawEncoder{}

RAW holds a raw encoder instance implementing Marshaller.

Functions

func Unmarshal

func Unmarshal[T any](ctx context.Context, m Marshaller, body []byte) (T, error)

Unmarshal allows unmarshalling body into a value of T using the given Marshaller.

Types

type Marshaller

type Marshaller interface {
	// Marshal marshals the given data structure to a certain format and returns the representation in bytes.
	Marshal(v interface{}) ([]byte, error)

	// Unmarshal parses a byte representation of a given data in a certain format and loads v with matching parsed values.
	Unmarshal(data []byte, v interface{}) error
}

Marshaller marshals and unmarshals data to/from specific formats.

type WriterEncoder

type WriterEncoder interface {
	// Write encodes v in a certain format and writes it to w.
	Write(w io.Writer, v interface{}) error
}

WriterEncoder encodes and writes data to a Writer.

Jump to

Keyboard shortcuts

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