cc.otavia.buffer

Members list

Type members

Classlikes

abstract class AbstractBuffer(val underlying: ByteBuffer) extends Buffer

Attributes

Supertypes
trait Buffer
class Object
trait Matchable
class Any
Known subtypes
trait Buffer

A wrapper of java.nio.ByteBuffer, with separate reader and writer offsets.

A wrapper of java.nio.ByteBuffer, with separate reader and writer offsets.

A buffer is a logically sequential stretch of memory with a certain capacity, an offset for writing, and an offset for reading. Buffers may be composed of multiple components, where each component is a guaranteed contiguous chunk of memory.

=== Creating a buffer === Buffers are created by allocators, and their allocate family of methods. A number of standard allocators exist, and are available through static methods on the BufferAllocator interface.

=== Buffer life cycle === The buffer has a life cycle, where it is allocated, used, and deallocated. When the buffer is initially allocated, a pairing close() call will deallocate it.

=== Thread-safety === Buffer are not thread-safe.

=== Accessing data === Data access methods fall into two classes:

  1. Access that are based on, and updates, the read or write offset positions.
    • These accessor methods are typically called readX or writeX.
  2. Access that take offsets as arguments, and do not update read or write offset positions.
    • These accessor methods are typically called getX or setX.

A buffer contains two mutable offset positions: one for reading and one for writing. These positions use zero-based indexing , such that the first byte of data in the buffer is placed at offset 0, and the last byte in the buffer is at offset capacity - 1. The readerOffset() is the offset into the buffer from which the next read will take place, and is initially zero. The reader offset must always be less than or equal to the writerOffset(). The writerOffset() is likewise the offset into the buffer where the next write will take place. The writer offset is also initially zero, and must be less than or equal to the capacity.

This carves the buffer into three regions, as demonstrated by this diagram:

| discardable bytes | readable bytes | writable bytes |
|:------------------|:--------------:|:--------------:|
|                   |   (CONTENT)    |                |
|                   |                |                |
0 <= readerOffset <= writerOffset <= capacity 

=== Byte Order === Buffers are always big endian, and this cannot be changed. Usages that need to get, set, read, or write, little-endian values will have to flip the byte order of the values they read and write.

=== Splitting buffers === The split() method is not support.

=== Buffers as constants === Constants buffer is not support, use Array[Byte] directly.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Buffer

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Buffer.type

Interface for allocating Buffers.

Interface for allocating Buffers.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
class BufferClosedException(message: String | Null, cause: Throwable | Null) extends IllegalStateException

An exception thrown when an operation is attempted on a Buffer when it has been closed.

An exception thrown when an operation is attempted on a Buffer when it has been closed.

Attributes

Supertypes
class IllegalStateException
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all

Attributes

Supertypes
class Object
trait Matchable
class Any
Show all
Self type
trait ByteCursor

The ByteCursor scans through a sequence of bytes. This is similar to ByteProcessor, but for external iteration rather than internal iteration. The external iteration allows the callers to control the pace of the iteration.

The ByteCursor scans through a sequence of bytes. This is similar to ByteProcessor, but for external iteration rather than internal iteration. The external iteration allows the callers to control the pace of the iteration.

Attributes

Supertypes
class Object
trait Matchable
class Any

Provides a mechanism to iterate over a collection of bytes.

Provides a mechanism to iterate over a collection of bytes.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object ByteProcessor

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
object BytesUtil

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
BytesUtil.type

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type