msgpack

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec struct{}

A Codec is a MessagePack implementation of an encoding.Codec.

func NewCodec

func NewCodec() Codec

NewCodec creates a MessagePack codec.

func (Codec) NewDocument

func (c Codec) NewDocument(data []byte) document.Document

NewDocument implements the encoding.Codec interface.

func (Codec) NewEncoder

func (c Codec) NewEncoder(w io.Writer) encoding.Encoder

NewEncoder implements the encoding.Codec interface.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decodes Genji documents and values from MessagePack.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates a Decoder that reads from the given reader.

func (*Decoder) Close

func (d *Decoder) Close()

Close puts the decoder into the pool for reuse.

func (*Decoder) DecodeArray

func (d *Decoder) DecodeArray() (document.Array, error)

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

func (d *Decoder) DecodeDocument() (document.Document, error)

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.

func (*Decoder) DecodeValue

func (d *Decoder) DecodeValue() (v document.Value, err error)

DecodeValue reads one value from the reader and decodes it.

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

func (e EncodedArray) Iterate(fn func(i int, value document.Value) error) error

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.

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

func (e EncodedDocument) Iterate(fn func(field string, value document.Value) error) error

Iterate decodes each fields one by one and passes them to fn until the end of the document or until fn returns an error.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder encodes Genji documents and values in MessagePack.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder creates an Encoder that writes in the given writer.

func (*Encoder) Close

func (e *Encoder) Close()

Close puts the encoder into the pool for reuse.

func (*Encoder) EncodeArray

func (e *Encoder) EncodeArray(a document.Array) error

EncodeArray encodes a as a MessagePack array.

func (*Encoder) EncodeDocument

func (e *Encoder) EncodeDocument(d document.Document) error

EncodeDocument encodes d as a MessagePack map.

func (*Encoder) EncodeValue

func (e *Encoder) EncodeValue(v document.Value) error

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

Jump to

Keyboard shortcuts

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