License:
BSD style: see license.txt
Version:
Initial release: Oct 2007
author:
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
: tango.io.device.Conduit.InputFilter, tango.io.model.IBuffer.Buffered;
- A simple way to read binary data from an arbitrary InputStream,
such as a file:
auto input = new DataInput (new FileInput("path"));
auto x = input.getInt;
auto y = input.getDouble;
auto l = input.read (buffer); // read raw data directly
auto s = cast(char[]) input.get; // read length, allocate space
input.close;
- this(InputStream stream, uint buffer = (uint).max);
- Propagate ctor to superclass
- final IBuffer
buffer
();
- Buffered interface
- final DataInput
allocate
(void[] delegate(uint)
allocate
);
- Set the array allocator
- final DataInput
endian
(int e);
- Extended ctor with explicit
endian
translation
- final DataInput
clear
();
- Override this to give back a useful chaining reference
- final uint
get
(void[] dst);
- 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.
- final void[]
get
();
- 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
required:
auto text = cast(char[]) input.get;
- final bool
getBool
();
- final byte
getByte
();
- final short
getShort
();
- final int
getInt
();
- final long
getLong
();
- final float
getFloat
();
- final double
getDouble
();
- class
DataOutput
: tango.io.device.Conduit.OutputFilter, tango.io.model.IBuffer.Buffered;
- A simple way to write binary data to an arbitrary OutputStream,
such as a file:
auto output = new DataOutput (new FileOutput("path"));
output.putInt (1024);
output.putDouble (3.14159);
output.put ("string with length prefix");
output.write ("raw array, no prefix");
output.flush.close;
- this(OutputStream stream, uint buffer = (uint).max);
- Propagate ctor to superclass
- final IBuffer
buffer
();
- Buffered interface
- final DataOutput
endian
(int e);
- Extended ctor with explicit
endian
translation
- final uint
put
(void[] src);
- 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.
- final void
putBool
(bool x);
- final void
putByte
(byte x);
- final void
putShort
(short x);
- final void
putInt
(int x);
- final void
putLong
(long x);
- final void
putFloat
(float x);
- final void
putDouble
(double x);
|