codecs

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownCodec = errors.New("unknown codec")

ErrUnknownCodec is returned when no codec is found for the given name.

Functions

This section is empty.

Types

type Codec

type Codec[Q, R any] interface {
	Encode(Q) ([]byte, error)
	Decode([]byte, *R) error
	Name() string
}

Codec defines the interface for a two way conversion between Q and R.

func ForName added in v0.3.0

func ForName[Q, R any](name string) (Codec[Q, R], error)

ForName returns the codec for the given name or ErrUnknownCodec if no codec is found.

type GobCodec

type GobCodec[Q, R any] struct{}

GobCodec is a Codec that uses gob as the underlying format.

func (GobCodec[Q, R]) Decode

func (c GobCodec[Q, R]) Decode(b []byte, r *R) error

func (GobCodec[Q, R]) Encode

func (c GobCodec[Q, R]) Encode(q Q) ([]byte, error)

func (GobCodec[Q, R]) Name added in v0.3.0

func (c GobCodec[Q, R]) Name() string

type JSONCodec

type JSONCodec[Q, R any] struct{}

JSONCodec is a Codec that uses JSON as the underlying format.

func (JSONCodec[Q, R]) Decode

func (c JSONCodec[Q, R]) Decode(b []byte, r *R) error

func (JSONCodec[Q, R]) Encode

func (c JSONCodec[Q, R]) Encode(q Q) ([]byte, error)

func (JSONCodec[Q, R]) Name added in v0.3.0

func (c JSONCodec[Q, R]) Name() string

type TOMLCodec

type TOMLCodec[Q, R any] struct{}

TOMLCodec is a Codec that uses TOML as the underlying format.

func (TOMLCodec[Q, R]) Decode

func (c TOMLCodec[Q, R]) Decode(b []byte, r *R) error

func (TOMLCodec[Q, R]) Encode

func (c TOMLCodec[Q, R]) Encode(q Q) ([]byte, error)

func (TOMLCodec[Q, R]) Name added in v0.3.0

func (c TOMLCodec[Q, R]) Name() string

Jump to

Keyboard shortcuts

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