dataio.eh
Additional I/O routines for binary data streams. More...
Functions
Description
This header enhances
io.eh with I/O routines that allow reading
and writing of various data types in binary form. Writing functions convert
values in byte sequences that can be later read and converted back by
corresponding reading functions.
If reading function meets EOF while decoding value, it raises
an ERR_IO error.
Function details
def IStream.readbool(): Bool;
|
Reads one byte from the input and returns
true
if that byte is non-zero,
false
otherwise.
def IStream.readbyte(): Int;
|
Reads and returns one byte from the input as signed integer in range −128..127.
def IStream.readubyte(): Int;
|
Reads and returns one byte from the input as unsigned integer in range 0..255.
def IStream.readshort(): Int;
|
Reads two bytes from the input and returns them as signed integer in range −32768..32767.
def IStream.readushort(): Int;
|
Reads two bytes from the input and returns them as unsigned integer in range 0..65535.
def IStream.readint(): Int;
|
Reads four bytes from the input and returns them as
Int
value.
def IStream.readlong(): Long;
|
Reads eight bytes from the input and returns them as
Long
value.
def IStream.readfloat(): Float;
|
Reads four bytes from the input and decodes a
Float
value.
It does so by reading an
Int
and decoding it with
ibits2f.
def IStream.readdouble(): Double;
|
Reads eight bytes from the input and decodes a
Double
value.
It does so by reading a
Long
and decoding it with
lbits2d.
def IStream.readutf(): String;
|
Reads a string that has been encoded using a modified UTF-8 format.
First, two bytes are read as unsigned integer. This value specifies are number
of bytes that represent a string. The following bytes then decoded using
ba2utf.
Reads one byte from stdin and returns
true
if that byte is non-zero,
false
otherwise.
Reads and returns one byte from stdin as signed integer in range −128..127.
Reads and returns one byte from stdin as unsigned integer in range 0..255.
Reads two bytes from stdin and returns them as signed integer in range −32768..32767.
Reads two bytes from stdin and returns them as unsigned integer in range 0..65535.
Reads four bytes from stdin and returns them as
Int
value.
Reads eight bytes from stdin and returns them as
Long
value.
Reads four bytes from stdin and decodes a
Float
value.
It does so by reading an
Int
and decoding it with
ibits2f.
Reads eight bytes from stdin and decodes a
Double
value.
It does so by reading a
Long
and decoding it with
lbits2d.
Reads a string that has been encoded using a modified UTF-8 format.
First, two bytes are read as unsigned integer. This value specifies are number
of bytes that represent a string. The following bytes then decoded using
ba2utf.
def OStream.writebool(b: Bool);
|
Writes
Bool
value to the output.
Writes 1 if argument is
true
and 0 if argument is
false
.
def OStream.writebyte(b: Int);
|
Writes byte to the output.
The byte is represented by low 8 bits of given value.
def OStream.writeshort(s: Int);
|
Writes short value (or character) to the output.
The value is represented by low 16 bits of given value and is written as two bytes.
def OStream.writeint(i: Int);
|
Writes
Int
value to the output.
Four bytes are written.
def OStream.writelong(l: Long);
|
Writes
Long
value to the output.
Eight bytes are written.
def OStream.writefloat(f: Float);
|
Writes
Float
value to the output.
It does so by converting given value to
Int
using
f2ibits and writing
resulting four bytes.
def OStream.writedouble(d: Double);
|
Writes
Double
value to the output.
It does so by converting given value to
Long
using
d2lbits and writing
resulting eight bytes.
def OStream.writeutf(str: String);
|
Writes string in modified UTF-8 representation to the output.
String is converted to byte sequence using
String.utfbytes method. First, length
of the sequence is written as unsigned short value. Then the sequence itself is written.
Writes a
Bool
value to stdout.
Writes 1 if argument is
true
and 0 if argument is
false
.
Writes byte to stdout.
The byte is represented by low 8 bits of given value.
Writes short value (or character) to stdout.
The value is represented by low 16 bits of given value and is written as two bytes.
Writes
Int
value to stdout.
Four bytes are written.
Writes
Long
value to stdout.
Eight bytes are written.
def writefloat(f: Float);
|
Writes
Float
value to stdout.
It does so by converting given value to
Int
using
f2ibits and writing
resulting four bytes.
Writes
Double
value to stdout.
It does so by converting given value to
Long
using
d2lbits and writing
resulting eight bytes.
Writes string in modified UTF-8 representation to stdout.
String is converted to byte sequence using
String.utfbytes method. First, length
of the sequence is written as unsigned short value. Then the sequence itself is written.