BSD style: see
license.txt
Initial release: Oct 2007
Kris
These classes represent a simple means of reading and writing
discrete data types as binary values, with an option to invert
the endian order of numeric values.
Arrays are treated as untyped byte streams, with an optional
length-prefix, and should otherwise be explicitly managed at
the application level. We'll add additional support for arrays
and aggregates in future.
- class DataInput : InputFilter ¶#
-
A simple way to read binary data from an arbitrary InputStream,
such as a file:
1
2
3
4
5
6
| auto input = new DataInput (new File ("path"));
auto x = input.int32;
auto y = input.float64;
auto l = input.read (buffer); // read raw data directly
auto s = cast(char[]) input.array; // read length, allocate space
input.close;
|
- alias array get [public] ¶#
- alias boolean getBool [public] ¶#
- alias int8 getByte [public] ¶#
- alias int16 getShort [public] ¶#
- alias int32 getInt [public] ¶#
- alias int64 getLong [public] ¶#
- alias float32 getFloat [public] ¶#
- alias float64 getDouble [public] ¶#
-
old name alias
- this(InputStream stream) ¶#
-
Propagate ctor to superclass
- DataInput allocate(Allocate allocate) [final] ¶#
-
Set the array allocator
- DataInput endian(int e) [final] ¶#
-
set current endian translation
- uint array(void[] dst) [final] ¶#
-
Read an array back into a user-provided workspace. The
space must be sufficiently large enough to house all of
the array, and the actual number of bytes is returned.
Note that the size of the array is written as an integer
prefixing the array content itself. Use read(void[]) to
eschew this prefix.
- void[] array() [final] ¶#
-
Read an array back from the source, with the assumption
it has been written using DataOutput.put() or otherwise
prefixed with an integer representing the total number
of bytes within the array content. That's *bytes*, not
elements.
An array of the appropriate size is allocated either via
the provided delegate, or from the heap, populated and
returned to the caller. Casting the return value to an
appropriate type will adjust the number of elements as
1
| auto text = cast(char[]) input.get;
|
- bool boolean() [final] ¶#
-
- byte int8() [final] ¶#
-
- short int16() [final] ¶#
-
- int int32() [final] ¶#
-
- long int64() [final] ¶#
-
- float float32() [final] ¶#
-
- double float64() [final] ¶#
-
- size_t read(void[] data) [override, final] ¶#
-
- void eat(void* dst, size_t bytes) [private, final] ¶#
-
- class DataOutput : OutputFilter ¶#
-
A simple way to write binary data to an arbitrary OutputStream,
such as a file:
1
2
3
4
5
6
| auto output = new DataOutput (new File ("path", File.WriteCreate));
output.int32 (1024);
output.float64 (3.14159);
output.array ("string with length prefix");
output.write ("raw array, no prefix");
output.close;
|
- alias array put [public] ¶#
- alias boolean putBool [public] ¶#
- alias int8 putByte [public] ¶#
- alias int16 putShort [public] ¶#
- alias int32 putInt [public] ¶#
- alias int64 putLong [public] ¶#
- alias float32 putFloat [public] ¶#
- alias float64 putFloat [public] ¶#
-
old name alias
- this(OutputStream stream) ¶#
-
Propagate ctor to superclass
- DataOutput endian(int e) [final] ¶#
-
Set current endian translation
- uint array(void[] src) [final] ¶#
-
Write an array to the target stream. Note that the size
of the array is written as an integer prefixing the array
content itself. Use write(void[]) to eschew this prefix.
- void boolean(bool x) [final] ¶#
-
- void int8(byte x) [final] ¶#
-
- void int16(short x) [final] ¶#
-
- void int32(int x) [final] ¶#
-
- void int64(long x) [final] ¶#
-
- void float32(float x) [final] ¶#
-
- void float64(double x) [final] ¶#
-
- size_t write(void[] data) [override, final] ¶#
-
- void eat(void* src, size_t bytes) [private, final] ¶#
-