pack-d 1.0.1

BinaryReader

BinaryReader (defined in binary.reader) provides an interface for reading binary data.

Reading methods (such as read) come in two variants: either data is returned or written to specified parameter (taken by ref).

Example

auto source = [...]; // binary data
auto reader = binaryReader(source); // Construct BinaryReader with binaryReader helper

byte b;
writeln(reader.read!ulong()); // return ulong
writer.read(b); // reads by reference into ch
writeln(writer.position); // ulong.sizeof + byte.sizeof = 9

// change byte order
writer.byteOrder = ByteOrder.BigEndian;
writer.read!ushort();
writer.clear(); // resets source

Methods

Fields

Properties

BinaryWriter

BinaryWriter (defined in binary.writer) provides an interface for writing binary data. It is an valid OutputRange.

Example

BinaryWriter writer = BinaryWriter(ByteOrder.LittleEndian);
writer.write(15UL);
writer.write!byte('a');
writeln(writer.position); // ulong.sizeof + byte.sizeof = 9
writeln(writer.buffer); // [15, 0, 0, 0,  0, 0, 0, 0,  97]

writer.byteOrder = ByteOrder.BigEndian;
writer.write!ushort(5);
writeln(writer.buffer); // [15, 0, 0, 0,  0, 0, 0, 0,  97, 0, 5]
writer.clear(); // buffer is now empty

Methods

Fields

Properties