msgp

package
v0.0.0-...-91c5940 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2017 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	M_NIL                  byte = 0xc0
	M_FALSE                byte = 0xc2
	M_TRUE                 byte = 0xc3
	M_UINT8                byte = 0xcc
	M_UINT16               byte = 0xcd
	M_UINT32               byte = 0xce
	M_UINT64               byte = 0xcf
	M_INT8                 byte = 0xd0
	M_INT16                byte = 0xd1
	M_INT32                byte = 0xd2
	M_INT64                byte = 0xd3
	M_FLOAT32              byte = 0xca
	M_FLOAT64              byte = 0xcb
	M_FIXSTR_BASE          byte = 0xa0 // 3 MSB bits are significant
	M_STR8                 byte = 0xd9
	M_STR16                byte = 0xda
	M_STR32                byte = 0xdb
	M_BIN8                 byte = 0xc4
	M_BIN16                byte = 0xc5
	M_BIN32                byte = 0xc6
	M_FIXARRAY_BASE        byte = 0x90 // 4 MSB bits are significant
	M_ARRAY16              byte = 0xdc
	M_ARRAY32              byte = 0xdd
	M_FIXMAP_BASE          byte = 0x80 // 4 MSB bits are significant
	M_MAP16                byte = 0xde
	M_MAP32                byte = 0xdf
	M_NEGATIVE_FIXINT_BASE byte = 0xe0 // 11100000 to 11111111 are negative fixint numbers

	PREFIX_FIXSTR_MASK   byte = 0xe0 // 11100000
	PREFIX_FIXARRAY_MASK byte = 0xf0 // 11110000
	PREFIX_FIXMAP_MASK   byte = 0xf0 // 11110000
)
View Source
const (
	READER_SCRATCH_BUFFER_DEFAULT_CAPACITY = 1024 // ReadString() may need a large buffer, if string being read is large
)
View Source
const (
	WRITER_STAGING_BUFFER_DEFAULT_CAPACITY = 1024 // quite large because large string can be written
)

Variables

This section is empty.

Functions

func AppendArrayHeader

func AppendArrayHeader(dest []byte, sz uint32) []byte

func AppendBool

func AppendBool(dest []byte, val bool) []byte

func AppendBytes

func AppendBytes(dest []byte, bts []byte) []byte

func AppendBytesHeader

func AppendBytesHeader(dest []byte, sz uint32) []byte

func AppendFloat32

func AppendFloat32(dest []byte, f float32) []byte

func AppendFloat64

func AppendFloat64(dest []byte, f float64) []byte

func AppendInt16

func AppendInt16(dest []byte, val int16) []byte

func AppendInt32

func AppendInt32(dest []byte, val int32) []byte

func AppendInt64

func AppendInt64(dest []byte, val int64) []byte

func AppendInt8

func AppendInt8(dest []byte, val int8) []byte

func AppendMapHeader

func AppendMapHeader(dest []byte, sz uint32) []byte

func AppendMapStrSimpleType

func AppendMapStrSimpleType(dest []byte, m map[string]interface{}) []byte

func AppendMapStrStr

func AppendMapStrStr(dest []byte, m map[string]string) []byte

func AppendMapStrStrFromList

func AppendMapStrStrFromList(dest []byte, args ...string) []byte

func AppendNil

func AppendNil(dest []byte) []byte

func AppendSimpleType

func AppendSimpleType(dest []byte, i interface{}) []byte

func AppendString

func AppendString(dest []byte, s string) []byte

func AppendStringFromBytes

func AppendStringFromBytes(dest []byte, s []byte) []byte

func AppendStringHeader

func AppendStringHeader(dest []byte, sz uint32) []byte

func AppendUint16

func AppendUint16(dest []byte, val uint16) []byte

func AppendUint32

func AppendUint32(dest []byte, val uint32) []byte

func AppendUint64

func AppendUint64(dest []byte, val uint64) []byte

func AppendUint8

func AppendUint8(dest []byte, val uint8) []byte

Types

type Reader

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

Reader reads msgpack data from a buffered reader.

All Read... methods returns an error.

errors can be:
     - connection is broken
     - a unexpected datatype is being read. This means the communication protocol is messed up
     - integer overflow. This also means the communication protocol is messed up

In case of error, the cause is really serious and cannot be recovered.
The best thing to do is to terminate the connection and the session, and making all necessary cleaning up of resources.

func NewReader

func NewReader(rd io.Reader) *Reader

NewReader returns a messagepack Reader. A bufio.Reader will be created internally if argument is not a *bufio.Reader.

func (*Reader) NextType

func (m *Reader) NextType() (Type, error)

func (*Reader) ReadArrayHeader

func (m *Reader) ReadArrayHeader() (sz uint32, err error)

func (*Reader) ReadBool

func (m *Reader) ReadBool() (val bool, err error)

func (*Reader) ReadBytes

func (m *Reader) ReadBytes(dest []byte) (res []byte, err error)

func (*Reader) ReadBytesHeader

func (m *Reader) ReadBytesHeader() (sz uint32, err error)

func (*Reader) ReadFloat32

func (m *Reader) ReadFloat32() (val float32, err error)

func (*Reader) ReadFloat64

func (m *Reader) ReadFloat64() (val float64, err error)

func (*Reader) ReadFull

func (m *Reader) ReadFull(dest []byte) (n int, err error)

ReadFull is a method that just calls io.ReadFull.

func (*Reader) ReadInt16

func (m *Reader) ReadInt16() (val int16, err error)

