ChunkBuffer
Types
Functions
Discard count readable bytes.
Create a new Buffer instance pointing to the same memory and having the same positions.
Read the next byte or fail with EOFException if it's not available. The returned byte is marked as consumed.
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).
Reserve startGap bytes in the beginning. May move readPosition and writePosition if no bytes available for reading.
Marks the whole buffer available for read and no for write
Marks all capacity writable except the start gap reserved before. The end gap reservation is discarded.
Rewind readPosition backward to make count bytes available for reading again.
Peek the next unsigned byte or return -1
if no more bytes available for reading. No bytes will be marked as consumed in any case.
Read the next unsigned byte or return -1
if no more bytes available for reading. The returned byte is marked as consumed.
Write a byte value at writePosition (incremented when written successfully).
Properties
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. kotlin.Int
) is separated into two chunks so bytes from the second chain could be copied to the reserved space of the first chunk and then the whole value could be read at once.
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.
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.