bytebuffer

package module
Version: v0.0.0-...-f1bbd17 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2013 License: Apache-2.0 Imports: 5 Imported by: 35

README

bytebuffer

Go implementation of the Java ByteBuffer

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteBuffer

type ByteBuffer struct {
	// contains filtered or unexported fields
}

A buffer is a linear, finite sequence of elements of a specific primitive type. The following invariant holds for the mark, position, limit, and capacity values:

0 <= mark <= position <= limit <= capacity

A newly-created buffer always has a position of zero and a mark that is undefined. The initial limit may be zero, or it may be some other value that depends upon the type of the buffer and the manner in which it is constructed. Each element of a newly-allocated buffer is initialized to zero.

func NewByteBuffer

func NewByteBuffer(size int) *ByteBuffer

func NewWrappedBuffer

func NewWrappedBuffer(buf []byte, size int) *ByteBuffer

func (*ByteBuffer) AsInt32Buffer

func (this *ByteBuffer) AsInt32Buffer() *Int32Buffer

AsInt32Buffer creates a view of this byte buffer as an uint32 buffer.

The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.

The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by four, and its mark will be undefined. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.

func (*ByteBuffer) AsReadOnlyBuffer

func (this *ByteBuffer) AsReadOnlyBuffer() *ByteBuffer

AsReadOnlyBuffer creates a new, read-only byte buffer that shares this buffer's content. The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer; the new buffer itself, however, will be read-only and will not allow the shared content to be modified. The two buffers' position, limit, and mark values will be independent.

The new buffer's capacity, limit, position, and mark values will be identical to those of this buffer.

If this buffer is itself read-only then this method behaves in exactly the same way as the duplicate method.

func (*ByteBuffer) AsUint32Buffer

func (this *ByteBuffer) AsUint32Buffer() *Uint32Buffer

AsUint32Buffer creates a view of this byte buffer as an uint32 buffer.

The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.

The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by four, and its mark will be undefined. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.

func (*ByteBuffer) Capacity

func (this *ByteBuffer) Capacity() int

Returns this buffer's capacity.

func (*ByteBuffer) Clear

func (this *ByteBuffer) Clear() error

Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded.

func (*ByteBuffer) Copy

func (this *ByteBuffer) Copy(b *ByteBuffer) error

func (*ByteBuffer) Duplicate

func (this *ByteBuffer) Duplicate() *ByteBuffer

Duplicate creates a new byte buffer that shares this buffer's content.

The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.

The new buffer's capacity, limit, position, and mark values will be identical to those of this buffer. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.

func (*ByteBuffer) Equals

func (this *ByteBuffer) Equals(other *ByteBuffer) bool

Equals tells whether or not this buffer is equal to another buffer

func (*ByteBuffer) Flip

func (this *ByteBuffer) Flip() error

Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.

func (*ByteBuffer) Get

func (this *ByteBuffer) Get() (byte, error)

Get is a relative get method. Reads the byte at this buffer's current position, and then increments the position.

func (*ByteBuffer) GetAsInt32

func (this *ByteBuffer) GetAsInt32() (int32, error)

GetAsInt32 is the same as Get() except it converts byte to int32 in the return This is mainly a convenience method

func (*ByteBuffer) GetAsUint32

func (this *ByteBuffer) GetAsUint32() (uint32, error)

GetAsUint32 is the same as Get() except it converts byte to uint32 in the return This is mainly a convenience method

func (*ByteBuffer) GetAt

func (this *ByteBuffer) GetAt(index int) (byte, error)

GetAt is an absolute get method. Reads the byte at the given index.

func (*ByteBuffer) GetBytes

func (this *ByteBuffer) GetBytes(dst []byte, offset, length int) error

GetBytes is a relative bulk get method.

This method transfers bytes from this buffer into the given destination array. If there are fewer bytes remaining in the buffer than are required to satisfy the request, that is, if length > remaining(), then no bytes are transferred and a BufferUnderflowException is thrown.

Otherwise, this method copies length bytes from this buffer into the given array, starting at the current position of this buffer and at the given offset in the array. The position of this buffer is then incremented by length.

