std.outbuffer

Serialize data to ubyte arrays.

*

class OutBuffer

Types 1

OutBuffer provides a way to build up an array of bytes out of raw data. It is useful for things like preparing an array of bytes to write out to a file. OutBuffer's byte order is the format native to the computer. To control the byte order (endianness), use a class derived from OutBuffer.

OutBuffer's internal buffer is allocated with the GC. Pointers stored into the buffer are scanned by the GC, but you have to ensure proper alignment, e.g. by using alignSize((void*).sizeof).

Fields
ubyte[] data
size_t offset
Methods
inout(ubyte)[] toBytes() pure nothrow @safe scope inoutConvert to array of bytes.
void reserve(size_t nbytes) pure nothrow @safe @trustedPreallocate nbytes more to the size of the internal buffer.
void write(scope const(ubyte)[] bytes) pure nothrow @safeAppend data to the internal buffer.
void write(scope const(wchar)[] chars) pure nothrow @safe @trusted
void write(scope const(dchar)[] chars) pure nothrow @safe @trusted
void write(ubyte b) pure nothrow @safe
void write(byte b) pure nothrow @safeditto
void write(char c) pure nothrow @safeditto
void write(dchar c) pure nothrow @safeditto
void write(ushort w) pure nothrow @safe @trusted
void write(short s) pure nothrow @safeditto
void write(wchar c) pure nothrow @safe @trusted
void write(uint w) pure nothrow @safe @trusted
void write(int i) pure nothrow @safeditto
void write(ulong l) pure nothrow @safe @trusted
void write(long l) pure nothrow @safeditto
void write(float f) pure nothrow @safe @trusted
void write(double f) pure nothrow @safe @trusted
void write(real f) pure nothrow @safe @trusted
void write(scope const(char)[] s) pure nothrow @safe @trusted
void write(scope const OutBuffer buf) pure nothrow @safe
void fill(size_t nbytes, ubyte val = 0) pure nothrow @safeAppend nbytes of val to the internal buffer. Params: nbytes = Number of bytes to fill. val = Value to fill, defaults to 0.
void fill0(size_t nbytes) pure nothrow @safeAppend nbytes of 0 to the internal buffer. Param: nbytes - number of bytes to fill.
void alignSize(size_t alignsize, ubyte val = 0) pure nothrow @safeAppend bytes until the buffer aligns on a power of 2 boundary.
void clear() pure nothrow @safeClear the data in the buffer
void align2(ubyte val = 0) pure nothrow @safeOptimize common special case alignSize(2) Params: val = Value to fill, defaults to 0.
void align4(ubyte val = 0) pure nothrow @safeOptimize common special case alignSize(4) Params: val = Value to fill, defaults to 0.
string toString() pure nothrow @safe constConvert internal buffer to array of chars.
void vprintf(scope string format, va_list args) @system nothrowAppend output of C's vprintf() to internal buffer.
void printf(scope string format, ...) @systemAppend output of C's printf() to internal buffer.
void writef(Char, A...)(scope const(Char)[] fmt, A args)Formats and writes its arguments in text format to the OutBuffer.
void writef(alias fmt, A...)(A args) if (isSomeString!(typeof(fmt)))ditto
void writefln(Char, A...)(scope const(Char)[] fmt, A args)Formats and writes its arguments in text format to the OutBuffer, followed by a newline.
void writefln(alias fmt, A...)(A args) if (isSomeString!(typeof(fmt)))ditto
void spread(size_t index, size_t nbytes) pure nothrow @safeAt offset index into buffer, create nbytes of space by shifting upwards all data past index.