codec

package
v0.0.0-...-b75375f Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2014 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package codec implements functions for encoding and decoding objects in several formats

Any registered codec can be used by both gnd.la/cache and gnd.la/orm.

This package provides the "gob" and "json" codecs, which encode the data using encoding/gob and encoding/json, respectivelly. Check gnd.la/cache and gnd.la/orm to learn how to use codecs with Gondola's cache and ORM.

Users might define their own codecs by implementing a Codec struct and registering it with Register().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, c *Codec)

Register registers a codec to be made available for use by the cache. If there was already a codec with the same name, it's overwritten by the new one. Keep in mind that this function is not thread safe, so it should only be called from the main goroutine.

func RequiredImport

func RequiredImport(name string) string

RequiredImport returns the import required for using the codec with the given name, or the empty string if the codec is not known.

Types

type Codec

type Codec struct {
	// Encode takes an object and returns its []byte representation.
	Encode func(v interface{}) ([]byte, error)
	// Decode takes a []byte representation and decodes it into
	// the passed in object.
	Decode func(data []byte, v interface{}) error
	// Binary indicates if the codec returns binary or text data
	Binary bool
}

Codec is a stateless struct which implements encoding and decoding objects into/from []byte. An struct rather than an interface is used to enforce them to be stateless and also for performance reasons.

func FromTag

func FromTag(t *structs.Tag) *Codec

FromTag returns the pipe for a given field tag.

func Get

func Get(name string) *Codec

Get returns the codec assocciated with the given name, or nil if there's no such codec.

Directories

Path Synopsis
Package msgpack provides a codec implementation using msgpack.
Package msgpack provides a codec implementation using msgpack.

Jump to

Keyboard shortcuts

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