WriteBuffer.opOpAssign - multiple declarations

Function WriteBuffer.opOpAssign

Appends data to the buffer.

WriteBuffer opOpAssign(string op) (
  ubyte[] buffer
)
if (op == "~");

Parameters

NameDescription
buffer Buffer chunk got with buffer.

Example

auto b = defaultAllocator.make!WriteBuffer(4);
ubyte[3] buf = [48, 23, 255];

b ~= buf;
assert(b.capacity == 4);
assert(b.buffer_[0] == 48 && b.buffer_[1] == 23 && b.buffer_[2] == 255);

b += 2;
b ~= buf;
assert(b.capacity == 4);
assert(b.buffer_[0] == 23 && b.buffer_[1] == 255
    && b.buffer_[2] == 255 && b.buffer_[3] == 48);

b += 2;
b ~= buf;
assert(b.capacity == 8);
assert(b.buffer_[0] == 23 && b.buffer_[1] == 255
    && b.buffer_[2] == 48 && b.buffer_[3] == 23 && b.buffer_[4] == 255);

defaultAllocator.dispose(b);

b = make!WriteBuffer(defaultAllocator, 2);

b ~= buf;
assert(b.start == 0);
assert(b.capacity == 4);
assert(b.ring == 3);
assert(b.position == 3);

defaultAllocator.dispose(b);

Function WriteBuffer.opOpAssign

Sets how many bytes were written. It will shrink the buffer appropriately. Always set this property after calling buffer.

WriteBuffer opOpAssign(string op) (
  size_t length
) pure nothrow @nogc @property @safe
if (op == "+");

Parameters

NameDescription
length Length of the written data.

Returns

this.

Example

auto b = defaultAllocator.make!WriteBuffer;
ubyte[6] buf = [23, 23, 255, 128, 127, 9];

b ~= buf;
assert(b.length == 6);
b += 2;
assert(b.length == 4);
b += 4;
assert(b.length == 0);

defaultAllocator.dispose(b);