Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
std.outbuffer
Serialize data to ubyte arrays.
License:
Authors:
Source std/outbuffer.d
- class
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 fromOutBuffer
.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).Examples:import std.string : cmp; OutBuffer buf = new OutBuffer(); writeln(buf.offset); // 0 buf.write("hello"); buf.write(cast(byte) 0x20); buf.write("world"); buf.printf(" %d", 62665); writeln(cmp(buf.toString(), "hello world 62665")); // 0 buf.clear(); writeln(cmp(buf.toString(), "")); // 0 buf.write("New data"); writeln(cmp(buf.toString(), "New data")); // 0
- pure nothrow @safe ubyte[]
toBytes
(); - Convert to array of bytes.
- pure nothrow @trusted void
reserve
(size_tnbytes
); - Preallocate
nbytes
more to the size of the internal buffer.This is a speed optimization, a good guess at the maximum size of the resulting buffer will improve performance by eliminating reallocations and copying. - alias
put
= write; put
enables OutBuffer to be used as an OutputRange.- pure nothrow @safe void
write
(const(ubyte)[]bytes
);
pure nothrow @safe voidwrite
(byteb
);
pure nothrow @safe voidwrite
(charc
);
pure nothrow @safe voidwrite
(dcharc
);
pure nothrow @safe voidwrite
(shorts
);
pure nothrow @safe voidwrite
(inti
);
pure nothrow @safe voidwrite
(longl
); - Append data to the internal buffer.
- pure nothrow @safe void
fill0
(size_tnbytes
); - Append
nbytes
of 0 to the internal buffer. - pure nothrow @safe void
alignSize
(size_talignsize
); - 0-fill to align on power of 2 boundary.
- pure nothrow @safe void
clear
(); - Clear the data in the buffer
- pure nothrow @safe void
align2
(); - Optimize common special case alignSize(2)
- pure nothrow @safe void
align4
(); - Optimize common special case alignSize(4)
- const pure nothrow @safe string
toString
(); - Convert internal buffer to array of chars.
- nothrow @trusted void
vprintf
(stringformat
, va_listargs
); - Append output of C's
vprintf
() to internal buffer. - @trusted void
printf
(stringformat
, ...); - Append output of C's
printf
() to internal buffer. - void
writef
(Char, A...)(in Char[]fmt
, Aargs
); - Formats and writes its arguments in text format to the OutBuffer.Parameters:
Char[] fmt
format string as described in std.format.formattedWrite A args
arguments to be formatted See Also:Examples:OutBuffer b = new OutBuffer(); b.writef("a%sb", 16); writeln(b.toString()); // "a16b"
- void
writefln
(Char, A...)(in Char[]fmt
, Aargs
); - Formats and writes its arguments in text format to the OutBuffer, followed by a newline.Parameters:
Char[] fmt
format string as described in std.format.formattedWrite A args
arguments to be formatted See Also:Examples:OutBuffer b = new OutBuffer(); b.writefln("a%sb", 16); writeln(b.toString()); // "a16b\n"
- pure nothrow @safe void
spread
(size_tindex
, size_tnbytes
); - At offset
index
into buffer, createnbytes
of space by shifting upwards all data pastindex
.
Copyright © 1999-2018 by the D Language Foundation | Page generated by
Ddoc on (no date time)