The OpenD Programming Language

OutBuffer

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).

Members

Aliases

put
alias put = write

put enables OutBuffer to be used as an OutputRange.

Functions

align2
void align2(ubyte val)

Optimize common special case alignSize(2)

align4
void align4(ubyte val)

Optimize common special case alignSize(4)

alignSize
void alignSize(size_t alignsize, ubyte val)

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

clear
void clear()

Clear the data in the buffer

fill
void fill(size_t nbytes, ubyte val)

Append nbytes of val to the internal buffer.

fill0
void fill0(size_t nbytes)

Append nbytes of 0 to the internal buffer. Param: nbytes - number of bytes to fill.

printf
void printf(string format, ...)

Append output of C's printf() to internal buffer.

reserve
void reserve(size_t nbytes)

Preallocate nbytes more to the size of the internal buffer.

spread
void spread(size_t index, size_t nbytes)

At offset index into buffer, create nbytes of space by shifting upwards all data past index.

toBytes
inout(ubyte)[] toBytes()

Convert to array of bytes.

toString
string toString()

Convert internal buffer to array of chars.

vprintf
void vprintf(string format, va_list args)

Append output of C's vprintf() to internal buffer.

write
void write(const(ubyte)[] bytes)

Append data to the internal buffer.

writef
void writef(const(Char)[] fmt, A args)
void writef(A args)

Formats and writes its arguments in text format to the OutBuffer.

writefln
void writefln(const(Char)[] fmt, A args)
void writefln(A args)

Formats and writes its arguments in text format to the OutBuffer, followed by a newline.

Examples

import std.string : cmp;

OutBuffer buf = new OutBuffer();

assert(buf.offset == 0);
buf.write("hello");
buf.write(cast(byte) 0x20);
buf.write("world");
buf.printf(" %d", 62665);
assert(cmp(buf.toString(), "hello world 62665") == 0);

buf.clear();
assert(cmp(buf.toString(), "") == 0);
buf.write("New data");
assert(cmp(buf.toString(),"New data") == 0);

Meta