typed

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2016 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 ByteRef

type ByteRef []byte

A ByteRef is a reference to a byte in a bufffer

func (ByteRef) Update

func (ref ByteRef) Update(b byte)

Update updates the byte in the buffer

type BytesRef

type BytesRef []byte

A BytesRef is a reference to a multi-byte placeholder in a buffer

func (BytesRef) Update

func (ref BytesRef) Update(b []byte)

Update updates the bytes in the buffer

func (BytesRef) UpdateString

func (ref BytesRef) UpdateString(s string)

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) Err

func (r *ReadBuffer) Err() error

Err returns the error in the ReadBuffer

func (*ReadBuffer) FillFrom

func (r *ReadBuffer) FillFrom(ior io.Reader, n int) (int, error)

FillFrom fills the buffer from a reader

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

func NewReader(reader io.Reader) *Reader

NewReader returns a reader that reads typed values from the reader.

func (*Reader) Err added in v1.0.1

func (r *Reader) Err() error

Err returns any errors hit while reading from the underlying reader.

func (*Reader) ReadLen16String added in v1.0.1

func (r *Reader) ReadLen16String() string

ReadLen16String reads a uint16-length prefixed string.

func (*Reader) ReadString added in v1.0.1

func (r *Reader) ReadString(n int) string

ReadString reads a string of length n.

func (*Reader) ReadUint16 added in v1.0.1

func (r *Reader) ReadUint16() uint16

ReadUint16 reads a uint16.

func (*Reader) Release added in v1.0.1

func (r *Reader) Release()

Release puts the Reader back in the pool.

type Uint16Ref

type Uint16Ref []byte

A Uint16Ref is a reference to a uint16 placeholder in a buffer

func (Uint16Ref) Update

func (ref Uint16Ref) Update(n uint16)

Update updates the uint16 in the buffer

type Uint32Ref

type Uint32Ref []byte

A Uint32Ref is a reference to a uint32 placeholder in a buffer

func (Uint32Ref) Update

func (ref Uint32Ref) Update(n uint32)

Update updates the uint32 in the buffer

type Uint64Ref

type Uint64Ref []byte

A Uint64Ref is a reference to a uin64 placeholder in a buffer

func (Uint64Ref) Update

func (ref Uint64Ref) Update(n uint64)

Update updates the uint64 in the 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL