The OpenD Programming Language

OutBuffer.alignSize

Append bytes until the buffer aligns on a power of 2 boundary.

By default fills with 0 bytes.

class OutBuffer
pure nothrow @safe
void
alignSize
(
size_t alignsize
,
ubyte val = 0
)
out { assert ((offset & (alignsize - 1)) == 0); }

Parameters

alignsize size_t

Alignment value. Must be power of 2.

val ubyte

Value to fill, defaults to 0.

Examples

OutBuffer buf = new OutBuffer();
buf.write(cast(ubyte) 1);
buf.align2();
assert(buf.toBytes() == "\x01\x00");
buf.write(cast(ubyte) 2);
buf.align4();
assert(buf.toBytes() == "\x01\x00\x02\x00");
buf.write(cast(ubyte) 3);
buf.alignSize(8);
assert(buf.toBytes() == "\x01\x00\x02\x00\x03\x00\x00\x00");

ditto

OutBuffer buf = new OutBuffer();
buf.write(cast(ubyte) 1);
buf.align2(0x55);
assert(buf.toBytes() == "\x01\x55");
buf.write(cast(ubyte) 2);
buf.align4(0x55);
assert(buf.toBytes() == "\x01\x55\x02\x55");
buf.write(cast(ubyte) 3);
buf.alignSize(8, 0x55);
assert(buf.toBytes() == "\x01\x55\x02\x55\x03\x55\x55\x55");

Meta