Documentation ¶
Index ¶
- Variables
- func PutUint16(buf []byte, offset int, value uint16)
- func PutUint32(buf []byte, offset int, value uint32)
- func PutUint64(buf []byte, offset int, value uint64)
- func PutUvariantLittleEndian(buf []byte, x uint64) int
- func ReadUint16(buf []byte, offset int) uint16
- func ReadUint32(buf []byte, offset int) uint32
- func ReadUint64(buf []byte, offset int) uint64
- func ReadUvarint(buf []byte, offset int) (value uint64, readLen int, err error)
- func UvariantSize(value uint64) int
- func UvarintLittleEndian(buf []byte) (x uint64, s int)
- func VariantSize(value int64) int
- type BufferWriter
- func (bw *BufferWriter) Bytes() ([]byte, error)
- func (bw *BufferWriter) Error() error
- func (w *BufferWriter) Len() int
- func (w *BufferWriter) PutByte(v byte)
- func (w *BufferWriter) PutBytes(v []byte)
- func (w *BufferWriter) PutInt16(v int16)
- func (w *BufferWriter) PutInt32(v int32)
- func (w *BufferWriter) PutInt64(v int64)
- func (w *BufferWriter) PutUInt16(v uint16)
- func (w *BufferWriter) PutUint32(v uint32)
- func (w *BufferWriter) PutUint64(v uint64)
- func (w *BufferWriter) PutUvarint32(v uint32)
- func (w *BufferWriter) PutUvarint64(v uint64)
- func (w *BufferWriter) PutVarint32(v int32)
- func (w *BufferWriter) PutVarint64(v int64)
- func (bw *BufferWriter) Reset()
- func (bw *BufferWriter) SwitchBuffer(newBuffer *bytes.Buffer)
- func (w *BufferWriter) Write(p []byte) (n int, err error)
- type Reader
- func (r *Reader) Empty() bool
- func (r *Reader) Error() error
- func (r *Reader) Position() int
- func (r *Reader) ReadAt(pos int)
- func (r *Reader) ReadByte() byte
- func (r *Reader) ReadBytes(n int) []byte
- func (r *Reader) ReadInt16() int16
- func (r *Reader) ReadInt32() int32
- func (r *Reader) ReadInt64() int64
- func (r *Reader) ReadSlice(n int) []byte
- func (r *Reader) ReadUint16() uint16
- func (r *Reader) ReadUint32() uint32
- func (r *Reader) ReadUint64() uint64
- func (r *Reader) ReadUntil(c byte) []byte
- func (r *Reader) ReadUvarint32() uint32
- func (r *Reader) ReadUvarint64() uint64
- func (r *Reader) ReadVarint32() int32
- func (r *Reader) ReadVarint64() int64
- func (r *Reader) Reset(buf []byte)
- func (r *Reader) SeekStart()
- func (r *Reader) UnreadSlice() []byte
- type SliceWriter
- func (sw *SliceWriter) Bytes() ([]byte, error)
- func (sw *SliceWriter) Error() error
- func (w *SliceWriter) Len() int
- func (w *SliceWriter) PutByte(v byte)
- func (w *SliceWriter) PutBytes(v []byte)
- func (w *SliceWriter) PutInt16(v int16)
- func (w *SliceWriter) PutInt32(v int32)
- func (w *SliceWriter) PutInt64(v int64)
- func (w *SliceWriter) PutUInt16(v uint16)
- func (w *SliceWriter) PutUint32(v uint32)
- func (w *SliceWriter) PutUint64(v uint64)
- func (w *SliceWriter) PutUvarint32(v uint32)
- func (w *SliceWriter) PutUvarint64(v uint64)
- func (w *SliceWriter) PutVarint32(v int32)
- func (w *SliceWriter) PutVarint64(v int64)
- func (w *SliceWriter) Write(p []byte) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
var ErrUnexpectedRead = fmt.Errorf("unexpected read")
ErrUnexpectedRead is raised when reading negative length
Functions ¶
func PutUvariantLittleEndian ¶
PutUvariantLittleEndian encodes a uint64 into buf and returns the number of bytes written. The default PutUvarint use big-endian
func ReadUint16 ¶
ReadUint16 reads 2 bytes from buf as uint16
func ReadUint32 ¶
ReadUint32 reads 4 bytes from buf as uint32
func ReadUint64 ¶
ReadUint64 reads 8 bytes from buf as uint64
func ReadUvarint ¶
ReadUvarint reads an encoded unsigned integer from bytes.Reader and returns it as a uint64.
func UvariantSize ¶
UvariantSize returns the bytes-size of a uint64 uvariant encoded number.
func UvarintLittleEndian ¶
UvarintLittleEndian decodes a uint64 from buf's tail with little endian and returns that value and the number of bytes read (> 0). If an error occurred, the value is 0 and the number of bytes n is <= 0 meaning:
n == 0: buf too small n < 0: value larger than 64 bits (overflow) and -n is the number of bytes read
func VariantSize ¶
VariantSize returns the bytes-size of a int64 variant encoded number.
Types ¶
type BufferWriter ¶
type BufferWriter struct {
// contains filtered or unexported fields
}
BufferWriter is a writer for writing data into a buffer
func NewBufferWriter ¶
func NewBufferWriter(buffer *bytes.Buffer) *BufferWriter
NewBufferWriter creates a binary stream for writing with provided buffer(append write).
func (*BufferWriter) Bytes ¶
func (bw *BufferWriter) Bytes() ([]byte, error)
Bytes returns memory buffer data, if error return err
func (*BufferWriter) Error ¶
func (bw *BufferWriter) Error() error
Error returns the error of BufferWriter
func (*BufferWriter) Len ¶
func (w *BufferWriter) Len() int
Len returns the size of bytes of the written data of the buffer;
func (*BufferWriter) PutByte ¶
func (w *BufferWriter) PutByte(v byte)
PutByte encodes a byte into buf
func (*BufferWriter) PutBytes ¶
func (w *BufferWriter) PutBytes(v []byte)
PutBytes encodes bytes into buf
func (*BufferWriter) PutInt16 ¶
func (w *BufferWriter) PutInt16(v int16)
PutInt16 encodes a int16 as 2 bytes into buf
func (*BufferWriter) PutInt32 ¶
func (w *BufferWriter) PutInt32(v int32)
PutInt32 encodes a int32 as 4 bytes into buf
func (*BufferWriter) PutInt64 ¶
func (w *BufferWriter) PutInt64(v int64)
PutInt64 encodes a int64 as 8 bytes into buf
func (*BufferWriter) PutUInt16 ¶
func (w *BufferWriter) PutUInt16(v uint16)
PutUInt16 encodes a uint16 as 2 bytes into buf
func (*BufferWriter) PutUint32 ¶
func (w *BufferWriter) PutUint32(v uint32)
PutUint32 encodes a uint32 as 4 bytes into buf
func (*BufferWriter) PutUint64 ¶
func (w *BufferWriter) PutUint64(v uint64)
PutUint64 encodes a uint64 as 8 bytes into buf
func (*BufferWriter) PutUvarint32 ¶
func (w *BufferWriter) PutUvarint32(v uint32)
PutUvarint32 encodes a uint32 into buf
func (*BufferWriter) PutUvarint64 ¶
func (w *BufferWriter) PutUvarint64(v uint64)
PutUvarint64 encodes a uint64 into buf
func (*BufferWriter) PutVarint32 ¶
func (w *BufferWriter) PutVarint32(v int32)
PutVarint32 encodes a int32 into buf
func (*BufferWriter) PutVarint64 ¶
func (w *BufferWriter) PutVarint64(v int64)
PutVarint64 encodes a int64 into buf
func (*BufferWriter) SwitchBuffer ¶
func (bw *BufferWriter) SwitchBuffer(newBuffer *bytes.Buffer)
SwitchBuffer switches to write a new buffer
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is a stream reader
func (*Reader) ReadAt ¶
ReadAt moves the cursor to the specified position, this operation is a combination of SeekStart() + _ = ReadSlice(pos)
func (*Reader) ReadSlice ¶
ReadSlice returns a sub-slice. make sure that the sub-slice is not in use before calling Reset.
func (*Reader) ReadUint16 ¶
ReadUint16 reads 2 bytes from buf as uint16
func (*Reader) ReadUint32 ¶
ReadUint32 reads 4 bytes from buf as uint32
func (*Reader) ReadUint64 ¶
ReadUint64 reads 8 bytes from buf as uint64
func (*Reader) ReadUvarint32 ¶
ReadUvarint32 reads uint32 from buffer
func (*Reader) ReadUvarint64 ¶
ReadUvarint64 reads uint64 from buffer
func (*Reader) ReadVarint32 ¶
ReadVarint32 reads int32 from buffer
func (*Reader) ReadVarint64 ¶
ReadVarint64 reads int64 from buffer
func (*Reader) SeekStart ¶
func (r *Reader) SeekStart()
SeekStart seeks to the start of the underlying slice.
func (*Reader) UnreadSlice ¶
UnreadSlice returns the unread sub-slice
type SliceWriter ¶
type SliceWriter struct {
// contains filtered or unexported fields
}
SliceWriter is a writer for writing data into a slice
func NewSliceWriter ¶
func NewSliceWriter(buffer []byte) *SliceWriter
NewSliceWriter creates a binary stream for writing with provided slice(writing start from offset 0). The caller is responsible to make sure the wrote bytes do not exceed the buffer size, otherwise the exceeding data will be missing. and if it is a large buf, buffer grow will cause a expensive reallocation
func (*SliceWriter) Bytes ¶
func (sw *SliceWriter) Bytes() ([]byte, error)
Bytes returns memory buffer data, if error return err
func (*SliceWriter) Error ¶
func (sw *SliceWriter) Error() error
Error returns the error of BufferWriter
func (*SliceWriter) Len ¶
func (w *SliceWriter) Len() int
Len returns the size of bytes of the written data of the buffer;
func (*SliceWriter) PutBytes ¶
func (w *SliceWriter) PutBytes(v []byte)
PutBytes encodes bytes into buf
func (*SliceWriter) PutInt16 ¶
func (w *SliceWriter) PutInt16(v int16)
PutInt16 encodes a int16 as 2 bytes into buf
func (*SliceWriter) PutInt32 ¶
func (w *SliceWriter) PutInt32(v int32)
PutInt32 encodes a int32 as 4 bytes into buf
func (*SliceWriter) PutInt64 ¶
func (w *SliceWriter) PutInt64(v int64)
PutInt64 encodes a int64 as 8 bytes into buf
func (*SliceWriter) PutUInt16 ¶
func (w *SliceWriter) PutUInt16(v uint16)
PutUInt16 encodes a uint16 as 2 bytes into buf
func (*SliceWriter) PutUint32 ¶
func (w *SliceWriter) PutUint32(v uint32)
PutUint32 encodes a uint32 as 4 bytes into buf
func (*SliceWriter) PutUint64 ¶
func (w *SliceWriter) PutUint64(v uint64)
PutUint64 encodes a uint64 as 8 bytes into buf
func (*SliceWriter) PutUvarint32 ¶
func (w *SliceWriter) PutUvarint32(v uint32)
PutUvarint32 encodes a uint32 into buf
func (*SliceWriter) PutUvarint64 ¶
func (w *SliceWriter) PutUvarint64(v uint64)
PutUvarint64 encodes a uint64 into buf
func (*SliceWriter) PutVarint32 ¶
func (w *SliceWriter) PutVarint32(v int32)
PutVarint32 encodes a int32 into buf
func (*SliceWriter) PutVarint64 ¶
func (w *SliceWriter) PutVarint64(v int64)
PutVarint64 encodes a int64 into buf