dst - The array into which bytes are to be written offset - The offset within the array of the first byte to be written; must be non-negative and no larger

than dst.length

length - The maximum number of bytes to be written to the given array; must be non-negative and no larger

than dst.length - offset

func (*ByteBuffer) GetUint16

func (this *ByteBuffer) GetUint16() (uint16, error)

GetUint16 is a relative get method for reading a short value. Reads the next two bytes at this buffer's current position, composing them into a short value according to the current byte order, and then increments the position by two.

func (*ByteBuffer) GetUint16At

func (this *ByteBuffer) GetUint16At(index int) (uint16, error)

GetUint16At is an absolute get method for reading a short value. Reads two bytes at the given index, composing them into a short value according to the current byte order.

func (*ByteBuffer) GetUint32

func (this *ByteBuffer) GetUint32() (uint32, error)

GetUint32 is a relative get method for reading a uint32 value. Reads the next four bytes at this buffer's current position, composing them into a uint32 value according to the current byte order, and then increments the position by two.

func (*ByteBuffer) GetUint32At

func (this *ByteBuffer) GetUint32At(index int) (uint32, error)

GetUint16At is an absolute get method for reading a uint32 value. Reads four bytes at the given index, composing them into a uint32 value according to the current byte order.

func (*ByteBuffer) GetUint64

func (this *ByteBuffer) GetUint64() (uint64, error)

GetUint64 is a relative get method for reading a uint64 value. Reads the next eight bytes at this buffer's current position, composing them into a uint64 value according to the current byte order, and then increments the position by two.

func (*ByteBuffer) GetUint64At

func (this *ByteBuffer) GetUint64At(index int) (uint64, error)

GetUint16At is an absolute get method for reading a uint64 value. Reads eight bytes at the given index, composing them into a uint64 value according to the current byte order.

func (*ByteBuffer) HasRemaining

func (this *ByteBuffer) HasRemaining() bool

HasRemaining tells whether there are any elements between the current position and the limit.

func (*ByteBuffer) IsReadOnly

func (this *ByteBuffer) IsReadOnly() bool

IsReadOnly tells whether or not this buffer is read-only.

func (*ByteBuffer) IsWrapped

func (this *ByteBuffer) IsWrapped() bool

IsWrapped tells whether or not this buffer wraps another []byte

func (*ByteBuffer) Limit

func (this *ByteBuffer) Limit() int

Limit returns this buffer's position.

func (*ByteBuffer) Mark

func (this *ByteBuffer) Mark() int

Mark returns this buffer's mark.

func (*ByteBuffer) Order

func (this *ByteBuffer) Order() binary.ByteOrder

Order retrieves this buffer's byte order. The byte order is used when reading or writing multibyte values, and when creating buffers that are views of this byte buffer. The order of a newly-created byte buffer is always binary.BigEndian.

func (*ByteBuffer) Peek

func (this *ByteBuffer) Peek() (byte, error)

func (*ByteBuffer) Position

func (this *ByteBuffer) Position() int

Position returns this buffer's position.

func (*ByteBuffer) Put

func (this *ByteBuffer) Put(b byte) error

Put is a relative put method Writes the given byte into this buffer at the current position, and then increments the position.

func (*ByteBuffer) PutAt

func (this *ByteBuffer) PutAt(index int, b byte) error

PutAt is an absolute put method that writes the given byte into this buffer at the given index.

func (*ByteBuffer) PutBytes

func (this *ByteBuffer) PutBytes(src []byte, offset, length int) error

PutBytes is a relative bulk put method

This method transfers bytes into this buffer from the given source array. If there are more bytes to be copied from the array than remain in this buffer, that is, if length > remaining(), then no bytes are transferred and a BufferOverflowException is thrown.

Otherwise, this method copies length bytes from the given array into this buffer, starting at the given offset in the array and at the current position of this buffer. The position of this buffer is then incremented by length.

func (*ByteBuffer) PutFrom

func (this *ByteBuffer) PutFrom(src *ByteBuffer) error

PutFrom is a relative bulk put method

This method transfers the bytes remaining in the given source buffer into this buffer. If there are more bytes remaining in the source buffer than in this buffer, that is, if src.remaining() > remaining(), then no bytes are transferred and a BufferOverflowException is thrown.

