Types Functions Properties Extensions
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.
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).
Clear buffer's state: read/write positions, gaps and so on. Byte content is not cleaned-up.
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.
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.
common fun rewind (
: Int =
readPosition - startGap
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.
Buffer's capacity (including reserved
startGap and endGap). Value for released buffer is unspecified.
Number of bytes reserved in the end.
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.
Reference to next buffer view. Useful to chain multiple views.
Reference to an origin buffer view this was copied from
Number of bytes available for reading.
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.
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.
Size of the free space available for writing in bytes.
block function on a ByteBuffer of readable bytes. The block function should return number of consumed bytes.
block function on a ByteBuffer of the free space. The block function should return number of written bytes.