D Programming Language
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 local clone.

# std.outbuffer

Serialize data to ubyte arrays.
License:
Boost License 1.0.
Authors:
Walter Bright

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 from OutBuffer. OutBuffer's internal buffer is allocated with the GC.
  pure nothrow @safe ubyte[] toBytes();
    Convert to array of bytes.
  pure nothrow @trusted void reserve(size_t nbytes);
    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 void write(byte b);
  pure nothrow @safe void write(char c);
  pure nothrow @safe void write(dchar c);
  pure nothrow @safe void write(short s);
  pure nothrow @safe void write(int i);
  pure nothrow @safe void write(long l);
    Append data to the internal buffer.
  pure nothrow @safe void fill0(size_t nbytes);
    Append nbytes of 0 to the internal buffer.
  pure nothrow @safe void alignSize(size_t alignsize);
    0-fill to align on power of 2 boundary.
  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(string format, va_list args);
    Append output of C's vprintf() to internal buffer.
  @trusted void printf(string format, ...);
    Append output of C's printf() to internal buffer.
  void writef(Char, A...)(in Char[] fmt, A args);
    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:
    writef">std.stdio.writef; std.format.formattedWrite;
    Examples:

        OutBuffer b = new OutBuffer();
        b.writef("a%sb", 16);
        assert(b.toString() == "a16b");

  void writefln(Char, A...)(in Char[] fmt, A args);
    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:
    writefln">std.stdio.writefln; std.format.formattedWrite;
    Examples:

        OutBuffer b = new OutBuffer();
        b.writefln("a%sb", 16);
        assert(b.toString() == "a16b\n");

  pure nothrow @safe void spread(size_t index, size_t nbytes);
    At offset index into buffer, create nbytes of space by shifting upwards all data past index.

Copyright Digital Mars 2000 - 2015. | Page generated by Ddoc on Mon Aug 10 07:11:36 2015