Overview
A lightweight library for reading and writing byte buffers. Although originally designed to work with Channels and part of the same project, it has no dependency on it and can be used independently.
Design
Buffer instances are always specialized for either reading or writing, never both.
- Use
IReadableByteBufferfor reading - Use
IWritableByteBufferfor writing
This separation simplifies the API surface and allows each implementation to be optimized for its specific purpose.
Using buffers
Outside of Channels, or when needed explicitly:
- Use
WritableByteBufferto create a writable buffer. - Use
ReadableByteBufferto wrap abyte[].
Reading Data
There are two ways to retrieve data:
- Get does not change the current offset
- Read advances the offset
IReadableByteBuffer buffer = ...;
// Reads at a custom offset (does not change buffer offset)
var b1 = buffer.GetByte( customOffset );
// Reads at current offset and advances it by 1
var b2 = buffer.ReadByte();
Good to know...
ReadableBytesexposes how many bytes remain unread.ResetOffsetresets the read offset to the beginning.ToArray()returns the full logical contents of the buffer (respecting view boundaries).GetByteBufferandReadByteBufferreturn zero-copy views.- Except for reading/getting methods, the API follows a fluent design.
IWritableByteBufferis not expected in the input pipeline middleware.