Documentation ¶
Index ¶
- Constants
- Variables
- func Marshal(v interface{}) ([]byte, error)
- func Unmarshal(b []byte, v interface{}) error
- type Decoder
- func (dec *Decoder) Decode(v interface{}) (err error)
- func (dec *Decoder) Read(p []byte) (int, error)
- func (dec *Decoder) ReadBinary(v encoding.BinaryUnmarshaler) error
- func (dec *Decoder) ReadBool() (bool, error)
- func (dec *Decoder) ReadBytes() ([]byte, error)
- func (dec *Decoder) ReadComplex128() (complex128, error)
- func (dec *Decoder) ReadComplex64() (complex64, error)
- func (dec *Decoder) ReadFloat32() (float32, error)
- func (dec *Decoder) ReadFloat64() (float64, error)
- func (dec *Decoder) ReadGob(v gob.GobDecoder) error
- func (dec *Decoder) ReadInt() (int64, uint8, error)
- func (dec *Decoder) ReadInt16() (int16, error)
- func (dec *Decoder) ReadInt32() (int32, error)
- func (dec *Decoder) ReadInt64() (int64, error)
- func (dec *Decoder) ReadInt8() (int8, error)
- func (dec *Decoder) ReadString() (string, error)
- func (dec *Decoder) ReadUint() (v uint64, sz uint8, err error)
- func (dec *Decoder) ReadUint16() (uint16, error)
- func (dec *Decoder) ReadUint32() (uint32, error)
- func (dec *Decoder) ReadUint64() (uint64, error)
- func (dec *Decoder) ReadUint8() (uint8, error)
- func (dec *Decoder) ReadVarInt() (int64, error)
- func (dec *Decoder) ReadVarUint() (uint64, error)
- func (dec *Decoder) Reset(r io.Reader)
- type DecoderTypeError
- type Encoder
- func (enc *Encoder) Encode(v interface{}) (err error)
- func (enc *Encoder) Flush() error
- func (enc *Encoder) Reset(w io.Writer)
- func (enc *Encoder) Write(p []byte) (n int, err error)
- func (enc *Encoder) WriteBinary(v encoding.BinaryMarshaler) error
- func (enc *Encoder) WriteBool(v bool) error
- func (enc *Encoder) WriteByte(v byte) (err error)
- func (enc *Encoder) WriteBytes(v []byte) error
- func (enc *Encoder) WriteComplex128(v complex128) error
- func (enc *Encoder) WriteComplex64(v complex64) error
- func (enc *Encoder) WriteFloat32(v float32) error
- func (enc *Encoder) WriteFloat64(v float64) error
- func (enc *Encoder) WriteGob(v gob.GobEncoder) error
- func (enc *Encoder) WriteInt(v int64) error
- func (enc *Encoder) WriteInt16(v int16) error
- func (enc *Encoder) WriteInt32(v int32) error
- func (enc *Encoder) WriteInt64(v int64) error
- func (enc *Encoder) WriteInt8(v int8) (err error)
- func (enc *Encoder) WriteString(v string) error
- func (enc *Encoder) WriteUint(v uint64) error
- func (enc *Encoder) WriteUint16(v uint16) error
- func (enc *Encoder) WriteUint32(v uint32) error
- func (enc *Encoder) WriteUint64(v uint64) error
- func (enc *Encoder) WriteUint8(v uint8) (err error)
- func (enc *Encoder) WriteVarInt(x int64) error
- func (enc *Encoder) WriteVarUint(x uint64) error
- type Marshaler
- type Type
- type Unmarshaler
Constants ¶
const DefaultDecoderBufferSize = 4096
const DefaultEncoderBufferSize = 4096
Variables ¶
var ( // ErrNoPointer gets returned if the user passes a non-pointer to Decode ErrNoPointer = errors.New("can't decode to a non-pointer") )
var (
ErrUnsupportedType = errors.New("unsupported encoding type")
)
Functions ¶
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads binary data from an input stream, it also does a little bit of buffering.
func NewDecoder ¶
NewDecoder is an alias for NewDecoder(r, DefaultDecoderBufferSize)
func NewDecoderSize ¶
NewDecoder returns a new decoder that reads from r with specific buffer size.
The decoder introduces its own buffering and may read data from r beyond the requested values.
func (*Decoder) Decode ¶
Decode reads the next binny-encoded value from its input and stores it in the value pointed to by v.
func (*Decoder) Read ¶
Read allows the Decoder to be used as an io.Reader, note that internally this calls io.ReadFull().
func (*Decoder) ReadBinary ¶
func (dec *Decoder) ReadBinary(v encoding.BinaryUnmarshaler) error
ReadBinary decodes and reads an object that implements the `encoding.BinaryUnmarshaler` interface.
func (*Decoder) ReadComplex128 ¶
func (dec *Decoder) ReadComplex128() (complex128, error)
ReadComplex128 returns a complex128 or an error.
func (*Decoder) ReadComplex64 ¶
ReadComplex64 returns a complex64 or an error.
func (*Decoder) ReadFloat32 ¶
ReadFloat32 returns a float32 or an error.
func (*Decoder) ReadFloat64 ¶
ReadFloat64 returns a float64 or an error.
func (*Decoder) ReadGob ¶
func (dec *Decoder) ReadGob(v gob.GobDecoder) error
ReadGob decodes and reads an object that implements the `gob.GobDecoder` interface.
func (*Decoder) ReadInt ¶
ReadInt retruns an int/varint value and the size of it (8, 16, 32, 64) or an error.
func (*Decoder) ReadString ¶
ReadBytes returns a string.
func (*Decoder) ReadUint ¶
ReadUint retruns an uint/varuint value and the size of it (8, 16, 32, 64) or an error.
func (*Decoder) ReadUint16 ¶
func (*Decoder) ReadUint32 ¶
func (*Decoder) ReadUint64 ¶
func (*Decoder) ReadVarInt ¶
func (*Decoder) ReadVarUint ¶
type DecoderTypeError ¶
func (DecoderTypeError) Error ¶
func (dte DecoderTypeError) Error() string
type Encoder ¶
type Encoder struct { NoAutoFlushOnEncode bool // Do not auto flush after calling .Encode. // contains filtered or unexported fields }
func NewEncoder ¶
NewEncoder returns a new encoder with the DefaultEncoderBufferSize
func NewEncoderSize ¶
NewEncoder returns a new encoder with the specific buffer size, minimum is 24 bytes.
func (*Encoder) Reset ¶
Reset discards any unflushed buffered data, clears any error, and resets b to write its output to w.
func (*Encoder) Write ¶
Write writes the contents of p into the buffer. It allows the Encoder to be used as a regular io.Writer since it takes control of the original w.
func (*Encoder) WriteBinary ¶
func (enc *Encoder) WriteBinary(v encoding.BinaryMarshaler) error
func (*Encoder) WriteBytes ¶
func (*Encoder) WriteComplex128 ¶
func (enc *Encoder) WriteComplex128(v complex128) error
func (*Encoder) WriteComplex64 ¶
func (*Encoder) WriteFloat32 ¶
func (*Encoder) WriteFloat64 ¶
func (*Encoder) WriteInt16 ¶
func (*Encoder) WriteInt32 ¶
func (*Encoder) WriteInt64 ¶
func (*Encoder) WriteString ¶
func (*Encoder) WriteUint16 ¶
func (*Encoder) WriteUint32 ¶
func (*Encoder) WriteUint64 ¶
func (*Encoder) WriteUint8 ¶
func (*Encoder) WriteVarInt ¶
func (*Encoder) WriteVarUint ¶
type Marshaler ¶
Marshaler is the interface implemented by objects that can marshal themselves into a binary representation. Implementing this bypasses reflection and is generally faster but not nessecery optimized.
type Type ¶
type Type byte
Type represents the field type
const ( Nil Type = iota // nil/empty type BoolTrue // true BoolFalse // false EmptyStruct // struct{} VarInt // Varint 1-10 bytes Int8 // Int16 // Int32 // Int64 // VarUint // VarUint 1-10 bytes Uint8 // Uint16 // Uint32 // Uint64 // Float32 // Float64 // Complex64 // Complex128 // String // ByteSlice // []byte Struct // Map // Slice // or array Interface // interface{} Binary // encoding BinaryMarshaler/BinaryUnmarshaler Gob // encoding/gob GobEncoder/GobDecoder EOV = ^Nil // end-of-value, *any* new types must be added before this line. )
type Unmarshaler ¶
Unmarshaler is the interface implemented by objects that can unmarshal a binary representation of themselves. Implementing this bypasses reflection and is generally faster.