Documentation
¶
Index ¶
- Constants
- func AppendArrayHeader(dest []byte, sz uint32) []byte
- func AppendBool(dest []byte, val bool) []byte
- func AppendBytes(dest []byte, bts []byte) []byte
- func AppendBytesHeader(dest []byte, sz uint32) []byte
- func AppendFloat32(dest []byte, f float32) []byte
- func AppendFloat64(dest []byte, f float64) []byte
- func AppendInt16(dest []byte, val int16) []byte
- func AppendInt32(dest []byte, val int32) []byte
- func AppendInt64(dest []byte, val int64) []byte
- func AppendInt8(dest []byte, val int8) []byte
- func AppendMapHeader(dest []byte, sz uint32) []byte
- func AppendMapStrSimpleType(dest []byte, m map[string]interface{}) []byte
- func AppendMapStrStr(dest []byte, m map[string]string) []byte
- func AppendMapStrStrFromList(dest []byte, args ...string) []byte
- func AppendNil(dest []byte) []byte
- func AppendSimpleType(dest []byte, i interface{}) []byte
- func AppendString(dest []byte, s string) []byte
- func AppendStringFromBytes(dest []byte, s []byte) []byte
- func AppendStringHeader(dest []byte, sz uint32) []byte
- func AppendUint16(dest []byte, val uint16) []byte
- func AppendUint32(dest []byte, val uint32) []byte
- func AppendUint64(dest []byte, val uint64) []byte
- func AppendUint8(dest []byte, val uint8) []byte
- type Reader
- func (m *Reader) NextType() (Type, error)
- func (m *Reader) ReadArrayHeader() (sz uint32, err error)
- func (m *Reader) ReadBool() (val bool, err error)
- func (m *Reader) ReadBytes(dest []byte) (res []byte, err error)
- func (m *Reader) ReadBytesHeader() (sz uint32, err error)
- func (m *Reader) ReadFloat32() (val float32, err error)
- func (m *Reader) ReadFloat64() (val float64, err error)
- func (m *Reader) ReadFull(dest []byte) (n int, err error)
- func (m *Reader) ReadInt16() (val int16, err error)
- func (m *Reader) ReadInt32() (val int32, err error)
- func (m *Reader) ReadInt64() (val int64, err error)
- func (m *Reader) ReadInt8() (val int8, err error)
- func (m *Reader) ReadMapHeader() (sz uint32, err error)
- func (m *Reader) ReadNBytes(dest []byte, n int) (res []byte, err error)
- func (m *Reader) ReadNil() (err error)
- func (m *Reader) ReadSimpleType() (interface{}, error)
- func (m *Reader) ReadString() (val string, err error)
- func (m *Reader) ReadStringAsBytes(dest []byte) (res []byte, err error)
- func (m *Reader) ReadStringHeader() (sz uint32, err error)
- func (m *Reader) ReadUint16() (val uint16, err error)
- func (m *Reader) ReadUint32() (val uint32, err error)
- func (m *Reader) ReadUint64() (val uint64, err error)
- func (m *Reader) ReadUint8() (val uint8, err error)
- type Type
- type Writer
- func (mw *Writer) Error() (doomed error)
- func (mw *Writer) Flush() (doomed error)
- func (mw *Writer) SetStaging(staging_buff []byte)
- func (mw *Writer) TruncatedStaging() []byte
- func (mw *Writer) WriteArrayHeader(sz uint32)
- func (mw *Writer) WriteBool(val bool)
- func (mw *Writer) WriteBytes(val []byte)
- func (mw *Writer) WriteBytesHeader(sz uint32)
- func (mw *Writer) WriteFloat32(val float32)
- func (mw *Writer) WriteFloat64(val float64)
- func (mw *Writer) WriteInt16(val int16)
- func (mw *Writer) WriteInt32(val int32)
- func (mw *Writer) WriteInt64(val int64)
- func (mw *Writer) WriteInt8(val int8)
- func (mw *Writer) WriteMapHeader(sz uint32)
- func (mw *Writer) WriteMapStrSimpleType(arg map[string]interface{})
- func (mw *Writer) WriteMapStrStr(arg map[string]string)
- func (mw *Writer) WriteMapStrStrFromList(args ...string)
- func (mw *Writer) WriteNil()
- func (mw *Writer) WriteSimpleType(i interface{})
- func (mw *Writer) WriteStaging()
- func (mw *Writer) WriteString(val string)
- func (mw *Writer) WriteStringFromBytes(val []byte)
- func (mw *Writer) WriteStringHeader(sz uint32)
- func (mw *Writer) WriteUint16(val uint16)
- func (mw *Writer) WriteUint32(val uint32)
- func (mw *Writer) WriteUint64(val uint64)
- func (mw *Writer) WriteUint8(val uint8)
Constants ¶
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 )
const (
READER_SCRATCH_BUFFER_DEFAULT_CAPACITY = 1024 // ReadString() may need a large buffer, if string being read is large
)
const (
WRITER_STAGING_BUFFER_DEFAULT_CAPACITY = 1024 // quite large because large string can be written
)
Variables ¶
This section is empty.
Functions ¶
func AppendArrayHeader ¶
func AppendBool ¶
func AppendBytes ¶
func AppendBytesHeader ¶
func AppendFloat32 ¶
func AppendFloat64 ¶
func AppendInt16 ¶
func AppendInt32 ¶
func AppendInt64 ¶
func AppendInt8 ¶
func AppendMapHeader ¶
func AppendMapStrSimpleType ¶
func AppendMapStrStrFromList ¶
func AppendSimpleType ¶
func AppendString ¶
func AppendStringFromBytes ¶
func AppendStringHeader ¶
func AppendUint16 ¶
func AppendUint32 ¶
func AppendUint64 ¶
func AppendUint8 ¶
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 ¶
NewReader returns a messagepack Reader. A bufio.Reader will be created internally if argument is not a *bufio.Reader.
func (*Reader) ReadArrayHeader ¶
func (*Reader) ReadBytesHeader ¶
func (*Reader) ReadFloat32 ¶
func (*Reader) ReadFloat64 ¶
func (*Reader) ReadMapHeader ¶
func (*Reader) ReadNBytes ¶
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) ReadSimpleType ¶
func (*Reader) ReadString ¶
func (*Reader) ReadStringAsBytes ¶
func (*Reader) ReadStringHeader ¶
func (*Reader) ReadUint16 ¶
func (*Reader) ReadUint32 ¶
func (*Reader) ReadUint64 ¶
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 ¶
NewWriter returns a messagepack Writer. A bufio.Writer will be created internally if argument is not a *bufio.Writer.
func (*Writer) Flush ¶
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 (*Writer) TruncatedStaging ¶
func (*Writer) WriteArrayHeader ¶
func (*Writer) WriteBytes ¶
func (*Writer) WriteBytesHeader ¶
func (*Writer) WriteFloat32 ¶
func (*Writer) WriteFloat64 ¶
func (*Writer) WriteInt16 ¶
func (*Writer) WriteInt32 ¶
func (*Writer) WriteInt64 ¶
func (*Writer) WriteMapHeader ¶
func (*Writer) WriteMapStrSimpleType ¶
func (*Writer) WriteMapStrStr ¶
func (*Writer) WriteMapStrStrFromList ¶
func (*Writer) WriteSimpleType ¶
func (mw *Writer) WriteSimpleType(i interface{})
func (*Writer) WriteStaging ¶
func (mw *Writer) WriteStaging()