Documentation ¶
Overview ¶
This package is the support library for the zebrapack code generator (http://github.com/glycerine/zebrapack).
This package defines the utilites used by the zebrapack code generator for encoding and decoding MessagePack from []byte and io.Reader/io.Writer types. Much of this package is devoted to helping the zebrapack code generator implement the Marshaler/Unmarshaler and Encodable/Decodable interfaces.
This package defines four "families" of functions:
- AppendXxxx() appends an object to a []byte in MessagePack encoding.
- ReadXxxxBytes() reads an object from a []byte and returns the remaining bytes.
- (*Writer).WriteXxxx() writes an object to the buffered *Writer type.
- (*Reader).ReadXxxx() reads an object from a buffered *Reader type.
Once a type has satisfied the `Encodable` and `Decodable` interfaces, it can be written and read from arbitrary `io.Writer`s and `io.Reader`s using
msgp.Encode(io.Writer, msgp.Encodable)
and
msgp.Decode(io.Reader, msgp.Decodable)
There are also methods for converting MessagePack to JSON without an explicit de-serialization step.
For additional tips, tricks, and gotchas, please visit the wiki at http://github.com/glycerine/zebrapack
Index ¶
- Constants
- Variables
- func AppendArrayHeader(b []byte, sz uint32) []byte
- func AppendBool(b []byte, t bool) []byte
- func AppendByte(b []byte, u byte) []byte
- func AppendBytes(b []byte, bts []byte) []byte
- func AppendComplex128(b []byte, c complex128) []byte
- func AppendComplex64(b []byte, c complex64) []byte
- func AppendExtension(b []byte, e Extension) ([]byte, error)
- func AppendFloat32(b []byte, f float32) []byte
- func AppendFloat64(b []byte, f float64) []byte
- func AppendInt(b []byte, i int) []byte
- func AppendInt16(b []byte, i int16) []byte
- func AppendInt32(b []byte, i int32) []byte
- func AppendInt64(b []byte, i int64) []byte
- func AppendInt8(b []byte, i int8) []byte
- func AppendIntf(b []byte, i interface{}) ([]byte, error)
- func AppendMapHeader(b []byte, sz uint32) []byte
- func AppendMapStrIntf(b []byte, m map[string]interface{}) ([]byte, error)
- func AppendMapStrStr(b []byte, m map[string]string) []byte
- func AppendNegativeOneAndStringAsBytes(b []byte, str []byte) []byte
- func AppendNil(b []byte) []byte
- func AppendString(b []byte, s string) []byte
- func AppendStringFromBytes(b []byte, str []byte) []byte
- func AppendTime(b []byte, t time.Time) []byte
- func AppendUint(b []byte, u uint) []byte
- func AppendUint16(b []byte, u uint16) []byte
- func AppendUint32(b []byte, u uint32) []byte
- func AppendUint64(b []byte, u uint64) []byte
- func AppendUint8(b []byte, u uint8) []byte
- func CopyReplace(key string, raw []byte, val []byte) []byte
- func CopyToJSON(dst io.Writer, src io.Reader) (n int64, err error)
- func Decode(r io.Reader, d Decodable) error
- func Encode(w io.Writer, e Encodable) error
- func GuessSize(i interface{}) int
- func HasKey(key string, raw []byte) bool
- func IsNil(b []byte) bool
- func Locate(key string, raw []byte) []byte
- func ReadFile(dst Unmarshaler, file *os.File) error
- func RegisterExtension(typ int8, f func() Extension)
- func Remove(key string, raw []byte) []byte
- func Replace(key string, raw []byte, val []byte) []byte
- func Require(old []byte, extra int) []byte
- func ShowFound(found []bool) string
- func Skip(b []byte) ([]byte, error)
- func UnmarshalAsJSON(w io.Writer, msg []byte) ([]byte, error)
- func UnsafeBytes(s string) []byte
- func UnsafeString(b []byte) string
- func WriteFile(src MarshalSizer, file *os.File) error
- type ArrayError
- type ConcreteFactory
- type Decodable
- type Encodable
- type EndlessReader
- type ErrUnsupportedType
- type Error
- type Extension
- type ExtensionTypeError
- type IntOverflow
- type InvalidPrefixError
- type MarshalSizer
- type Marshaler
- type NilBitsStack
- func (r *NilBitsStack) AlwaysNilString() string
- func (nbs *NilBitsStack) DidConsumeNil(b *[]byte) bool
- func (r *NilBitsStack) Init(cfg *RuntimeConfig)
- func (r *NilBitsStack) IsNil(bts []byte) bool
- func (nbs *NilBitsStack) NextStructName(o []byte) (nm string, by []byte)
- func (nbs *NilBitsStack) PeekNil(b []byte) bool
- func (r *NilBitsStack) PopAlwaysNil() (bts []byte)
- func (r *NilBitsStack) PushAlwaysNil(bts []byte) []byte
- func (nbs *NilBitsStack) ReadArrayHeaderBytes(b []byte) (sz uint32, o []byte, err error)
- func (nbs *NilBitsStack) ReadBoolBytes(b []byte) (bool, []byte, error)
- func (nbs *NilBitsStack) ReadByteBytes(b []byte) (byte, []byte, error)
- func (nbs *NilBitsStack) ReadBytesBytes(b []byte, scratch []byte) (v []byte, o []byte, err error)
- func (nbs *NilBitsStack) ReadBytesZC(b []byte) (v []byte, o []byte, err error)
- func (nbs *NilBitsStack) ReadComplex128Bytes(b []byte) (c complex128, o []byte, err error)
- func (nbs *NilBitsStack) ReadComplex64Bytes(b []byte) (c complex64, o []byte, err error)
- func (nbs *NilBitsStack) ReadExactBytes(b []byte, into []byte) (o []byte, err error)
- func (nbs *NilBitsStack) ReadExtensionBytes(b []byte, e Extension) ([]byte, error)
- func (nbs *NilBitsStack) ReadFloat32Bytes(b []byte) (f float32, o []byte, err error)
- func (nbs *NilBitsStack) ReadFloat64Bytes(b []byte) (f float64, o []byte, err error)
- func (nbs *NilBitsStack) ReadInt16Bytes(b []byte) (int16, []byte, error)
- func (nbs *NilBitsStack) ReadInt32Bytes(b []byte) (int32, []byte, error)
- func (nbs *NilBitsStack) ReadInt64Bytes(b []byte) (i int64, o []byte, err error)
- func (nbs *NilBitsStack) ReadInt8Bytes(b []byte) (int8, []byte, error)
- func (nbs *NilBitsStack) ReadIntBytes(b []byte) (int, []byte, error)
- func (nbs *NilBitsStack) ReadIntfBytes(b []byte) (i interface{}, o []byte, err error)
- func (nbs *NilBitsStack) ReadMapHeaderBytes(b []byte) (sz uint32, o []byte, err error)
- func (nbs *NilBitsStack) ReadMapKeyZC(b []byte) ([]byte, []byte, error)
- func (nbs *NilBitsStack) ReadMapStrIntfBytes(b []byte, old map[string]interface{}) (v map[string]interface{}, o []byte, err error)
- func (nbs *NilBitsStack) ReadNilBytes(b []byte) ([]byte, error)
- func (nbs *NilBitsStack) ReadStringAsBytes(b []byte, scratch []byte) (v []byte, o []byte, err error)
- func (nbs *NilBitsStack) ReadStringBytes(b []byte) (string, []byte, error)
- func (nbs *NilBitsStack) ReadStringZC(b []byte) (v []byte, o []byte, err error)
- func (nbs *NilBitsStack) ReadTimeBytes(b []byte) (t time.Time, o []byte, err error)
- func (nbs *NilBitsStack) ReadUint16Bytes(b []byte) (uint16, []byte, error)
- func (nbs *NilBitsStack) ReadUint32Bytes(b []byte) (uint32, []byte, error)
- func (nbs *NilBitsStack) ReadUint64Bytes(b []byte) (u uint64, o []byte, err error)
- func (nbs *NilBitsStack) ReadUint8Bytes(b []byte) (uint8, []byte, error)
- func (nbs *NilBitsStack) ReadUintBytes(b []byte) (uint, []byte, error)
- type NilTracker
- type Number
- func (n *Number) AsFloat32(f float32)
- func (n *Number) AsFloat64(f float64)
- func (n *Number) AsInt(i int64)
- func (n *Number) AsUint(u uint64)
- func (n *Number) DecodeMsg(r *Reader) error
- func (n *Number) EncodeMsg(w *Writer) error
- func (n *Number) Float() (float64, bool)
- func (n *Number) Int() (int64, bool)
- func (n *Number) MarshalJSON() ([]byte, error)
- func (n *Number) MarshalMsg(b []byte) ([]byte, error)
- func (n *Number) Msgsize() int
- func (n *Number) String() string
- func (n *Number) Type() Type
- func (n *Number) Uint() (uint64, bool)
- func (n *Number) UnmarshalMsg(b []byte) ([]byte, error)
- type PostLoad
- type PreSave
- type Raw
- type RawExtension
- type Reader
- func (m *Reader) BufferSize() int
- func (m *Reader) Buffered() int
- func (m *Reader) IsNil() bool
- func (m *Reader) NextStructName() string
- func (m *Reader) NextType() (Type, error)
- func (m *Reader) Read(p []byte) (int, error)
- func (m *Reader) ReadArrayHeader() (sz uint32, err error)
- func (m *Reader) ReadBool() (b bool, err error)
- func (m *Reader) ReadByte() (b byte, err error)
- func (m *Reader) ReadBytes(scratch []byte) (b []byte, err error)
- func (m *Reader) ReadBytesHeader() (sz uint32, err error)
- func (m *Reader) ReadComplex128() (f complex128, err error)
- func (m *Reader) ReadComplex64() (f complex64, err error)
- func (m *Reader) ReadExactBytes(into []byte) error
- func (m *Reader) ReadExtension(e Extension) (err error)
- func (m *Reader) ReadFloat32() (f float32, err error)
- func (m *Reader) ReadFloat64() (f float64, err error)
- func (m *Reader) ReadFull(p []byte) (int, error)
- func (m *Reader) ReadInt() (i int, err error)
- func (m *Reader) ReadInt16() (i int16, err error)
- func (m *Reader) ReadInt32() (i int32, err error)
- func (m *Reader) ReadInt64() (i int64, err error)
- func (m *Reader) ReadInt8() (i int8, err error)
- func (m *Reader) ReadIntf() (i interface{}, err error)
- func (m *Reader) ReadMapHeader() (sz uint32, err error)
- func (m *Reader) ReadMapKey(scratch []byte) ([]byte, error)
- func (m *Reader) ReadMapKeyPtr() ([]byte, error)
- func (m *Reader) ReadMapStrIntf(mp map[string]interface{}) (err error)
- func (m *Reader) ReadNil() error
- func (m *Reader) ReadString() (s string, err error)
- func (m *Reader) ReadStringAsBytes(scratch []byte) (b []byte, err error)
- func (m *Reader) ReadStringHeader() (sz uint32, err error)
- func (m *Reader) ReadTime() (t time.Time, err error)
- func (m *Reader) ReadUint() (u uint, err error)
- func (m *Reader) ReadUint16() (u uint16, err error)
- func (m *Reader) ReadUint32() (u uint32, err error)
- func (m *Reader) ReadUint64() (u uint64, err error)
- func (m *Reader) ReadUint8() (u uint8, err error)
- func (m *Reader) Reset(r io.Reader)
- func (m *Reader) Skip() error
- func (r *Reader) WriteToJSON(w io.Writer) (n int64, err error)
- type RuntimeConfig
- type Sizer
- type Type
- type TypeError
- type UintOverflow
- type Unmarshaler
- type Writer
- func (mw *Writer) Append(b ...byte) error
- func (mw *Writer) Buffered() int
- func (mw *Writer) Flush() error
- func (mw *Writer) Reset(w io.Writer)
- func (mw *Writer) Write(p []byte) (int, error)
- func (mw *Writer) WriteArrayHeader(sz uint32) error
- func (mw *Writer) WriteBool(b bool) error
- func (mw *Writer) WriteByte(u byte) error
- func (mw *Writer) WriteBytes(b []byte) error
- func (mw *Writer) WriteBytesHeader(sz uint32) error
- func (mw *Writer) WriteComplex128(f complex128) error
- func (mw *Writer) WriteComplex64(f complex64) error
- func (mw *Writer) WriteExtension(e Extension) error
- func (mw *Writer) WriteFloat32(f float32) error
- func (mw *Writer) WriteFloat64(f float64) error
- func (mw *Writer) WriteInt(i int) error
- func (mw *Writer) WriteInt16(i int16) error
- func (mw *Writer) WriteInt32(i int32) error
- func (mw *Writer) WriteInt64(i int64) error
- func (mw *Writer) WriteInt8(i int8) error
- func (mw *Writer) WriteIntf(v interface{}) error
- func (mw *Writer) WriteMapHeader(sz uint32) error
- func (mw *Writer) WriteMapStrIntf(mp map[string]interface{}) (err error)
- func (mw *Writer) WriteMapStrStr(mp map[string]string) (err error)
- func (mw *Writer) WriteNil() error
- func (mw *Writer) WriteString(s string) error
- func (mw *Writer) WriteStringFromBytes(str []byte) error
- func (mw *Writer) WriteStringHeader(sz uint32) error
- func (mw *Writer) WriteTime(t time.Time) error
- func (mw *Writer) WriteUint(u uint) error
- func (mw *Writer) WriteUint16(u uint16) error
- func (mw *Writer) WriteUint32(u uint32) error
- func (mw *Writer) WriteUint64(u uint64) error
- func (mw *Writer) WriteUint8(u uint8) error
Constants ¶
const ( // Complex64Extension is the extension number used for complex64 Complex64Extension = 3 // Complex128Extension is the extension number used for complex128 Complex128Extension = 4 // TimeExtension is the extension number used for time.Time TimeExtension = 5 )
const ( Int64Size = 9 IntSize = Int64Size UintSize = Int64Size Int8Size = 2 Int16Size = 3 Int32Size = 5 Uint8Size = 2 ByteSize = Uint8Size Uint16Size = 3 Uint32Size = 5 Uint64Size = Int64Size Float64Size = 9 Float32Size = 5 Complex64Size = 10 Complex128Size = 18 TimeSize = 15 BoolSize = 1 NilSize = 1 MapHeaderSize = 5 ArrayHeaderSize = 5 BytesPrefixSize = 5 StringPrefixSize = 5 ExtensionPrefixSize = 6 )
The sizes provided are the worst-case encoded sizes for each type. For variable- length types ([]byte, string), the total encoded size is the prefix size plus the length of the object.
const MaxNestedStructPointerDepth = 8
Variables ¶
var ( // ErrShortBytes is returned when the // slice being decoded is too short to // contain the contents of the message ErrShortBytes error = errShort{} )
var ( // Nowhere is an io.Writer to nowhere Nowhere io.Writer = nwhere{} )
var OnlyNilSlice = []byte{mnil}
OnlyNilSlice is a slice that contains only the msgpack nil (0xc0) bytes.
Functions ¶
func AppendArrayHeader ¶
AppendArrayHeader appends an array header with the given size to the slice
func AppendBytes ¶
AppendBytes appends bytes to the slice as MessagePack 'bin' data
func AppendComplex128 ¶
func AppendComplex128(b []byte, c complex128) []byte
AppendComplex128 appends a complex128 to the slice as a MessagePack extension
func AppendComplex64 ¶
AppendComplex64 appends a complex64 to the slice as a MessagePack extension
func AppendExtension ¶
AppendExtension appends a MessagePack extension to the provided slice
func AppendFloat32 ¶
AppendFloat32 appends a float32 to the slice
func AppendFloat64 ¶
AppendFloat64 appends a float64 to the slice
func AppendInt16 ¶
AppendInt16 appends an int16 to the slice
func AppendInt32 ¶
AppendInt32 appends an int32 to the slice
func AppendInt64 ¶
AppendInt64 appends an int64 to the slice
func AppendIntf ¶
AppendIntf appends the concrete type of 'i' to the provided []byte. 'i' must be one of the following:
- 'nil'
- A bool, float, string, []byte, int, uint, or complex
- A map[string]interface{} or map[string]string
- A []T, where T is another supported type
- A *T, where T is another supported type
- A type that satisfieds the msgp.Marshaler interface
- A type that satisfies the msgp.Extension interface
func AppendMapHeader ¶
AppendMapHeader appends a map header with the given size to the slice
func AppendMapStrIntf ¶
AppendMapStrIntf appends a map[string]interface{} to the slice as a MessagePack map with 'str'-type keys.
func AppendMapStrStr ¶
AppendMapStrStr appends a map[string]string to the slice as a MessagePack map with 'str'-type keys and values
func AppendNegativeOneAndStringAsBytes ¶
AppendNegativeOneAndString is a helper for runtime struct id
func AppendString ¶
AppendString appends a string as a MessagePack 'str' to the slice
func AppendStringFromBytes ¶
AppendStringFromBytes appends a []byte as a MessagePack 'str' to the slice 'b.'
func AppendTime ¶
AppendTime appends a time.Time to the slice as a MessagePack extension
func AppendUint16 ¶
AppendUint16 appends a uint16 to the slice
func AppendUint32 ¶
AppendUint32 appends a uint32 to the slice
func AppendUint64 ¶
AppendUint64 appends a uint64 to the slice
func AppendUint8 ¶
AppendUint8 appends a uint8 to the slice
func CopyReplace ¶
CopyReplace works similarly to Replace except that the returned byte slice does not point to the same memory as 'raw'. CopyReplace returns 'nil' if the field doesn't exist or 'raw' isn't a map.
func CopyToJSON ¶
CopyToJSON reads MessagePack from 'src' and copies it as JSON to 'dst' until EOF.
func GuessSize ¶
func GuessSize(i interface{}) int
GuessSize guesses the size of the underlying value of 'i'. If the underlying value is not a simple builtin (or []byte), GuessSize defaults to 512.
func IsNil ¶
IsNil returns true if len(b)>0 and the leading byte is a 'nil' MessagePack byte; false otherwise
func Locate ¶
Locate returns a []byte pointing to the field in a messagepack map with the provided key. (The returned []byte points to a sub-slice of 'raw'; Locate does no allocations.) If the key doesn't exist in the map, a zero-length []byte will be returned.
func ReadFile ¶
func ReadFile(dst Unmarshaler, file *os.File) error
ReadFile reads a file into 'dst' using a read-only memory mapping. Consequently, the file must be mmap-able, and the Unmarshaler should never write to the source memory. (Methods generated by the msgp tool obey that constraint, but user-defined implementations may not.)
Reading and writing through file mappings is only efficient for large files; small files are best read and written using the ordinary streaming interfaces.
func RegisterExtension ¶
RegisterExtension registers extensions so that they can be initialized and returned by methods that decode `interface{}` values. This should only be called during initialization. f() should return a newly-initialized zero value of the extension. Keep in mind that extensions 3, 4, and 5 are reserved for complex64, complex128, and time.Time, respectively, and that MessagePack reserves extension types from -127 to -1.
For example, if you wanted to register a user-defined struct:
msgp.RegisterExtension(10, func() msgp.Extension { &MyExtension{} })
RegisterExtension will panic if you call it multiple times with the same 'typ' argument, or if you use a reserved type (3, 4, or 5).
func Remove ¶
Remove removes a key-value pair from 'raw'. It returns 'raw' unchanged if the key didn't exist.
func Replace ¶
Replace takes a key ("key") in a messagepack map ("raw") and replaces its value with the one provided and returns the new []byte. The returned []byte may point to the same memory as "raw". Replace makes no effort to evaluate the validity of the contents of 'val'. It may use up to the full capacity of 'raw.' Replace returns 'nil' if the field doesn't exist or if the object in 'raw' is not a map.
func Skip ¶
Skip skips the next object in 'b' and returns the remaining bytes. If the object is a map or array, all of its elements will be skipped. Possible Errors: - ErrShortBytes (not enough bytes in b) - InvalidPrefixError (bad encoding)
func UnmarshalAsJSON ¶
UnmarshalAsJSON takes raw messagepack and writes it as JSON to 'w'. If an error is returned, the bytes not translated will also be returned. If no errors are encountered, the length of the returned slice will be zero.
func UnsafeBytes ¶
UnsafeBytes returns the string as a byte slice THIS SHOULD ONLY BE USED BY THE CODE GENERATOR. THIS IS EVIL CODE. YOU HAVE BEEN WARNED.
func UnsafeString ¶
UnsafeString returns the byte slice as a volatile string THIS SHOULD ONLY BE USED BY THE CODE GENERATOR. THIS IS EVIL CODE. YOU HAVE BEEN WARNED.
func WriteFile ¶
func WriteFile(src MarshalSizer, file *os.File) error
WriteFile writes a file from 'src' using memory mapping. It overwrites the entire contents of the previous file. The mapping size is calculated using the `Msgsize()` method of 'src', so it must produce a result equal to or greater than the actual encoded size of the object. Otherwise, a fault (SIGBUS) will occur.
Reading and writing through file mappings is only efficient for large files; small files are best read and written using the ordinary streaming interfaces.
NOTE: The performance of this call is highly OS- and filesystem-dependent. Users should take care to test that this performs as expected in a production environment. (Linux users should run a kernel and filesystem that support fallocate(2) for the best results.)
Types ¶
type ArrayError ¶
ArrayError is an error returned when decoding a fix-sized array of the wrong size
func (ArrayError) Resumable ¶
func (a ArrayError) Resumable() bool
Resumable is always 'true' for ArrayErrors
type ConcreteFactory ¶
type Decodable ¶
Decodable is the interface fulfilled by objects that know how to read themselves from a *Reader.
type Encodable ¶
Encodable is the interface implemented by types that know how to write themselves as MessagePack using a *msgp.Writer.
type EndlessReader ¶
type EndlessReader struct {
// contains filtered or unexported fields
}
EndlessReader is an io.Reader that loops over the same data endlessly. It is used for benchmarking.
func NewEndlessReader ¶
func NewEndlessReader(b []byte, tb timer) *EndlessReader
NewEndlessReader returns a new endless reader
type ErrUnsupportedType ¶
ErrUnsupportedType is returned when a bad argument is supplied to a function that takes `interface{}`.
func (*ErrUnsupportedType) Error ¶
func (e *ErrUnsupportedType) Error() string
Error implements error
func (*ErrUnsupportedType) Resumable ¶
func (e *ErrUnsupportedType) Resumable() bool
Resumable returns 'true' for ErrUnsupportedType
type Error ¶
type Error interface { error // Resumable returns whether // or not the error means that // the stream of data is malformed // and the information is unrecoverable. Resumable() bool }
Error is the interface satisfied by all of the errors that originate from this package.
type Extension ¶
type Extension interface { // ExtensionType should return // a int8 that identifies the concrete // type of the extension. (Types <0 are // officially reserved by the MessagePack // specifications.) ExtensionType() int8 // Len should return the length // of the data to be encoded Len() int // MarshalBinaryTo should copy // the data into the supplied slice, // assuming that the slice has length Len() MarshalBinaryTo([]byte) error UnmarshalBinary([]byte) error }
Extension is the interface fulfilled by types that want to define their own binary encoding.
type ExtensionTypeError ¶
ExtensionTypeError is an error type returned when there is a mis-match between an extension type and the type encoded on the wire
func (ExtensionTypeError) Error ¶
func (e ExtensionTypeError) Error() string
Error implements the error interface
func (ExtensionTypeError) Resumable ¶
func (e ExtensionTypeError) Resumable() bool
Resumable returns 'true' for ExtensionTypeErrors
type IntOverflow ¶
type IntOverflow struct { Value int64 // the value of the integer FailedBitsize int // the bit size that the int64 could not fit into }
IntOverflow is returned when a call would downcast an integer to a type with too few bits to hold its value.
func (IntOverflow) Resumable ¶
func (i IntOverflow) Resumable() bool
Resumable is always 'true' for overflows
type InvalidPrefixError ¶
type InvalidPrefixError byte
InvalidPrefixError is returned when a bad encoding uses a prefix that is not recognized in the MessagePack standard. This kind of error is unrecoverable.
func (InvalidPrefixError) Error ¶
func (i InvalidPrefixError) Error() string
Error implements the error interface
func (InvalidPrefixError) Resumable ¶
func (i InvalidPrefixError) Resumable() bool
Resumable returns 'false' for InvalidPrefixErrors
type MarshalSizer ¶
MarshalSizer is the combination of the Marshaler and Sizer interfaces.
type Marshaler ¶
Marshaler is the interface implemented by types that know how to marshal themselves as MessagePack. MarshalMsg appends the marshalled form of the object to the provided byte slice, returning the extended slice and any errors encountered.
type NilBitsStack ¶
type NilBitsStack struct { // simulate getting nils on the wire AlwaysNil bool LifoAlwaysNil int // this lifo always had false in it, so change it to a count. LifoBts [MaxNestedStructPointerDepth][]byte // caps our static tree depth at 8, but avoids all memory allocation during the decode hotpath. // UnsafeZeroCopy will make strings point to the // original msgpack buffers. This is unsafe because // if the buffer changes the string will change/be // invalid/not protected against re-use. But for // processing and disposing of single messages, one-at-at-time, // without re-using any part of a message (or making a copy of strings explicitly with copy() // if you must) then we can avoid all allocations for strings. UnsafeZeroCopy bool }
NilBitsStack is a helper for Unmarshal methods to track where we are when deserializing from empty/nil/missing fields.
func (*NilBitsStack) AlwaysNilString ¶
func (r *NilBitsStack) AlwaysNilString() string
AlwaysNilString returns a string representation of the internal state of the NilBitsStack for debugging purposes.
func (*NilBitsStack) DidConsumeNil ¶
func (nbs *NilBitsStack) DidConsumeNil(b *[]byte) bool
DidConsumeNil returns true without changing b if nbs.AlwaysNil is true.
Otherwise, if (*b)[0] is 0xc0, then ConsumeNil returns true and consumes the nil from (*b).
This convenience method avoids having to have separate consume-the-Nil-or-not logic after an IsNil call.
func (*NilBitsStack) Init ¶
func (r *NilBitsStack) Init(cfg *RuntimeConfig)
func (*NilBitsStack) IsNil ¶
func (r *NilBitsStack) IsNil(bts []byte) bool
func (*NilBitsStack) NextStructName ¶
func (nbs *NilBitsStack) NextStructName(o []byte) (nm string, by []byte)
NextTypeName inspects the next time, assuming it is a struct (map) for its (-1: name) key-value pair, and returns the name or empty string if not found. Also empty string if not a map type.
func (*NilBitsStack) PeekNil ¶
func (nbs *NilBitsStack) PeekNil(b []byte) bool
func (*NilBitsStack) PopAlwaysNil ¶
func (r *NilBitsStack) PopAlwaysNil() (bts []byte)
PopAlwaysNil pops the last []byte off the internal stack and returns it. If the stack is empty we panic.
func (*NilBitsStack) PushAlwaysNil ¶
func (r *NilBitsStack) PushAlwaysNil(bts []byte) []byte
PushAlwaysNil will set r.AlwaysNil to true and store bts on the internal stack.
func (*NilBitsStack) ReadArrayHeaderBytes ¶
func (nbs *NilBitsStack) ReadArrayHeaderBytes(b []byte) (sz uint32, o []byte, err error)
ReadArrayHeaderBytes attempts to read the array header size off of 'b' and return the size and remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not an array)
func (*NilBitsStack) ReadBoolBytes ¶
func (nbs *NilBitsStack) ReadBoolBytes(b []byte) (bool, []byte, error)
ReadBoolBytes tries to read a bool from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a bool)
func (*NilBitsStack) ReadByteBytes ¶
func (nbs *NilBitsStack) ReadByteBytes(b []byte) (byte, []byte, error)
ReadByteBytes is analogous to ReadUint8Bytes
func (*NilBitsStack) ReadBytesBytes ¶
ReadBytesBytes reads a 'bin' object from 'b' and returns its vaue and the remaining bytes in 'b'. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a 'bin' object)
func (*NilBitsStack) ReadBytesZC ¶
func (nbs *NilBitsStack) ReadBytesZC(b []byte) (v []byte, o []byte, err error)
ReadBytesZC extracts the messagepack-encoded binary field without copying. The returned []byte points to the same memory as the input slice. Possible errors: - ErrShortBytes (b not long enough) - TypeError{} (object not 'bin')
func (*NilBitsStack) ReadComplex128Bytes ¶
func (nbs *NilBitsStack) ReadComplex128Bytes(b []byte) (c complex128, o []byte, err error)
ReadComplex128Bytes reads a complex128 extension object from 'b' and returns the remaining bytes. Possible errors: - ErrShortBytes (not enough bytes in 'b') - TypeError{} (object not a complex128) - InvalidPrefixError - ExtensionTypeError{} (object an extension of the correct size, but not a complex128)
func (*NilBitsStack) ReadComplex64Bytes ¶
func (nbs *NilBitsStack) ReadComplex64Bytes(b []byte) (c complex64, o []byte, err error)
ReadComplex64Bytes reads a complex64 extension object from 'b' and returns the remaining bytes. Possible errors: - ErrShortBytes (not enough bytes in 'b') - TypeError{} (object not a complex64) - ExtensionTypeError{} (object an extension of the correct size, but not a complex64)
func (*NilBitsStack) ReadExactBytes ¶
func (nbs *NilBitsStack) ReadExactBytes(b []byte, into []byte) (o []byte, err error)
func (*NilBitsStack) ReadExtensionBytes ¶
func (nbs *NilBitsStack) ReadExtensionBytes(b []byte, e Extension) ([]byte, error)
ReadExtensionBytes reads an extension from 'b' into 'e' and returns any remaining bytes. Possible errors: - ErrShortBytes ('b' not long enough) - ExtensionTypeErorr{} (wire type not the same as e.Type()) - TypeErorr{} (next object not an extension) - InvalidPrefixError - An umarshal error returned from e.UnmarshalBinary
func (*NilBitsStack) ReadFloat32Bytes ¶
func (nbs *NilBitsStack) ReadFloat32Bytes(b []byte) (f float32, o []byte, err error)
ReadFloat32Bytes tries to read a float64 from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a float32)
func (*NilBitsStack) ReadFloat64Bytes ¶
func (nbs *NilBitsStack) ReadFloat64Bytes(b []byte) (f float64, o []byte, err error)
ReadFloat64Bytes tries to read a float64 from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a float64)
func (*NilBitsStack) ReadInt16Bytes ¶
func (nbs *NilBitsStack) ReadInt16Bytes(b []byte) (int16, []byte, error)
ReadInt16Bytes tries to read an int16 from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a int) - IntOverflow{} (value doesn't fit in int16)
func (*NilBitsStack) ReadInt32Bytes ¶
func (nbs *NilBitsStack) ReadInt32Bytes(b []byte) (int32, []byte, error)
ReadInt32Bytes tries to read an int32 from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a int) - IntOverflow{} (value doesn't fit in int32)
func (*NilBitsStack) ReadInt64Bytes ¶
func (nbs *NilBitsStack) ReadInt64Bytes(b []byte) (i int64, o []byte, err error)
ReadInt64Bytes tries to read an int64 from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError (not a int)
func (*NilBitsStack) ReadInt8Bytes ¶
func (nbs *NilBitsStack) ReadInt8Bytes(b []byte) (int8, []byte, error)
ReadInt8Bytes tries to read an int16 from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a int) - IntOverflow{} (value doesn't fit in int8)
func (*NilBitsStack) ReadIntBytes ¶
func (nbs *NilBitsStack) ReadIntBytes(b []byte) (int, []byte, error)
ReadIntBytes tries to read an int from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a int) - IntOverflow{} (value doesn't fit in int; 32-bit platforms only)
func (*NilBitsStack) ReadIntfBytes ¶
func (nbs *NilBitsStack) ReadIntfBytes(b []byte) (i interface{}, o []byte, err error)
ReadIntfBytes attempts to read the next object out of 'b' as a raw interface{} and return the remaining bytes.
func (*NilBitsStack) ReadMapHeaderBytes ¶
func (nbs *NilBitsStack) ReadMapHeaderBytes(b []byte) (sz uint32, o []byte, err error)
ReadMapHeaderBytes reads a map header size from 'b' and returns the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a map)
func (*NilBitsStack) ReadMapKeyZC ¶
func (nbs *NilBitsStack) ReadMapKeyZC(b []byte) ([]byte, []byte, error)
ReadMapKeyZC attempts to read a map key from 'b' and returns the key bytes and the remaining bytes Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a str or bin)
func (*NilBitsStack) ReadMapStrIntfBytes ¶
func (nbs *NilBitsStack) ReadMapStrIntfBytes(b []byte, old map[string]interface{}) (v map[string]interface{}, o []byte, err error)
ReadMapStrIntfBytes reads a map[string]interface{} out of 'b' and returns the map and remaining bytes. If 'old' is non-nil, the values will be read into that map.
func (*NilBitsStack) ReadNilBytes ¶
func (nbs *NilBitsStack) ReadNilBytes(b []byte) ([]byte, error)
ReadNilBytes tries to read a "nil" byte off of 'b' and return the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a 'nil') - InvalidPrefixError
func (*NilBitsStack) ReadStringAsBytes ¶
func (nbs *NilBitsStack) ReadStringAsBytes(b []byte, scratch []byte) (v []byte, o []byte, err error)
ReadStringAsBytes reads a 'str' object into a slice of bytes. 'v' is the value of the 'str' object, which may reside in memory pointed to by 'scratch.' 'o' is the remaining bytes in 'b.” Possible errors: - ErrShortBytes (b not long enough) - TypeError{} (not 'str' type) - InvalidPrefixError (unknown type marker)
func (*NilBitsStack) ReadStringBytes ¶
func (nbs *NilBitsStack) ReadStringBytes(b []byte) (string, []byte, error)
ReadStringBytes reads a 'str' object from 'b' and returns its value and the remaining bytes in 'b'. Possible errors: - ErrShortBytes (b not long enough) - TypeError{} (not 'str' type) - InvalidPrefixError
func (*NilBitsStack) ReadStringZC ¶
func (nbs *NilBitsStack) ReadStringZC(b []byte) (v []byte, o []byte, err error)
ReadStringZC reads a messagepack string field without copying. The returned []byte points to the same memory as the input slice. Possible errors: - ErrShortBytes (b not long enough) - TypeError{} (object not 'str')
func (*NilBitsStack) ReadTimeBytes ¶
ReadTimeBytes reads a time.Time extension object from 'b' and returns the remaining bytes. Possible errors: - ErrShortBytes (not enough bytes in 'b') - TypeError{} (object not a complex64) - ExtensionTypeError{} (object an extension of the correct size, but not a time.Time)
func (*NilBitsStack) ReadUint16Bytes ¶
func (nbs *NilBitsStack) ReadUint16Bytes(b []byte) (uint16, []byte, error)
ReadUint16Bytes tries to read a uint16 from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a uint) - UintOverflow{} (value too large for uint16)
func (*NilBitsStack) ReadUint32Bytes ¶
func (nbs *NilBitsStack) ReadUint32Bytes(b []byte) (uint32, []byte, error)
ReadUint32Bytes tries to read a uint32 from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a uint) - UintOverflow{} (value too large for uint32)
func (*NilBitsStack) ReadUint64Bytes ¶
func (nbs *NilBitsStack) ReadUint64Bytes(b []byte) (u uint64, o []byte, err error)
ReadUint64Bytes tries to read a uint64 from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a uint)
func (*NilBitsStack) ReadUint8Bytes ¶
func (nbs *NilBitsStack) ReadUint8Bytes(b []byte) (uint8, []byte, error)
ReadUint8Bytes tries to read a uint8 from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a uint) - UintOverflow{} (value too large for uint8)
func (*NilBitsStack) ReadUintBytes ¶
func (nbs *NilBitsStack) ReadUintBytes(b []byte) (uint, []byte, error)
ReadUintBytes tries to read a uint from 'b' and return the value and the remaining bytes. Possible errors: - ErrShortBytes (too few bytes) - TypeError{} (not a uint) - UintOverflow{} (value too large for uint; 32-bit platforms only)
type NilTracker ¶
NilTracker maintains a stack to assit DecodeMsg methods when deserializing from nil fields.
func (*NilTracker) AlwaysNilString ¶
func (r *NilTracker) AlwaysNilString() string
AlwaysNilString returns a string representation of the internal state of the stack for debugging purposes.
func (*NilTracker) PopAlwaysNil ¶
func (r *NilTracker) PopAlwaysNil()
PopAlwaysNil pops the last entry off the internal stack and uses it to set r.AlwaysNil.
func (*NilTracker) PushAlwaysNil ¶
func (r *NilTracker) PushAlwaysNil()
PushAlwaysNil will set r.AlwaysNil to true and store the previous value of r.AlwaysNil on the internal stack.
type Number ¶
type Number struct {
// contains filtered or unexported fields
}
Number can be an int64, uint64, float32, or float64 internally. It can decode itself from any of the native messagepack number types. The zero-value of Number is Int(0). Using the equality operator with Number compares both the type and the value of the number.
func (*Number) Float ¶
Float casts the number to a float64, and returns whether or not that was the underlying type (either a float64 or a float32).
func (*Number) Int ¶
Int casts the number as an int64, and returns whether or not that was the underlying type.
func (*Number) MarshalJSON ¶
MarshalJSON implements json.Marshaler
func (*Number) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type PostLoad ¶
type PostLoad interface { // PostLoadHook is called after // msgp.UnmarshalMsg and msgp.DecodeMsg. // The opposite of PreSaveHook, it allows // one to add a custom finishing step // after basic deserialization has // completed. PostLoadHook() }
PostLoad will be called after DecodeMsg/UnmarshalMsg, if you struct implements it.
type PreSave ¶
type PreSave interface { // PreSaveHook is called before msgp.MarshalMsg // and msgp.EncodeMsg. It allows you to prep // the struct for serialization. See // PostLoadHook for the complimentary hook // called after deserialization. PreSaveHook() }
PreSave will be called before EncodeMsg/MarshalMsg if you struct implements it.
type Raw ¶
type Raw []byte
Raw is raw MessagePack. Raw allows you to read and write data without interpreting its contents.
func (*Raw) DecodeMsg ¶
DecodeMsg implements msgp.Decodable. It sets the value of *Raw to be the next object on the wire.
func (Raw) EncodeMsg ¶
EncodeMsg implements msgp.Encodable. It writes the raw bytes to the writer. If r is empty, it writes 'nil' instead.
func (*Raw) MarshalJSON ¶
MarshalJSON implements json.Marshaler
func (Raw) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler. It appends the raw contents of 'raw' to the provided byte slice. If 'raw' is 0 bytes, 'nil' will be appended instead.
type RawExtension ¶
RawExtension implements the Extension interface
func (*RawExtension) ExtensionType ¶
func (r *RawExtension) ExtensionType() int8
ExtensionType implements Extension.ExtensionType, and returns r.Type
func (*RawExtension) Len ¶
func (r *RawExtension) Len() int
Len implements Extension.Len, and returns len(r.Data)
func (*RawExtension) MarshalBinaryTo ¶
func (r *RawExtension) MarshalBinaryTo(d []byte) error
MarshalBinaryTo implements Extension.MarshalBinaryTo, and returns a copy of r.Data
func (*RawExtension) UnmarshalBinary ¶
func (r *RawExtension) UnmarshalBinary(b []byte) error
UnmarshalBinary implements Extension.UnmarshalBinary, and sets r.Data to the contents of the provided slice
type Reader ¶
type Reader struct { // R is the buffered reader // that the Reader uses // to decode MessagePack. // The Reader itself // is stateless; all the // buffering is done // within R. R *fwd.Reader NilTracker // contains filtered or unexported fields }
Reader wraps an io.Reader and provides methods to read MessagePack-encoded values from it. Readers are buffered.
func NewReader ¶
NewReader returns a *Reader that reads from the provided reader. The reader will be buffered.
func NewReaderSize ¶
NewReaderSize returns a *Reader with a buffer of the given size. (This is vastly preferable to passing the decoder a reader that is already buffered.)
func (*Reader) BufferSize ¶
BufferSize returns the capacity of the read buffer.
func (*Reader) NextStructName ¶
NextStructName inspects the next time, assuming it is a struct (map) for its (-1: name) key-value pair, and returns the name or empty string if not found. Also empty string if not a map type.
func (*Reader) ReadArrayHeader ¶
ReadArrayHeader reads the next object as an array header and returns the size of the array and the number of bytes read.
func (*Reader) ReadByte ¶
ReadByte is analogous to ReadUint8.
NOTE: this is *not* an implementation of io.ByteReader.
func (*Reader) ReadBytes ¶
ReadBytes reads a MessagePack 'bin' object from the reader and returns its value. It may use 'scratch' for storage if it is non-nil.
func (*Reader) ReadBytesHeader ¶
ReadBytesHeader reads the size header of a MessagePack 'bin' object. The user is responsible for dealing with the next 'sz' bytes from the reader in an application-specific way.
func (*Reader) ReadComplex128 ¶
func (m *Reader) ReadComplex128() (f complex128, err error)
ReadComplex128 reads a complex128 from the reader
func (*Reader) ReadComplex64 ¶
ReadComplex64 reads a complex64 from the reader
func (*Reader) ReadExactBytes ¶
ReadExactBytes reads a MessagePack 'bin'-encoded object off of the wire into the provided slice. An ArrayError will be returned if the object is not exactly the length of the input slice.
func (*Reader) ReadExtension ¶
ReadExtension reads the next object from the reader as an extension. ReadExtension will fail if the next object in the stream is not an extension, or if e.Type() is not the same as the wire type.
func (*Reader) ReadFloat32 ¶
ReadFloat32 reads a float32 from the reader
func (*Reader) ReadFloat64 ¶
ReadFloat64 reads a float64 from the reader. (If the value on the wire is encoded as a float32, it will be up-cast to a float64.)
func (*Reader) ReadIntf ¶
ReadIntf reads out the next object as a raw interface{}. Arrays are decoded as []interface{}, and maps are decoded as map[string]interface{}. Integers are decoded as int64 and unsigned integers are decoded as uint64.
func (*Reader) ReadMapHeader ¶
ReadMapHeader reads the next object as a map header and returns the size of the map and the number of bytes written. It will return a TypeError{} if the next object is not a map.
func (*Reader) ReadMapKey ¶
ReadMapKey reads either a 'str' or 'bin' field from the reader and returns the value as a []byte. It uses scratch for storage if it is large enough.
func (*Reader) ReadMapKeyPtr ¶
MapKeyPtr returns a []byte pointing to the contents of a valid map key. The key cannot be empty, and it must be shorter than the total buffer size of the *Reader. Additionally, the returned slice is only valid until the next *Reader method call. Users should exercise extreme care when using this method; writing into the returned slice may corrupt future reads.
func (*Reader) ReadMapStrIntf ¶
ReadMapStrIntf reads a MessagePack map into a map[string]interface{}. (You must pass a non-nil map into the function.)
func (*Reader) ReadString ¶
ReadString reads a utf-8 string from the reader
func (*Reader) ReadStringAsBytes ¶
ReadStringAsBytes reads a MessagePack 'str' (utf-8) string and returns its value as bytes. It may use 'scratch' for storage if it is non-nil.
func (*Reader) ReadStringHeader ¶
ReadStringHeader reads a string header off of the wire. The user is then responsible for dealing with the next 'sz' bytes from the reader in an application-specific manner.
func (*Reader) ReadTime ¶
ReadTime reads a time.Time object from the reader. The returned time's location will be set to time.Local.
func (*Reader) ReadUint16 ¶
ReadUint16 reads a uint16 from the reader
func (*Reader) ReadUint32 ¶
ReadUint32 reads a uint32 from the reader
func (*Reader) ReadUint64 ¶
ReadUint64 reads a uint64 from the reader
type RuntimeConfig ¶
type RuntimeConfig struct { // UnsafeZeroCopy will make strings point to the // original msgpack buffers. This is unsafe because // if the buffer changes the string will change/be // invalid/not protected against re-use. But for // processing and disposing of single messages, one-at-at-time, // without re-using any part of a message (or making a copy of strings explicitly with copy() // if you must) then we can avoid all allocations for strings. UnsafeZeroCopy bool }
type Sizer ¶
type Sizer interface {
Msgsize() int
}
Sizer is an interface implemented by types that can estimate their size when MessagePack encoded. This interface is optional, but encoding/marshaling implementations may use this as a way to pre-allocate memory for serialization.
type Type ¶
type Type byte
Type is a MessagePack wire type, including this package's built-in extension types.
const ( InvalidType Type = iota StrType BinType MapType ArrayType Float64Type Float32Type BoolType IntType UintType NilType ExtensionType Complex64Type Complex128Type TimeType )
MessagePack Types
The zero value of Type is InvalidType.
type TypeError ¶
type TypeError struct { Method Type // Type expected by method Encoded Type // Type actually encoded }
A TypeError is returned when a particular decoding method is unsuitable for decoding a particular MessagePack value.
type UintOverflow ¶
type UintOverflow struct { Value uint64 // value of the uint FailedBitsize int // the bit size that couldn't fit the value }
UintOverflow is returned when a call would downcast an unsigned integer to a type with too few bits to hold its value
func (UintOverflow) Error ¶
func (u UintOverflow) Error() string
Error implements the error interface
func (UintOverflow) Resumable ¶
func (u UintOverflow) Resumable() bool
Resumable is always 'true' for overflows
type Unmarshaler ¶
Unmarshaler is the interface fulfilled by objects that know how to unmarshal themselves from MessagePack. UnmarshalMsg unmarshals the object from binary, returing any leftover bytes and any errors encountered.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is a buffered writer that can be used to write MessagePack objects to an io.Writer. You must call *Writer.Flush() in order to flush all of the buffered data to the underlying writer.
func NewWriterSize ¶
NewWriterSize returns a writer with a custom buffer size.
func (*Writer) WriteArrayHeader ¶
WriteArrayHeader writes an array header of the given size to the writer
func (*Writer) WriteBytes ¶
WriteBytes writes binary as 'bin' to the writer
func (*Writer) WriteBytesHeader ¶
WriteBytesHeader writes just the size header of a MessagePack 'bin' object. The user is responsible for then writing 'sz' more bytes into the stream.
func (*Writer) WriteComplex128 ¶
func (mw *Writer) WriteComplex128(f complex128) error
WriteComplex128 writes a complex128 to the writer
func (*Writer) WriteComplex64 ¶
WriteComplex64 writes a complex64 to the writer
func (*Writer) WriteExtension ¶
WriteExtension writes an extension type to the writer
func (*Writer) WriteFloat32 ¶
WriteFloat32 writes a float32 to the writer
func (*Writer) WriteFloat64 ¶
WriteFloat64 writes a float64 to the writer
func (*Writer) WriteInt16 ¶
WriteInt16 writes an int16 to the writer
func (*Writer) WriteInt32 ¶
WriteInt32 writes an int32 to the writer
func (*Writer) WriteInt64 ¶
WriteInt64 writes an int64 to the writer
func (*Writer) WriteIntf ¶
WriteIntf writes the concrete type of 'v'. WriteIntf will error if 'v' is not one of the following:
- A bool, float, string, []byte, int, uint, or complex
- A map of supported types (with string keys)
- An array or slice of supported types
- A pointer to a supported type
- A type that satisfies the msgp.Encodable interface
- A type that satisfies the msgp.Extension interface
func (*Writer) WriteMapHeader ¶
WriteMapHeader writes a map header of the given size to the writer
func (*Writer) WriteMapStrIntf ¶
WriteMapStrIntf writes a map[string]interface to the writer
func (*Writer) WriteMapStrStr ¶
WriteMapStrStr writes a map[string]string to the writer
func (*Writer) WriteString ¶
WriteString writes a messagepack string to the writer. (This is NOT an implementation of io.StringWriter)
func (*Writer) WriteStringFromBytes ¶
WriteStringFromBytes writes a 'str' object from a []byte.
func (*Writer) WriteStringHeader ¶
WriteStringHeader writes just the string size header of a MessagePack 'str' object. The user is responsible for writing 'sz' more valid UTF-8 bytes to the stream.
func (*Writer) WriteTime ¶
WriteTime writes a time.Time object to the wire.
Time is encoded as Unix time, which means that location (time zone) data is removed from the object. The encoded object itself is 12 bytes: 8 bytes for a big-endian 64-bit integer denoting seconds elapsed since "zero" Unix time, followed by 4 bytes for a big-endian 32-bit signed integer denoting the nanosecond offset of the time. This encoding is intended to ease portability across languages. (Note that this is *not* the standard time.Time binary encoding, because its implementation relies heavily on the internal representation used by the time package.)
func (*Writer) WriteUint16 ¶
WriteUint16 writes a uint16 to the writer
func (*Writer) WriteUint32 ¶
WriteUint32 writes a uint32 to the writer
func (*Writer) WriteUint64 ¶
WriteUint64 writes a uint64 to the writer
func (*Writer) WriteUint8 ¶
WriteUint8 writes a uint8 to the writer