ArrayReadWriteBuffer
Implements [ReadWriteBuffer]
using ByteArray as backing buffer. Using array of bytes are usually faster than ByteBuffer
.
This class is not thread-safe, meaning that it must operate on a single thread. Operating from multiple thread leads into an undefined behavior
All operations assume Little Endian byte order.
Constructors
Properties
Defines last relative position of the backed buffer that can be written. Any addition to the buffer that goes beyond will throw an exception instead of regrow the buffer (default behavior).
Current position of the buffer to be written. It will be automatically updated on put operations.
Functions
Expose ReadBuffer as an array of bytes. This method is meant to be as efficient as possible, so for an array-backed ReadBuffer, it should return its own internal data. In case access to internal data is not possible, a copy of the data into an array of bytes might occur.
Read boolean from the buffer. Booleans as stored as a single byte
Special operation where we increase the backed buffer size to capacity and shift all already written data to the end of the buffer.
Put a Boolean into the buffer at writePosition . Booleans as stored as single byte. Write position will be incremented.
Write a Byte into the buffer at writePosition. Write position will be incremented.
Write a 64-bit Double into the buffer at writePosition. Write position will be incremented.
Write a 32-bit Float into the buffer at writePosition. Write position will be incremented.
Write a Int in the buffer at writePosition. Write position will be incremented.
Write a Long into in the buffer at writePosition. Write position will be incremented.
Write a Short into in the buffer at writePosition. Write position will be incremented.
Write a UByte into the buffer at writePosition. Write position will be incremented.
Write a UInt into in the buffer at writePosition. Write position will be incremented.
Write a ULong into in the buffer at writePosition. Write position will be incremented.
Write a UShort into in the buffer at writePosition. Write position will be incremented.
Write a String encoded as UTF-8 into the buffer at writePosition. Write position will be incremented.
Put an array of bytes into the buffer at writePosition. Write position will be incremented.
Request capacity of the buffer relative to writePosition. In case buffer is already larger than the requested, this method will just return true. Otherwise, It might try to resize the buffer. In case of being unable to allocate enough memory, an exception will be thrown.
Request capacity of the buffer. In case buffer is already larger than the requested, it is a no-op. Otherwise, It might try to resize the buffer. In case of being unable to allocate enough memory, an exception will be thrown.
Short
Write an array of bytes into the buffer.
Creates a new ReadBuffer point to a region of the current buffer, starting at start with size size.
Creates a new ReadWriteBuffer point to a region of the current buffer, starting at offset with size size.