Otherwise, this method copies n = src.remaining() bytes from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.

func (*ByteBuffer) PutUint16

func (this *ByteBuffer) PutUint16(value uint16) error

GetUint16 is a relative get method for reading a short value. Reads the next two bytes at this buffer's current position, composing them into a short value according to the current byte order, and then increments the position by two.

func (*ByteBuffer) PutUint16At

func (this *ByteBuffer) PutUint16At(index int, value uint16) error

PutUint16At is an absolute put method for writing a short value Writes two bytes containing the given short value, in the current byte order, into this buffer at the given index.

func (*ByteBuffer) PutUint32

func (this *ByteBuffer) PutUint32(value uint32) error

GetUint32 is a relative get method for reading a uint32 value. Reads the next four bytes at this buffer's current position, composing them into a uint32 value according to the current byte order, and then increments the position by two.

func (*ByteBuffer) PutUint32At

func (this *ByteBuffer) PutUint32At(index int, value uint32) error

PutUint32At is an absolute put method for writing a uint32 value Writes four bytes containing the given uint32 value, in the current byte order, into this buffer at the given index.

func (*ByteBuffer) PutUint64

func (this *ByteBuffer) PutUint64(value uint64) error

GetUint64 is a relative get method for reading a uint64 value. Reads the next eight bytes at this buffer's current position, composing them into a uint64 value according to the current byte order, and then increments the position by two.

func (*ByteBuffer) PutUint64At

func (this *ByteBuffer) PutUint64At(index int, value uint64) error

PutUint64At is an absolute put method for writing a uint64 value Writes eight bytes containing the given uint64 value, in the current byte order, into this buffer at the given index.

func (*ByteBuffer) Remaining

func (this *ByteBuffer) Remaining() int

Remaining returns the number of elements between the current position and the capacity

func (*ByteBuffer) Reset

func (this *ByteBuffer) Reset() error

Reset resets this buffer's position to the previously-marked position. Invoking this method neither changes nor discards the mark's value.

func (*ByteBuffer) Resize

func (this *ByteBuffer) Resize(newSize int) error

func (*ByteBuffer) Rewind

func (this *ByteBuffer) Rewind() error

Rewinds this buffer. The position is set to zero and the mark is discarded.

func (*ByteBuffer) SetLimit

func (this *ByteBuffer) SetLimit(limit int) error

SetLimit sets this buffer's limit. If the position is larger than the new limit then it is set to the new limit. If the mark is defined and larger than the new limit then it is discarded.

func (*ByteBuffer) SetOrder

func (this *ByteBuffer) SetOrder(bo binary.ByteOrder)

SetOrder modifies this buffer's byte order.

func (*ByteBuffer) SetPosition

func (this *ByteBuffer) SetPosition(pos int) error

SetPosition sets this buffer's position.

func (*ByteBuffer) Slice

func (this *ByteBuffer) Slice() *ByteBuffer

Slice creates a new byte buffer whose content is a shared subsequence of this buffer's content.

The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.

The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer, and its mark will be undefined. The new buffer will be read-only if, and only if, this buffer is read-only.

func (*ByteBuffer) String

func (this *ByteBuffer) String() string

type Int32Buffer

type Int32Buffer struct {
	// contains filtered or unexported fields
}

func (*Int32Buffer) Capacity

func (this *Int32Buffer) Capacity() int

Returns this buffer's capacity.

func (*Int32Buffer) Clear

func (this *Int32Buffer) Clear() error

Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded.

func (*Int32Buffer) Flip

func (this *Int32Buffer) Flip() error

Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.

func (*Int32Buffer) Get

func (this *Int32Buffer) Get() (int32, error)

GetUint32 is a relative get method for reading a int32 value. Reads the next four bytes at this buffer's current position, composing them into a int32 value according to the current byte order, and then increments the position by two.

func (*Int32Buffer) GetAt

func (this *Int32Buffer) GetAt(index int) (int32, error)

GetUint16At is an absolute get method for reading a int32 value. Reads four bytes at the given index, composing them into a int32 value according to the current byte order.

func (*Int32Buffer) GetInt32s

