codec

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: MIT Imports: 1 Imported by: 1

README

codec

Build Status Report Card GoCover

Package contains a set of tools around data encoders/decoders

Installation
go get -u github.com/tiny-go/codec
Supported codecs
  • JSON (application/json)
  • XML (application/xml)
  • TEXT (text/plain)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec interface {
	// Ecoder instantiates the ecnoder part of the codec with provided writer.
	Encoder(w io.Writer) Encoder
	// Decoder instantiates the decoder part of the codec with provided reader.
	Decoder(r io.Reader) Decoder
	// MimeType returns the (main) mime type of the codec.
	MimeType() string
}

Codec can create Encoder(s) and Decoder(s) with provided io.Reader/io.Writer.

type Decoder

type Decoder interface{ Decode(v interface{}) error }

Decoder is responsible for data decoding.

type DecoderFunc

type DecoderFunc func(interface{}) error

DecoderFunc is a wrapper that allows using regular function as Decoder interface.

func (DecoderFunc) Decode

func (fn DecoderFunc) Decode(recv interface{}) error

Decode decodes data from the reader to provided receiver.

type Encoder

type Encoder interface{ Encode(v interface{}) error }

Encoder is responsible for data encoding.

type EncoderFunc

type EncoderFunc func(interface{}) error

EncoderFunc is a wrapper that allows using regular function as Encoder interface.

func (EncoderFunc) Encode

func (fn EncoderFunc) Encode(src interface{}) error

Encode encodes provided interface to the writer.

type Registry

type Registry interface {
	// Lookup should find appropriate Codec by MimeType or return nil if not found.
	Lookup(mimeType string) Codec
}

Registry represents any kind of codec registry, thus it can be global registry or a custom list of codecs that is supposed to be used for a particular case.

Directories

Path Synopsis
xml

Jump to

Keyboard shortcuts

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