Documentation
¶
Overview ¶
Package binary implements simple translation between numbers and byte sequences and encoding and decoding of varints.
Numbers are translated by reading and writing fixed-size values. A fixed-size value is either a fixed-size arithmetic type (bool, int8, uint8, int16, float32, complex64, ...) or an array or struct containing only fixed-size values.
Based on the encoding/binary package.
Index ¶
- type AppendByteOrder
- type BE
- func (BE) AppendUint16(b []byte, v uint16) []byte
- func (BE) AppendUint32(b []byte, v uint32) []byte
- func (BE) AppendUint64(b []byte, v uint64) []byte
- func (BE) PutUint16(b []byte, v uint16)
- func (BE) PutUint32(b []byte, v uint32)
- func (BE) PutUint64(b []byte, v uint64)
- func (BE) String() string
- func (BE) Uint16(b []byte) uint16
- func (BE) Uint32(b []byte) uint32
- func (BE) Uint64(b []byte) uint64
- type ByteOrder
- type LE
- func (LE) AppendUint16(b []byte, v uint16) []byte
- func (LE) AppendUint32(b []byte, v uint32) []byte
- func (LE) AppendUint64(b []byte, v uint64) []byte
- func (LE) PutUint16(b []byte, v uint16)
- func (LE) PutUint32(b []byte, v uint32)
- func (LE) PutUint64(b []byte, v uint64)
- func (LE) String() string
- func (LE) Uint16(b []byte) uint16
- func (LE) Uint32(b []byte) uint32
- func (LE) Uint64(b []byte) uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppendByteOrder ¶
type AppendByteOrder interface {
AppendUint16([]byte, uint16) []byte
AppendUint32([]byte, uint32) []byte
AppendUint64([]byte, uint64) []byte
String() string
}
AppendByteOrder specifies how to append 16-, 32-, or 64-bit unsigned integers into a byte slice.
It is implemented by LittleEndian, BigEndian, and [NativeEndian].
type BE ¶
type BE struct {
// contains filtered or unexported fields
}
var BigEndian BE
BigEndian is the big-endian implementation of ByteOrder and AppendByteOrder.
func (BE) AppendUint16 ¶
AppendUint16 appends the bytes of v to b and returns the appended slice. Requires at least 2 bytes of spare capacity in b.
func (BE) AppendUint32 ¶
AppendUint32 appends the bytes of v to b and returns the appended slice. Requires at least 4 bytes of spare capacity in b.
func (BE) AppendUint64 ¶
AppendUint64 appends the bytes of v to b and returns the appended slice. Requires at least 8 bytes of spare capacity in b.
type ByteOrder ¶
type ByteOrder interface {
Uint16([]byte) uint16
Uint32([]byte) uint32
Uint64([]byte) uint64
PutUint16([]byte, uint16)
PutUint32([]byte, uint32)
PutUint64([]byte, uint64)
String() string
}
A ByteOrder specifies how to convert byte slices into 16-, 32-, or 64-bit unsigned integers.
It is implemented by LittleEndian, BigEndian, and [NativeEndian].
type LE ¶
type LE struct {
// contains filtered or unexported fields
}
var LittleEndian LE
LittleEndian is the little-endian implementation of ByteOrder and AppendByteOrder.
func (LE) AppendUint16 ¶
AppendUint16 appends the bytes of v to b and returns the appended slice. Requires at least 2 bytes of spare capacity in b.
func (LE) AppendUint32 ¶
AppendUint32 appends the bytes of v to b and returns the appended slice. Requires at least 4 bytes of spare capacity in b.
func (LE) AppendUint64 ¶
AppendUint64 appends the bytes of v to b and returns the appended slice. Requires at least 8 bytes of spare capacity in b.