Skip to content

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 IReadableByteBuffer for reading
  • Use IWritableByteBuffer for 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 WritableByteBuffer to create a writable buffer.
  • Use ReadableByteBuffer to wrap a byte[].

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...

  • ReadableBytes exposes how many bytes remain unread.
  • ResetOffset resets the read offset to the beginning.
  • ToArray() returns the full logical contents of the buffer (respecting view boundaries).
  • GetByteBuffer and ReadByteBuffer return zero-copy views.
  • Except for reading/getting methods, the API follows a fluent design.
  • IWritableByteBuffer is not expected in the input pipeline middleware.