Documentation
¶
Overview ¶
Package encoding provides types and functions to encode and decode documents and values.
Encoding values ¶
Each type is encoded in a way that allows ordering to be preserved. That way, if vA < vB, where vA and vB are two unencoded values of the same type, then eA < eB, where eA and eB are the respective encoded values of vA and vB.
Index ¶
- func DecodeArray(buf []byte) document.Array
- func DecodeBlob(buf []byte) ([]byte, error)
- func DecodeBool(buf []byte) (bool, error)
- func DecodeDocument(buf []byte) document.Document
- func DecodeFloat64(buf []byte) (float64, error)
- func DecodeInt(buf []byte) (int, error)
- func DecodeInt16(buf []byte) (int16, error)
- func DecodeInt32(buf []byte) (int32, error)
- func DecodeInt64(buf []byte) (int64, error)
- func DecodeInt8(buf []byte) (int8, error)
- func DecodeText(buf []byte) (string, error)
- func DecodeUint(buf []byte) (uint, error)
- func DecodeUint16(buf []byte) (uint16, error)
- func DecodeUint32(buf []byte) (uint32, error)
- func DecodeUint64(buf []byte) (uint64, error)
- func DecodeUint8(buf []byte) (uint8, error)
- func DecodeValue(t document.ValueType, data []byte) (document.Value, error)
- func EncodeArray(a document.Array) ([]byte, error)
- func EncodeBlob(x []byte) []byte
- func EncodeBool(x bool) []byte
- func EncodeDocument(d document.Document) ([]byte, error)
- func EncodeFloat64(x float64) []byte
- func EncodeInt(x int) []byte
- func EncodeInt16(x int16) []byte
- func EncodeInt32(x int32) []byte
- func EncodeInt64(x int64) []byte
- func EncodeInt8(x int8) []byte
- func EncodeText(x string) []byte
- func EncodeUint(x uint) []byte
- func EncodeUint16(x uint16) []byte
- func EncodeUint32(x uint32) []byte
- func EncodeUint64(x uint64) []byte
- func EncodeUint8(x uint8) []byte
- func EncodeValue(v document.Value) ([]byte, error)
- type EncodedArray
- type EncodedDocument
- type FieldHeader
- type Format
- type Header
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeArray ¶
DecodeArray takes a byte slice and returns a lazily decoded array. If buf is malformed, an error will be returned when calling one of the array method.
func DecodeBlob ¶
DecodeBlob takes a byte slice and returns it. It is present to ease code generation.
func DecodeBool ¶
DecodeBool takes a byte slice and decodes it into a boolean.
func DecodeDocument ¶
DecodeDocument takes a byte slice and returns a lazily decoded document. If buf is malformed, an error will be returned when calling one of the document method.
func DecodeFloat64 ¶
DecodeFloat64 takes a byte slice and decodes it into an float64.
func DecodeInt16 ¶
DecodeInt16 takes a byte slice and decodes it into an int16.
func DecodeInt32 ¶
DecodeInt32 takes a byte slice and decodes it into an int32.
func DecodeInt64 ¶
DecodeInt64 takes a byte slice and decodes it into an int64.
func DecodeInt8 ¶
DecodeInt8 takes a byte slice and decodes it into an int8.
func DecodeText ¶
DecodeText takes a byte slice and decodes it into a string.
func DecodeUint ¶
DecodeUint takes a byte slice and decodes it into a uint.
func DecodeUint16 ¶
DecodeUint16 takes a byte slice and decodes it into a uint16.
func DecodeUint32 ¶
DecodeUint32 takes a byte slice and decodes it into a uint32.
func DecodeUint64 ¶
DecodeUint64 takes a byte slice and decodes it into a uint64.
func DecodeUint8 ¶
DecodeUint8 takes a byte slice and decodes it into a uint8.
func DecodeValue ¶
DecodeValue takes some encoded data and decodes it to the target type t.
func EncodeArray ¶
EncodeArray encodes a into its binary representation.
func EncodeBlob ¶
EncodeBlob takes a blob and returns it. It is present to ease code generation.
func EncodeBool ¶
EncodeBool takes a bool and returns its binary representation.
func EncodeDocument ¶
EncodeDocument takes a document and encodes it using the encoding.Format type.
func EncodeFloat64 ¶
EncodeFloat64 takes an float64 and returns its binary representation.
func EncodeInt16 ¶
EncodeInt16 takes an int16 and returns its binary representation.
func EncodeInt32 ¶
EncodeInt32 takes an int32 and returns its binary representation.
func EncodeInt64 ¶
EncodeInt64 takes an int64 and returns its binary representation.
func EncodeInt8 ¶
EncodeInt8 takes an int8 and returns its binary representation.
func EncodeText ¶
EncodeText takes a string and returns its binary representation.
func EncodeUint ¶
EncodeUint takes an uint and returns its binary representation.
func EncodeUint16 ¶
EncodeUint16 takes an uint16 and returns its binary representation.
func EncodeUint32 ¶
EncodeUint32 takes an uint32 and returns its binary representation.
func EncodeUint64 ¶
EncodeUint64 takes an uint64 and returns its binary representation.
func EncodeUint8 ¶
EncodeUint8 takes an uint8 and returns its binary representation.
Types ¶
type EncodedArray ¶
type EncodedArray []byte
An EncodedArray implements the document.Array interface on top of an encoded representation of an array. It is useful to avoid decoding the entire array when only a few values are needed.
func (EncodedArray) GetByIndex ¶
func (e EncodedArray) GetByIndex(i int) (document.Value, error)
GetByIndex returns a value by index of the array.
func (EncodedArray) Iterate ¶
Iterate goes through all the values of the array and calls the given function by passing each one of them. If the given function returns an error, the iteration stops.
func (EncodedArray) MarshalJSON ¶
func (e EncodedArray) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
type EncodedDocument ¶
type EncodedDocument []byte
An EncodedDocument implements the document.Document interface on top of an encoded representation of a document. It is useful to avoid decoding the entire document when only a few fields are needed.
func (EncodedDocument) GetByField ¶
func (e EncodedDocument) GetByField(field string) (document.Value, error)
GetByField decodes the selected field.
func (EncodedDocument) Iterate ¶
Iterate decodes each fields one by one and passes them to fn until the end of the document or until fn returns an error.
func (EncodedDocument) MarshalJSON ¶
func (e EncodedDocument) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
type FieldHeader ¶
type FieldHeader struct { // Size of the name of the field NameSize uint64 // Name of the field Name []byte // Type of the field, corresponds to the Type Type uint64 // Size of the data of the field Size uint64 // Offset describing where the field is located, starting // from the end of the format header. Offset uint64 NameString string // used for encoding // contains filtered or unexported fields }
FieldHeader represents the metadata of a field.
type Format ¶
Format is an encoding format used to encode and decode documents. It is composed of a header and a body. The header defines a list of fields, offsets and relevant metadata. The body contains each fields data one concatenated one after another.