Documentation ¶
Index ¶
- Variables
- type ByteRef
- type BytesRef
- type ReadBuffer
- func (r *ReadBuffer) BytesRemaining() int
- func (r *ReadBuffer) Err() error
- func (r *ReadBuffer) FillFrom(ior io.Reader, n int) (int, error)
- func (r *ReadBuffer) ReadByte() (byte, error)
- func (r *ReadBuffer) ReadBytes(n int) []byte
- func (r *ReadBuffer) ReadLen16String() string
- func (r *ReadBuffer) ReadLen8String() string
- func (r *ReadBuffer) ReadSingleByte() byte
- func (r *ReadBuffer) ReadString(n int) string
- func (r *ReadBuffer) ReadUint16() uint16
- func (r *ReadBuffer) ReadUint32() uint32
- func (r *ReadBuffer) ReadUint64() uint64
- func (r *ReadBuffer) ReadUvarint() uint64
- func (r *ReadBuffer) Wrap(b []byte)
- type Reader
- type Uint16Ref
- type Uint32Ref
- type Uint64Ref
- type WriteBuffer
- func (w *WriteBuffer) BytesRemaining() int
- func (w *WriteBuffer) BytesWritten() int
- func (w *WriteBuffer) DeferByte() ByteRef
- func (w *WriteBuffer) DeferBytes(n int) BytesRef
- func (w *WriteBuffer) DeferUint16() Uint16Ref
- func (w *WriteBuffer) DeferUint32() Uint32Ref
- func (w *WriteBuffer) DeferUint64() Uint64Ref
- func (w *WriteBuffer) Err() error
- func (w *WriteBuffer) FlushTo(iow io.Writer) (int, error)
- func (w *WriteBuffer) Reset()
- func (w *WriteBuffer) Wrap(b []byte)
- func (w *WriteBuffer) WriteBytes(in []byte)
- func (w *WriteBuffer) WriteLen16String(s string)
- func (w *WriteBuffer) WriteLen8String(s string)
- func (w *WriteBuffer) WriteSingleByte(n byte)
- func (w *WriteBuffer) WriteString(s string)
- func (w *WriteBuffer) WriteUint16(n uint16)
- func (w *WriteBuffer) WriteUint32(n uint32)
- func (w *WriteBuffer) WriteUint64(n uint64)
- func (w *WriteBuffer) WriteUvarint(n uint64)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEOF is returned when trying to read past end of buffer ErrEOF = errors.New("buffer is too small") // ErrBufferFull is returned when trying to write past end of buffer ErrBufferFull = errors.New("no more room in buffer") )
Functions ¶
This section is empty.
Types ¶
type BytesRef ¶
type BytesRef []byte
A BytesRef is a reference to a multi-byte placeholder in a buffer
func (BytesRef) UpdateString ¶
UpdateString updates the bytes in the buffer from a string
type ReadBuffer ¶
type ReadBuffer struct {
// contains filtered or unexported fields
}
A ReadBuffer is a wrapper around an underlying []byte with methods to read from that buffer in big-endian format.
func NewReadBuffer ¶
func NewReadBuffer(buffer []byte) *ReadBuffer
NewReadBuffer returns a ReadBuffer wrapping a byte slice
func NewReadBufferWithSize ¶
func NewReadBufferWithSize(size int) *ReadBuffer
NewReadBufferWithSize returns a ReadBuffer with a given capacity
func (*ReadBuffer) BytesRemaining ¶
func (r *ReadBuffer) BytesRemaining() int
BytesRemaining returns the number of unconsumed bytes remaining in the buffer
func (*ReadBuffer) ReadByte ¶
func (r *ReadBuffer) ReadByte() (byte, error)
ReadByte returns the next byte from the buffer.
func (*ReadBuffer) ReadBytes ¶
func (r *ReadBuffer) ReadBytes(n int) []byte
ReadBytes returns the next n bytes from the buffer
func (*ReadBuffer) ReadLen16String ¶
func (r *ReadBuffer) ReadLen16String() string
ReadLen16String reads a 16-bit length preceded string value
func (*ReadBuffer) ReadLen8String ¶
func (r *ReadBuffer) ReadLen8String() string
ReadLen8String reads an 8-bit length preceded string value
func (*ReadBuffer) ReadSingleByte ¶
func (r *ReadBuffer) ReadSingleByte() byte
ReadSingleByte reads the next byte from the buffer
func (*ReadBuffer) ReadString ¶
func (r *ReadBuffer) ReadString(n int) string
ReadString returns a string of size n from the buffer
func (*ReadBuffer) ReadUint16 ¶
func (r *ReadBuffer) ReadUint16() uint16
ReadUint16 returns the next value in the buffer as a uint16
func (*ReadBuffer) ReadUint32 ¶
func (r *ReadBuffer) ReadUint32() uint32
ReadUint32 returns the next value in the buffer as a uint32
func (*ReadBuffer) ReadUint64 ¶
func (r *ReadBuffer) ReadUint64() uint64
ReadUint64 returns the next value in the buffer as a uint64
func (*ReadBuffer) ReadUvarint ¶
func (r *ReadBuffer) ReadUvarint() uint64
ReadUvarint reads an unsigned varint from the buffer.
func (*ReadBuffer) Wrap ¶
func (r *ReadBuffer) Wrap(b []byte)
Wrap initializes the buffer to read from the given byte slice
type Reader ¶ added in v1.0.1
type Reader struct {
// contains filtered or unexported fields
}
Reader is a reader that reads typed values from an io.Reader.
func NewReader ¶ added in v1.0.1
NewReader returns a reader that reads typed values from the reader.
func (*Reader) Err ¶ added in v1.0.1
Err returns any errors hit while reading from the underlying reader.
func (*Reader) ReadLen16String ¶ added in v1.0.1
ReadLen16String reads a uint16-length prefixed string.
func (*Reader) ReadString ¶ added in v1.0.1
ReadString reads a string of length n.
func (*Reader) ReadUint16 ¶ added in v1.0.1
ReadUint16 reads a uint16.
type Uint16Ref ¶
type Uint16Ref []byte
A Uint16Ref is a reference to a uint16 placeholder in a buffer
type Uint32Ref ¶
type Uint32Ref []byte
A Uint32Ref is a reference to a uint32 placeholder in a buffer
type Uint64Ref ¶
type Uint64Ref []byte
A Uint64Ref is a reference to a uin64 placeholder in a buffer
type WriteBuffer ¶
type WriteBuffer struct {
// contains filtered or unexported fields
}
A WriteBuffer is a wrapper around an underlying []byte with methods to write to that buffer in big-endian format. The buffer is of fixed size, and does not grow.
func NewWriteBuffer ¶
func NewWriteBuffer(buffer []byte) *WriteBuffer
NewWriteBuffer creates a WriteBuffer wrapping the given slice
func NewWriteBufferWithSize ¶
func NewWriteBufferWithSize(size int) *WriteBuffer
NewWriteBufferWithSize create a new WriteBuffer using an internal buffer of the given size
func (*WriteBuffer) BytesRemaining ¶
func (w *WriteBuffer) BytesRemaining() int
BytesRemaining returns the number of available bytes remaining in the bufffer
func (*WriteBuffer) BytesWritten ¶
func (w *WriteBuffer) BytesWritten() int
BytesWritten returns the number of bytes that have been written to the buffer
func (*WriteBuffer) DeferByte ¶
func (w *WriteBuffer) DeferByte() ByteRef
DeferByte reserves space in the buffer for a single byte, and returns a reference that can be used to update that byte later
func (*WriteBuffer) DeferBytes ¶
func (w *WriteBuffer) DeferBytes(n int) BytesRef
DeferBytes reserves space in the buffer for a fixed sequence of bytes, and returns a reference that can be used to update those bytes
func (*WriteBuffer) DeferUint16 ¶
func (w *WriteBuffer) DeferUint16() Uint16Ref
DeferUint16 reserves space in the buffer for a uint16, and returns a reference that can be used to update that uint16
func (*WriteBuffer) DeferUint32 ¶
func (w *WriteBuffer) DeferUint32() Uint32Ref
DeferUint32 reserves space in the buffer for a uint32, and returns a reference that can be used to update that uint32
func (*WriteBuffer) DeferUint64 ¶
func (w *WriteBuffer) DeferUint64() Uint64Ref
DeferUint64 reserves space in the buffer for a uint64, and returns a reference that can be used to update that uint64
func (*WriteBuffer) Err ¶
func (w *WriteBuffer) Err() error
Err returns the current error in the buffer
func (*WriteBuffer) FlushTo ¶
func (w *WriteBuffer) FlushTo(iow io.Writer) (int, error)
FlushTo flushes the written buffer to the given writer
func (*WriteBuffer) Reset ¶
func (w *WriteBuffer) Reset()
Reset resets the buffer to an empty state, ready for writing
func (*WriteBuffer) Wrap ¶
func (w *WriteBuffer) Wrap(b []byte)
Wrap initializes the buffer to wrap the given byte slice
func (*WriteBuffer) WriteBytes ¶
func (w *WriteBuffer) WriteBytes(in []byte)
WriteBytes writes a slice of bytes to the buffer
func (*WriteBuffer) WriteLen16String ¶
func (w *WriteBuffer) WriteLen16String(s string)
WriteLen16String writes a 16-bit length preceded string
func (*WriteBuffer) WriteLen8String ¶
func (w *WriteBuffer) WriteLen8String(s string)
WriteLen8String writes an 8-bit length preceded string
func (*WriteBuffer) WriteSingleByte ¶
func (w *WriteBuffer) WriteSingleByte(n byte)
WriteSingleByte writes a single byte to the buffer
func (*WriteBuffer) WriteString ¶
func (w *WriteBuffer) WriteString(s string)
WriteString writes a string to the buffer
func (*WriteBuffer) WriteUint16 ¶
func (w *WriteBuffer) WriteUint16(n uint16)
WriteUint16 writes a big endian encoded uint16 value to the buffer
func (*WriteBuffer) WriteUint32 ¶
func (w *WriteBuffer) WriteUint32(n uint32)
WriteUint32 writes a big endian uint32 value to the buffer
func (*WriteBuffer) WriteUint64 ¶
func (w *WriteBuffer) WriteUint64(n uint64)
WriteUint64 writes a big endian uint64 to the buffer
func (*WriteBuffer) WriteUvarint ¶
func (w *WriteBuffer) WriteUvarint(n uint64)
WriteUvarint writes an unsigned varint to the buffer