func (this *Int32Buffer) GetInt32s(dst []int32, offset, length int) error

GetInt32s is a relative bulk get method.

This method transfers ints from this buffer into the given destination array. If there are fewer ints remaining in the buffer than are required to satisfy the request, that is, if length > remaining(), then no ints are transferred and a BufferUnderflowException is thrown.

Otherwise, this method copies length ints from this buffer into the given array, starting at the current position of this buffer and at the given offset in the array. The position of this buffer is then incremented by length.

func (*Int32Buffer) HasRemaining

func (this *Int32Buffer) HasRemaining() bool

HasRemaining tells whether there are any elements between the current position and the limit.

func (*Int32Buffer) IsReadOnly

func (this *Int32Buffer) IsReadOnly() bool

IsReadOnly tells whether or not this buffer is read-only.

func (*Int32Buffer) Limit

func (this *Int32Buffer) Limit() int

Limit returns this buffer's position.

func (*Int32Buffer) Mark

func (this *Int32Buffer) Mark() int

Mark returns this buffer's mark.

func (*Int32Buffer) Order

func (this *Int32Buffer) Order() binary.ByteOrder

Order retrieves this buffer's byte order. The byte order is used when reading or writing multibyte values, and when creating buffers that are views of this byte buffer. The order of a newly-created byte buffer is always binary.BigEndian.

func (*Int32Buffer) Position

func (this *Int32Buffer) Position() int

Position returns this buffer's position.

func (*Int32Buffer) Put

func (this *Int32Buffer) Put(value int32) error

GetUint32 is a relative get method for reading a int32 value. Reads the next four bytes at this buffer's current position, composing them into a int32 value according to the current byte order, and then increments the position by two.

func (*Int32Buffer) PutAt

func (this *Int32Buffer) PutAt(index int, value int32) error

PutUint32At is an absolute put method for writing a int32 value Writes four bytes containing the given int32 value, in the current byte order, into this buffer at the given index.

func (*Int32Buffer) PutInt32s

func (this *Int32Buffer) PutInt32s(dst []int32, offset, length int) error

PutInt32s is a Relative bulk put method This method transfers ints into this buffer from the given source array. If there are more ints to be copied from the array than remain in this buffer, that is, if length > remaining(), then no ints are transferred and a BufferOverflowException is thrown.

Otherwise, this method copies length ints from the given array into this buffer, starting at the g iven offset in the array and at the current position of this buffer. The position of this buffer is then incremented by length.

func (*Int32Buffer) Remaining

func (this *Int32Buffer) Remaining() int

Remaining returns the number of elements between the current position and the capacity

func (*Int32Buffer) Reset

func (this *Int32Buffer) Reset() error

Reset resets this buffer's position to the previously-marked position. Invoking this method neither changes nor discards the mark's value.

func (*Int32Buffer) Rewind

func (this *Int32Buffer) Rewind() error

Rewinds this buffer. The position is set to zero and the mark is discarded.

func (*Int32Buffer) SetLimit

func (this *Int32Buffer) SetLimit(limit int) error

SetLimit sets this buffer's limit. If the position is larger than the new limit then it is set to the new limit. If the mark is defined and larger than the new limit then it is discarded.

func (*Int32Buffer) SetOrder

func (this *Int32Buffer) SetOrder(bo binary.ByteOrder)

SetOrder modifies this buffer's byte order.

func (*Int32Buffer) SetPosition

func (this *Int32Buffer) SetPosition(pos int) error

SetPosition sets this buffer's position.

func (*Int32Buffer) String

func (this *Int32Buffer) String() string

type Uint32Buffer

type Uint32Buffer struct {
	// contains filtered or unexported fields
}

func (*Uint32Buffer) Capacity

func (this *Uint32Buffer) Capacity() int

Returns this buffer's capacity.

func (*Uint32Buffer) Clear

func (this *Uint32Buffer) Clear() error

Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded.

func (*Uint32Buffer) Flip

func (this *Uint32Buffer) Flip() error

Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.

func (*Uint32Buffer) Get

func (this *Uint32Buffer) Get() (uint32, error)