func (*Reader) ReadInt32

func (m *Reader) ReadInt32() (val int32, err error)

func (*Reader) ReadInt64

func (m *Reader) ReadInt64() (val int64, err error)

func (*Reader) ReadInt8

func (m *Reader) ReadInt8() (val int8, err error)

func (*Reader) ReadMapHeader

func (m *Reader) ReadMapHeader() (sz uint32, err error)

func (*Reader) ReadNBytes

func (m *Reader) ReadNBytes(dest []byte, n int) (res []byte, err error)

ReadNBytes reads exactly n bytes from internal reader. dest buffer is overwritten, and is returned to the caller. If dest capacity < n, a new larger buffer is returned.

If success, the returned buffer is always of length n.

func (*Reader) ReadNil

func (m *Reader) ReadNil() (err error)

func (*Reader) ReadSimpleType

func (m *Reader) ReadSimpleType() (interface{}, error)

func (*Reader) ReadString

func (m *Reader) ReadString() (val string, err error)

func (*Reader) ReadStringAsBytes

func (m *Reader) ReadStringAsBytes(dest []byte) (res []byte, err error)

func (*Reader) ReadStringHeader

func (m *Reader) ReadStringHeader() (sz uint32, err error)

func (*Reader) ReadUint16

func (m *Reader) ReadUint16() (val uint16, err error)

func (*Reader) ReadUint32

func (m *Reader) ReadUint32() (val uint32, err error)

func (*Reader) ReadUint64

func (m *Reader) ReadUint64() (val uint64, err error)

func (*Reader) ReadUint8

func (m *Reader) ReadUint8() (val uint8, err error)

type Type

type Type byte
const (
	InvalidType Type = iota

	BinType
	StrType

	NilType
	BoolType
	UintType
	IntType
	Float32Type
	Float64Type

	ArrayType
	MapType
)

type Writer

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

Writer writes msgpack data to a buffered writer.

Use the WriteNil(), WriteBool(), etc functions to write the data into the underlying bufio.Writer. These functions don't write anything if the Writer is in error state (mw.doomed != nil).

Then, when all you have written all your data, you MUST call Flush() to flush the underlying bufio.Writer, and check its return value for error.

Note: the doomed field is an error, that occurs because Write has failed. Most probably because connection is broken.
      When such failure occurs, it is unrecoverable and the connection should be just closed. The Writer cannot be used any more.

func NewWriter

func NewWriter(wt io.Writer) *Writer

NewWriter returns a messagepack Writer. A bufio.Writer will be created internally if argument is not a *bufio.Writer.

func (*Writer) Error

func (mw *Writer) Error() (doomed error)

Error returns the error state of the Writer.

func (*Writer) Flush

func (mw *Writer) Flush() (doomed error)

Flush flushes the underlying bufio.Buffer.

IF AN ERROR IS RETURNED, IT MEANS THE WRITE HAS FAILED BECAUSE CONNECTION HAS FAILED.
This error could have occurred in any previous operation.

func (*Writer) SetStaging

func (mw *Writer) SetStaging(staging_buff []byte)

func (*Writer) TruncatedStaging

func (mw *Writer) TruncatedStaging() []byte

func (*Writer) WriteArrayHeader

func (mw *Writer) WriteArrayHeader(sz uint32)

func (*Writer) WriteBool

func (mw *Writer) WriteBool(val bool)

func (*Writer) WriteBytes

func (mw *Writer) WriteBytes(val []byte)

func (*Writer) WriteBytesHeader

func (mw *Writer) WriteBytesHeader(sz uint32)

func (*Writer) WriteFloat32

func (mw *Writer) WriteFloat32(val float32)

func (*Writer) WriteFloat64

func (mw *Writer) WriteFloat64(val float64)

func (*Writer) WriteInt16

func (mw *Writer) WriteInt16(val int16)

func (*Writer) WriteInt32

func (mw *Writer) WriteInt32(val int32)

func (*Writer) WriteInt64

func (mw *Writer) WriteInt64(val int64)

func (*Writer) WriteInt8

func (mw *Writer) WriteInt8(val int8)

func (*Writer) WriteMapHeader

func (mw *Writer) WriteMapHeader(sz uint32)

func (*Writer) WriteMapStrSimpleType

func (mw *Writer) WriteMapStrSimpleType(arg map[string]interface{})

func (*Writer) WriteMapStrStr

func (mw *Writer) WriteMapStrStr(arg map[string]string)

func (*Writer) WriteMapStrStrFromList

func (mw *Writer) WriteMapStrStrFromList(args ...string)

func (*Writer) WriteNil

func (mw *Writer) WriteNil()

func (*Writer) WriteSimpleType

func (mw *Writer) WriteSimpleType(i interface{})

func (*Writer) WriteStaging

func (mw *Writer) WriteStaging()

func (*Writer) WriteString

func (mw *Writer) WriteString(val string)

func (*Writer) WriteStringFromBytes

func (mw *Writer) WriteStringFromBytes(val []byte)

func (*Writer) WriteStringHeader

func (mw *Writer) WriteStringHeader(sz uint32)

func (*Writer) WriteUint16

func (mw *Writer) WriteUint16(val uint16)

func (*Writer) WriteUint32

func (mw *Writer) WriteUint32(val uint32)

func (*Writer) WriteUint64

func (mw *Writer) WriteUint64(val uint64)

func (*Writer) WriteUint8

func (mw *Writer) WriteUint8(val uint8)

Jump to

Keyboard shortcuts

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