open class ChunkBuffer : Buffer
var next: ChunkBuffer?
Reference to next buffer view. Useful to chain multiple views. |
|
var origin: ChunkBuffer?
Reference to an origin buffer view this was copied from |
|
val referenceCount: Int |
var
User data: could be a session, connection or anything useful |
|
val capacity: Int
Buffer's capacity (including reserved startGap and endGap. Value for released buffer is unspecified. |
|
val endGap: Int
Number of bytes reserved in the end. |
|
var limit: Int
Write position limit. No bytes could be written ahead of this limit. When the limit is less than the capacity
then this means that there are reserved bytes in the end (endGap). Such a reserved space in the end could be used
to write size, hash and so on. Also it is useful when several buffers are connected into a chain and some
primitive value (e.g. |
|
val memory: Memory |
|
var readPosition: Int
Current read position. It is always non-negative and will never run ahead of the writePosition. It is usually greater or equal to startGap reservation. This position is affected by discard, rewind, resetForRead, resetForWrite, reserveStartGap and reserveEndGap. |
|
val readRemaining: Int
Number of bytes available for reading. |
|
var startGap: Int
Start gap is a reserved space in the beginning. The reserved space is usually used to write a packet length in the case when it's not known before the packet constructed. |
|
var writePosition: Int
Current write position. It is always non-negative and will never run ahead of the limit. It is always greater or equal to the readPosition. |
|
val writeRemaining: Int
Size of the free space available for writing in bytes. |
fun cleanNext(): ChunkBuffer? |
|
open fun duplicate(): ChunkBuffer
Create a new Buffer instance pointing to the same memory and having the same positions. |
|
open fun release(pool: ObjectPool<ChunkBuffer>): Unit |
|
fun reset(): Unit
Clear buffer's state: read/write positions, gaps and so on. Byte content is not cleaned-up. |
fun commitWritten(count: Int): Unit |
|
fun fun |
|
fun discardExact(count: Int = readRemaining): Unit
Discard count readable bytes. |
|
open fun duplicateTo(copy: Buffer): Unit |
|
fun readByte(): Byte
Read the next byte or fail with EOFException if it's not available. The returned byte is marked as consumed. |
|
fun reserveEndGap(endGap: Int): Unit
Reserve endGap bytes in the end. Could move readPosition and writePosition to reserve space but only when no bytes were written or all written bytes are marked as consumed (were read or discarded). |
|
fun reserveStartGap(startGap: Int): Unit
Reserve startGap bytes in the beginning. May move readPosition and writePosition if no bytes available for reading. |
|
fun resetForRead(): Unit
Marks the whole buffer available for read and no for write |
|
fun resetForWrite(): Unit
Marks all capacity writable except the start gap reserved before. The end gap reservation is discarded. fun resetForWrite(limit: Int): Unit
Marks up to limit bytes of the buffer available for write and no bytes for read. It does respect startGap already reserved. All extra bytes after the specified limit are considered as endGap. |
|
fun rewind(count: Int = readPosition - startGap): Unit
Rewind readPosition backward to make count bytes available for reading again. |
|
open fun toString(): String |
|
fun tryPeekByte(): Int
Peek the next unsigned byte or return |
|
fun tryReadByte(): Int
Read the next unsigned byte or return |
|
fun writeByte(value: Byte): Unit
Write a byte value at writePosition (incremented when written successfully). |
val Empty: ChunkBuffer |
|
val EmptyPool: ObjectPool<ChunkBuffer>
A pool that always returns ChunkBuffer.Empty |
|
val Pool: ObjectPool<ChunkBuffer> |
var Buffer. |
fun Buffer. fun Buffer. fun Buffer. fun Buffer. |
|
fun Buffer.canRead(): Boolean |
|
fun Buffer.canWrite(): Boolean |
|
fun Buffer.decodeUTF8(consumer: (Char) -> Boolean): Int
Decodes all the bytes to utf8 applying every character on consumer until or consumer return |
|
fun Buffer.fill(times: Int, value: Byte): Unit
Write byte value repeated the specified times. fun Buffer.fill(times: Int, value: <ERROR CLASS>): Unit
Write unsigned byte value repeated the specified times. fun Buffer.
|
|
fun Buffer. |
|
fun Buffer.forEach(block: (Byte) -> Unit): Unit
For every byte from this buffer invokes block function giving it as parameter. |
|
fun ChunkBuffer. |
|
fun Buffer.
Push back n bytes: only possible if there were at least n bytes read before this operation. |
|
fun Buffer.read(block: (memory: Memory, start: Int, endExclusive: Int) -> Int): Int
Apply block of code with buffer's memory providing read range indices. The returned value of block lambda should return number of bytes to be marked as consumed. No read/write functions on this buffer should be called inside of block otherwise an undefined behaviour may occur including data damage. |
|
fun Buffer.readAvailable(destination: ByteArray, offset: Int = 0, length: Int = destination.size - offset): Int fun Buffer.readAvailable(destination: <ERROR CLASS>, offset: Int = 0, length: Int = destination.size - offset): Int
Read available for read bytes to the destination array range starting at array offset and length bytes. If less than length bytes available then less bytes will be copied and the corresponding number will be returned as result. fun Buffer.readAvailable(destination: ShortArray, offset: Int = 0, length: Int = destination.size - offset): Int fun Buffer.readAvailable(destination: IntArray, offset: Int = 0, length: Int = destination.size - offset): Int fun Buffer.readAvailable(destination: LongArray, offset: Int = 0, length: Int = destination.size - offset): Int fun Buffer.readAvailable(destination: FloatArray, offset: Int = 0, length: Int = destination.size - offset): Int fun Buffer.readAvailable(destination: DoubleArray, offset: Int = 0, length: Int = destination.size - offset): Int
Read available for read bytes to the destination array range starting at array offset and length elements. If less than length elements available then less elements will be copied and the corresponding number will be returned as result (possibly zero). fun Buffer.readAvailable(dst: Buffer, length: Int = dst.writeRemaining): Int
Read at most length available bytes to the dst buffer or fun Buffer.readAvailable(dst: ByteBuffer, length: Int = dst.remaining()): Int |
|
fun Buffer.readAvailableLittleEndian(dst: <ERROR CLASS>, offset: Int = 0, length: Int = dst.size - offset): Int fun Buffer.readAvailableLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Int fun Buffer.readAvailableLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Int fun Buffer.readAvailableLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Int fun Buffer.readAvailableLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Int fun Buffer.readAvailableLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Int |
|
fun Buffer.readBytes(count: Int = readRemaining): ByteArray
Read the specified number of bytes specified (optional, read all remaining by default) |
|
fun Buffer.readDirect(block: (ByteBuffer) -> Unit): Int |
|
fun Buffer.readDouble(): Double
Read a floating point number or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian). |
|
fun Buffer.readDoubleLittleEndian(): Double |
|
fun Buffer.readFloat(): Float
Read a floating point number or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian). |
|
fun Buffer.readFloatLittleEndian(): Float |
|
fun Buffer.readFully(dst: Array<Byte>, offset: Int = 0, length: Int = dst.size - offset): Unit fun Buffer.readFully(dst: ByteBuffer, length: Int): Unit fun Buffer.readFully(destination: ByteArray, offset: Int = 0, length: Int = destination.size - offset): Unit fun Buffer.readFully(destination: <ERROR CLASS>, offset: Int = 0, length: Int = destination.size - offset): Unit
Read from this buffer to the destination array to offset and length bytes. fun Buffer.readFully(destination: ShortArray, offset: Int = 0, length: Int = destination.size - offset): Unit fun Buffer.readFully(destination: IntArray, offset: Int = 0, length: Int = destination.size - offset): Unit fun Buffer.readFully(destination: LongArray, offset: Int = 0, length: Int = destination.size - offset): Unit fun Buffer.readFully(destination: FloatArray, offset: Int = 0, length: Int = destination.size - offset): Unit fun Buffer.readFully(destination: DoubleArray, offset: Int = 0, length: Int = destination.size - offset): Unit
Read from this buffer to the destination array to offset and length bytes. Numeric values are interpreted in the network byte order (Big Endian). fun Buffer.readFully(dst: Buffer, length: Int = dst.writeRemaining): Int
Read at most length bytes from this buffer to the dst buffer. fun Buffer.readFully(destination: ByteBuffer): Unit
Read buffer's content to the destination buffer moving it's position. |
|
fun Buffer.readFullyLittleEndian(dst: <ERROR CLASS>, offset: Int = 0, length: Int = dst.size - offset): Unit fun Buffer.readFullyLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Unit fun Buffer.readFullyLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Unit fun Buffer.readFullyLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Unit fun Buffer.readFullyLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Unit fun Buffer.readFullyLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Unit |
|
fun Buffer.readInt(): Int
Read an integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian). |
|
fun Buffer.readIntLittleEndian(): Int |
|
fun Buffer.readLong(): Long
Read a long integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian). |
|
fun Buffer.readLongLittleEndian(): Long |
|
fun Buffer.readShort(): Short
Read a short integer or fail if no bytes available for reading. The numeric value is decoded in the network order (Big Endian). |
|
fun Buffer.readShortLittleEndian(): Short |
|
fun Buffer. fun Buffer.readText(charset: Charset = Charsets.UTF_8, max: Int = Int.MAX_VALUE): String
Reads at most max characters decoding bytes with specified charset. Extra character bytes will remain unconsumed |
|
fun Buffer.readUByte(): <ERROR CLASS>
Read an unsigned byte or fail if no bytes available for reading. |
|
fun Buffer.readUInt(): <ERROR CLASS>
Read an unsigned integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian). |
|
fun Buffer.readULong(): <ERROR CLASS>
Read an unsigned long integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian). |
|
fun Buffer.readUShort(): <ERROR CLASS>
Read an unsigned short integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian). |
|
fun ChunkBuffer.remainingAll(): Long
Summarize remainings of all elements of the chain |
|
fun Buffer.
Peek the next unsigned byte or return |
|
fun Buffer.write(block: (memory: Memory, start: Int, endExclusive: Int) -> Int): Int
Apply block of code with buffer's memory providing write range indices. The returned value of block lambda should return number of bytes were written. o read/write functions on this buffer should be called inside of block otherwise an undefined behaviour may occur including data damage. |
|
fun Buffer.writeDirect(size: Int = 1, block: (ByteBuffer) -> Unit): Int |
|
fun Buffer.writeDouble(value: Double): Unit
Write a floating point number or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian). |
|
fun Buffer.writeDoubleLittleEndian(value: Double): Unit |
|
fun Buffer.writeFloat(value: Float): Unit
Write a floating point number or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian). |
|
fun Buffer.writeFloatLittleEndian(value: Float): Unit |
|
fun Buffer.writeFully(source: ByteArray, offset: Int = 0, length: Int = source.size - offset): Unit fun Buffer.writeFully(source: <ERROR CLASS>, offset: Int = 0, length: Int = source.size - offset): Unit
Write the whole source array range staring at offset and having the specified bytes length. fun Buffer.writeFully(source: ShortArray, offset: Int = 0, length: Int = source.size - offset): Unit fun Buffer.writeFully(source: IntArray, offset: Int = 0, length: Int = source.size - offset): Unit fun Buffer.writeFully(source: LongArray, offset: Int = 0, length: Int = source.size - offset): Unit fun Buffer.writeFully(source: FloatArray, offset: Int = 0, length: Int = source.size - offset): Unit fun Buffer.writeFully(source: DoubleArray, offset: Int = 0, length: Int = source.size - offset): Unit
Write the whole source array range staring at offset and having the specified items length. Numeric values are interpreted in the network byte order (Big Endian). fun Buffer.writeFully(src: Buffer): Unit
Write all readable bytes from src to this buffer. Fails if not enough space available to write all bytes. fun Buffer.writeFully(src: Buffer, length: Int): Unit
Write at most length readable bytes from src to this buffer. Fails if not enough space available to write all bytes. fun Buffer.writeFully(source: ByteBuffer): Unit
Write source buffer content moving it's position. |
|
fun Buffer.writeFullyLittleEndian(source: <ERROR CLASS>, offset: Int = 0, length: Int = source.size - offset): Unit fun Buffer.writeFullyLittleEndian(source: ShortArray, offset: Int = 0, length: Int = source.size - offset): Unit fun Buffer.writeFullyLittleEndian(source: IntArray, offset: Int = 0, length: Int = source.size - offset): Unit fun Buffer.writeFullyLittleEndian(source: LongArray, offset: Int = 0, length: Int = source.size - offset): Unit fun Buffer.writeFullyLittleEndian(source: FloatArray, offset: Int = 0, length: Int = source.size - offset): Unit fun Buffer.writeFullyLittleEndian(source: DoubleArray, offset: Int = 0, length: Int = source.size - offset): Unit |
|
fun Buffer.writeInt(value: Int): Unit
Write an integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian). |
|
fun Buffer.writeIntLittleEndian(value: Int): Unit |
|
fun Buffer.writeLong(value: Long): Unit
Write a long integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian). |
|
fun Buffer.writeLongLittleEndian(value: Long): Unit |
|
fun Buffer.writeShort(value: Short): Unit
Write a short integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian). |
|
fun Buffer.writeShortLittleEndian(value: Short): Unit |
|
fun Buffer.writeUByte(value: <ERROR CLASS>): Unit
Write an unsigned byte or fail if not enough space available for writing. |
|
fun Buffer.writeUInt(value: <ERROR CLASS>): Unit
Write an unsigned integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian). |
|
fun Buffer.writeULong(value: <ERROR CLASS>): Unit
Write an unsigned long integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian). |
|
fun Buffer.writeUShort(value: <ERROR CLASS>): Unit
Write an unsigned short integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian). |
expect class
A read-write facade to actual buffer of fixed size. Multiple views could share the same actual buffer. Concurrent unsafe. The only concurrent-safe operation is release. In most cases ByteReadPacket and BytePacketBuilder should be used instead. |