GetUint32 is a relative get method for reading a uint32 value. Reads the next four bytes at this buffer's current position, composing them into a uint32 value according to the current byte order, and then increments the position by two.

func (*Uint32Buffer) GetAt

func (this *Uint32Buffer) GetAt(index int) (uint32, error)

GetUint16At is an absolute get method for reading a uint32 value. Reads four bytes at the given index, composing them into a uint32 value according to the current byte order.

func (*Uint32Buffer) GetUint32s

func (this *Uint32Buffer) GetUint32s(dst []uint32, offset, length int) error

GetUint32s is a relative bulk get method.

This method transfers ints from this buffer into the given destination array. If there are fewer ints remaining in the buffer than are required to satisfy the request, that is, if length > remaining(), then no ints are transferred and a BufferUnderflowException is thrown.

Otherwise, this method copies length ints from this buffer into the given array, starting at the current position of this buffer and at the given offset in the array. The position of this buffer is then incremented by length.

func (*Uint32Buffer) HasRemaining

func (this *Uint32Buffer) HasRemaining() bool

HasRemaining tells whether there are any elements between the current position and the limit.

func (*Uint32Buffer) IsReadOnly

func (this *Uint32Buffer) IsReadOnly() bool

IsReadOnly tells whether or not this buffer is read-only.

func (*Uint32Buffer) Limit

func (this *Uint32Buffer) Limit() int

Limit returns this buffer's position.

func (*Uint32Buffer) Mark

func (this *Uint32Buffer) Mark() int

Mark returns this buffer's mark.

func (*Uint32Buffer) Order

func (this *Uint32Buffer) Order() binary.ByteOrder

Order retrieves this buffer's byte order. The byte order is used when reading or writing multibyte values, and when creating buffers that are views of this byte buffer. The order of a newly-created byte buffer is always binary.BigEndian.

func (*Uint32Buffer) Position

func (this *Uint32Buffer) Position() int

Position returns this buffer's position.

func (*Uint32Buffer) Put

func (this *Uint32Buffer) Put(value uint32) error

GetUint32 is a relative get method for reading a uint32 value. Reads the next four bytes at this buffer's current position, composing them into a uint32 value according to the current byte order, and then increments the position by two.

func (*Uint32Buffer) PutAt

func (this *Uint32Buffer) PutAt(index int, value uint32) error

PutUint32At is an absolute put method for writing a uint32 value Writes four bytes containing the given uint32 value, in the current byte order, into this buffer at the given index.

func (*Uint32Buffer) PutUint32s

func (this *Uint32Buffer) PutUint32s(dst []uint32, offset, length int) error

PutUint32s is a Relative bulk put method This method transfers ints into this buffer from the given source array. If there are more ints to be copied from the array than remain in this buffer, that is, if length > remaining(), then no ints are transferred and a BufferOverflowException is thrown.

Otherwise, this method copies length ints from the given array into this buffer, starting at the g iven offset in the array and at the current position of this buffer. The position of this buffer is then incremented by length.

func (*Uint32Buffer) Remaining

func (this *Uint32Buffer) Remaining() int

Remaining returns the number of elements between the current position and the capacity

func (*Uint32Buffer) Reset

func (this *Uint32Buffer) Reset() error

Reset resets this buffer's position to the previously-marked position. Invoking this method neither changes nor discards the mark's value.

func (*Uint32Buffer) Rewind

func (this *Uint32Buffer) Rewind() error

Rewinds this buffer. The position is set to zero and the mark is discarded.

func (*Uint32Buffer) SetLimit

func (this *Uint32Buffer) SetLimit(limit int) error

SetLimit sets this buffer's limit. If the position is larger than the new limit then it is set to the new limit. If the mark is defined and larger than the new limit then it is discarded.

func (*Uint32Buffer) SetOrder

func (this *Uint32Buffer) SetOrder(bo binary.ByteOrder)

SetOrder modifies this buffer's byte order.

func (*Uint32Buffer) SetPosition

func (this *Uint32Buffer) SetPosition(pos int) error

SetPosition sets this buffer's position.

func (*Uint32Buffer) String

func (this *Uint32Buffer) String() string

Jump to

Keyboard shortcuts

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