Documentation ¶
Overview ¶
Package bin provides support for encoding and decoding binary data.
Example ¶
var b bytes.Buffer e := NewEncoder(&b) e.Uint64(42) data := b.Bytes() r := NewDecoder(data) fmt.Println(r.Uint64())
Output: 42
Index ¶
- type Decoder
- func (r *Decoder) Array() []byte
- func (r *Decoder) Array16() []byte
- func (r *Decoder) Bytes(n int) []byte
- func (r Decoder) RemainingBytes() int
- func (r *Decoder) Uint16() uint16
- func (r *Decoder) Uint32() uint32
- func (r *Decoder) Uint64() uint64
- func (r *Decoder) Uint8() uint8
- func (r *Decoder) VarInt() uint64
- type Encoder
- func (r *Encoder) Array(data []byte)
- func (w *Encoder) Array16(b []byte)
- func (w *Encoder) Bytes(b []byte)
- func (w Encoder) BytesWritten() int
- func (w *Encoder) Uint16(v uint16)
- func (w *Encoder) Uint32(v uint32)
- func (w *Encoder) Uint64(v uint64)
- func (w *Encoder) Uint8(b uint8)
- func (r *Encoder) VarInt(u uint64)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder streams binary data from a byte buffer.
Example ¶
r := NewDecoder([]byte{0x34, 0x1c, 0, 0}) fmt.Printf("%#x", r.Uint32())
Output: 0x1c34
func NewDecoder ¶
NewDecoder creates a decoder that parses data from buffer b.
Retains b, which the caller should not use afterward.
func (Decoder) RemainingBytes ¶
RemainingBytes gives the number of bytes remaining in the buffer.
func (*Decoder) VarInt ¶
VarInt parses a varint
See the protocol-buffer documentation for the encoding format: https://developers.google.com/protocol-buffers/docs/encoding#varints.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes values to an output stream.
Example ¶
var b bytes.Buffer e := NewEncoder(&b) e.Uint32(0x1c34) fmt.Println(b.Bytes())
Output: [52 28 0 0]
func NewEncoder ¶
NewEncoder creates an encoder that writes data to w.
func (Encoder) BytesWritten ¶
BytesWritten returns the number of bytes written to the encoder since this encoder was created.