Documentation
¶
Index ¶
- Constants
- func DecodeArray(buf []byte) document.Array
- func DecodeDocument(buf []byte) document.Document
- func DecodeValue(data []byte) (document.Value, error)
- func EncodeArray(a document.Array) ([]byte, error)
- func EncodeDocument(d document.Document) ([]byte, error)
- func EncodeValue(w io.Writer, v document.Value) error
- type Decoder
- type EncodedArray
- type EncodedDocument
- type Encoder
Constants ¶
const (
DurationType int8 = 0x1
)
List of custom types
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 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 DecodeValue ¶
DecodeValue takes some encoded data and decodes it into its concrete value.
func EncodeArray ¶
EncodeArray encodes a document.Array into its binary representation.
func EncodeDocument ¶
EncodeDocument takes a document and encodes it in MessagePack.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes Genji documents and values from MessagePack.
func NewDecoder ¶
NewDecoder creates a Decoder that reads from the given reader.
func (*Decoder) DecodeArray ¶
DecodeArray decodes one array from the reader. If the array is malformed, this function will not return an error. However, calls to Iterate or GetByIndex will fail.
func (*Decoder) DecodeDocument ¶
DecodeDocument decodes one document from the reader. If the document is malformed, it will not return an error. However, calls to Iterate or GetByField will fail.
type EncodedArray ¶
type EncodedArray []byte
An EncodedArray implements the document.Array interface on top of an encoded representation of an array. It is useful for avoiding decoding the entire array when only a few values are needed.
func (EncodedArray) GetByIndex ¶
func (e EncodedArray) GetByIndex(idx int) (v document.Value, err 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 for avoiding decoding the entire document when only a few fields are needed.
func (EncodedDocument) GetByField ¶
func (e EncodedDocument) GetByField(field string) (v document.Value, err error)
GetByField decodes the selected field from the buffer.
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 Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes Genji documents and values in MessagePack.
func NewEncoder ¶
NewEncoder creates an Encoder that writes in the given writer.
func (*Encoder) EncodeArray ¶
EncodeArray encodes a as a MessagePack array.
func (*Encoder) EncodeDocument ¶
EncodeDocument encodes d as a MessagePack map.
func (*Encoder) EncodeValue ¶
EncodeValue encodes v based on its type. - document -> map - array -> array - NULL -> nil - text -> string - blob -> bytes - bool -> bool - int8 -> int8 - int16 -> int16 - int32 -> int32 - int64 -> int64 - float64 -> float64 - duration -> custom type with code 0x1 and size 8