encoding

package
v0.0.0-...-61b3f89 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCodec

func RegisterCodec(codec Codec)

RegisterCodec registers the provided Codec for use with all exposed clients and servers.

The Codec will be stored and looked up by result of its Name() method, which should match the content-subtype of the encoding handled by the Codec. This is case-insensitive, and is stored and looked up as lowercase. NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. If multiple Compressors are registered with the same name, the one registered last will take effect.

func RegisterCompressor

func RegisterCompressor(c Compressor)

RegisterCompressor registers the compressor with exposed by its name. It can NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. If multiple Compressors are registered with the same name, the one registered last will take effect.

Types

type Codec

type Codec interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
	Name() string
}

Codec defines the interface exposed uses to encode and decode messages. Note that implementations of this interface must be thread safe; a Codec's methods can be called from concurrent goroutines.

func GetCodec

func GetCodec(name string) Codec

GetCodec gets a registered Codec by codec name

type Compressor

type Compressor interface {
	// Compress writes the data written to wc to w after compressing it.  If an
	// error occurs while initializing the compressor, that error is returned
	// instead.
	Compress(w io.Writer) (io.WriteCloser, error)
	// Decompress reads data from r, decompresses it, and provides the
	// uncompressed data via the returned io.Reader.  If an error occurs while
	// initializing the decompressor, that error is returned instead.
	Decompress(r io.Reader) (io.Reader, error)
	// Name is the name of the compression codec and is used to set the content
	// coding header.  The result must be static; the result cannot change
	// between calls.
	Name() string
}

Compressor is used for compressing and decompressing when sending or receiving messages.

func GetCompressor

func GetCompressor(name string) Compressor

GetCompressor returns Compressor for the given compressor name.

Directories

Path Synopsis
codec

Jump to

Keyboard shortcuts

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