View source code
Display the source code in std/bitmanip.d from which this
page was generated on github.
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.
Function std.bitmanip.append
Takes an integral value, converts it to the given endianness, and appends
it to the given range of ubyte
s (using put
) as a sequence of
T
ubyte
s starting at index. hasSlicing!R
must be
true
.
void append(T, Endian endianness = Endian .bigEndian, R)
(
R range,
T value
)
if (canSwapEndianness!T && isOutputRange!(R, ubyte));
Parameters
Name | Description |
---|---|
T | The integral type to convert the first T bytes to. |
endianness | The endianness to write the bytes in. |
range | The range to append to. |
value | The value to append. |
Example
import std .array;
auto buffer = appender!(const ubyte[])();
buffer .append!ushort(261);
writeln(buffer .data); // [1, 5]
buffer .append!uint(369700095u);
writeln(buffer .data); // [1, 5, 22, 9, 44, 255]
buffer .append!ubyte(8);
writeln(buffer .data); // [1, 5, 22, 9, 44, 255, 8]
Example
bool
import std .array : appender;
auto buffer = appender!(const ubyte[])();
buffer .append!bool(true);
writeln(buffer .data); // [1]
buffer .append!bool(false);
writeln(buffer .data); // [1, 0]
Example
char wchar dchar
import std .array : appender;
auto buffer = appender!(const ubyte[])();
buffer .append!char('a');
writeln(buffer .data); // [97]
buffer .append!char('b');
writeln(buffer .data); // [97, 98]
buffer .append!wchar('ą');
writeln(buffer .data); // [97, 98, 1, 5]
buffer .append!dchar('ą');
writeln(buffer .data); // [97, 98, 1, 5, 0, 0, 1, 5]
Example
float double
import std .array : appender;
auto buffer = appender!(const ubyte[])();
buffer .append!float(32.0f);
writeln(buffer .data); // [66, 0, 0, 0]
buffer .append!double(32.0);
writeln(buffer .data); // [66, 0, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0]
Example
enum
import std .array : appender;
auto buffer = appender!(const ubyte[])();
enum Foo
{
one = 10,
two = 20,
three = 30
}
buffer .append!Foo(Foo .one);
writeln(buffer .data); // [0, 0, 0, 10]
buffer .append!Foo(Foo .two);
writeln(buffer .data); // [0, 0, 0, 10, 0, 0, 0, 20]
buffer .append!Foo(Foo .three);
writeln(buffer .data); // [0, 0, 0, 10, 0, 0, 0, 20, 0, 0, 0, 30]
Example
enum - bool
import std .array : appender;
auto buffer = appender!(const ubyte[])();
enum Bool: bool
{
bfalse = false,
btrue = true,
}
buffer .append!Bool(Bool .btrue);
writeln(buffer .data); // [1]
buffer .append!Bool(Bool .bfalse);
writeln(buffer .data); // [1, 0]
buffer .append!Bool(Bool .btrue);
writeln(buffer .data); // [1, 0, 1]
Example
enum - float
import std .array : appender;
auto buffer = appender!(const ubyte[])();
enum Float: float
{
one = 32.0f,
two = 25.0f
}
buffer .append!Float(Float .one);
writeln(buffer .data); // [66, 0, 0, 0]
buffer .append!Float(Float .two);
writeln(buffer .data); // [66, 0, 0, 0, 65, 200, 0, 0]
Example
enum - double
import std .array : appender;
auto buffer = appender!(const ubyte[])();
enum Double: double
{
one = 32.0,
two = 25.0
}
buffer .append!Double(Double .one);
writeln(buffer .data); // [64, 64, 0, 0, 0, 0, 0, 0]
buffer .append!Double(Double .two);
writeln(buffer .data); // [64, 64, 0, 0, 0, 0, 0, 0, 64, 57, 0, 0, 0, 0, 0, 0]
Example
enum - real
import std .array : appender;
auto buffer = appender!(const ubyte[])();
enum Real: real
{
one = 32.0,
two = 25.0
}
static assert(!__traits(compiles, buffer .append!Real(Real .one)));
Authors
Walter Bright, Andrei Alexandrescu, Jonathan M Davis, Alex Rønne Petersen, Damian Ziemba, Amaury SECHET
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.