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() scope inoutConvert to array of bytes.
void reserve(size_t nbytes) @trustedPreallocate nbytes more to the size of the internal buffer.
void write(scope const(ubyte)[] bytes)Append data to the internal buffer.
void write(scope const(wchar)[] chars) @trusted
void write(scope const(dchar)[] chars) @trusted
void write(ubyte b)
void write(byte b)ditto
void write(char c)ditto
void write(dchar c)ditto
void write(ushort w) @trusted
void write(short s)ditto
void write(wchar c) @trusted
void write(uint w) @trusted
void write(int i)ditto
void write(ulong l) @trusted
void write(long l)ditto
void write(float f) @trusted
void write(double f) @trusted
void write(real f) @trusted
void write(scope const(char)[] s) @trusted
void write(scope const OutBuffer buf)
void fill(size_t nbytes, ubyte val = 0)Append 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)Append nbytes of 0 to the internal buffer. Param: nbytes - number of bytes to fill.
void alignSize(size_t alignsize, ubyte val = 0)Append bytes until the buffer aligns on a power of 2 boundary.
void clear()Clear the data in the buffer
void align2(ubyte val = 0)Optimize common special case alignSize(2) Params: val = Value to fill, defaults to 0.
void align4(ubyte val = 0)Optimize common special case alignSize(4) Params: val = Value to fill, defaults to 0.
string toString() 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.