Struct WriteBuffer

Circular, self-expanding buffer with overflow support. Can be used with functions returning the number of the transferred bytes.

struct WriteBuffer(T)
  
if (isScalarType!T);

The buffer is optimized for situations where you read all the data from it at once (without writing to it occasionally). It can become ineffective if you permanently keep some data in the buffer and alternate writing and reading, because it may allocate and move elements.

Constructors

NameDescription
this (size, allocator)

Fields

NameTypeDescription
blockSize size_tSize by which the buffer will grow.
buffer_ T[]Internal buffer.
position size_tThe position of the free area in the buffer.
ring size_tBuffer ring area size. After this position begins buffer overflow area.
start size_tBuffer start position.

Properties

NameTypeDescription
capacity[get] size_t
free[get] size_t
length[get] size_tNote that length doesn't return the real length of the data, but only the array length that will be returned with opIndex next time. Be sure to call opIndex and set += until length returns 0.

Methods

NameDescription
opIndex () After calling it, set += to the length could be written.
opOpAssign (length) Sets how many bytes were written. It will shrink the buffer appropriately. Always call it after opIndex.
opOpAssign (buffer) Appends data to the buffer.
opSlice (start, end) Returns a chunk with data.

Aliases

NameDescription
opDollar Note that length doesn't return the real length of the data, but only the array length that will be returned with opIndex next time. Be sure to call opIndex and set += until length returns 0.

Parameters

NameDescription
T Buffer type.