Documentation ¶
Overview ¶
Package codec implements functions for encoding and decoding objects in several formats
Any registered codec can be used by both gondola/cache and gondola/orm.
This package provides the "gob" and "json" codecs, which encode the data using encoding/gob and encoding/json, respectivelly. Check gondola/cache and gondola/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 ¶
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 ¶
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.