dataio.eh

Additional I/O routines for binary data streams. More...

use "dataio.eh"

Functions

def IStream.readbool(): Bool;
def IStream.readbyte(): Int;
def IStream.readdouble(): Double;
def IStream.readfloat(): Float;
def IStream.readint(): Int;
def IStream.readlong(): Long;
def IStream.readshort(): Int;
def IStream.readubyte(): Int;
def IStream.readushort(): Int;
def IStream.readutf(): String;
def OStream.writebool(b: Bool);
def OStream.writebyte(b: Int);
def OStream.writedouble(d: Double);
def OStream.writefloat(f: Float);
def OStream.writeint(i: Int);
def OStream.writelong(l: Long);
def OStream.writeshort(s: Int);
def OStream.writeutf(str: String);
def readbool(): Bool;
def readbyte(): Int;
def readdouble(): Double;
def readfloat(): Float;
def readint(): Int;
def readlong(): Long;
def readshort(): Int;
def readubyte(): Int;
def readushort(): Int;
def readutf(): String;
def writebool(b: Bool);
def writebyte(b: Int);
def writedouble(d: Double);
def writefloat(f: Float);
def writeint(i: Int);
def writelong(l: Long);
def writeshort(s: Int);
def writeutf(str: String);

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.

def readbool(): Bool;
Reads one byte from stdin and returns true if that byte is non-zero, false otherwise.

def readbyte(): Int;
Reads and returns one byte from stdin as signed integer in range −128..127.

def readubyte(): Int;
Reads and returns one byte from stdin as unsigned integer in range 0..255.

def readshort(): Int;
Reads two bytes from stdin and returns them as signed integer in range −32768..32767.

def readushort(): Int;
Reads two bytes from stdin and returns them as unsigned integer in range 0..65535.

def readint(): Int;
Reads four bytes from stdin and returns them as Int value.

def readlong(): Long;
Reads eight bytes from stdin and returns them as Long value.

def readfloat(): Float;
Reads four bytes from stdin and decodes a Float value. It does so by reading an Int and decoding it with ibits2f.

def readdouble(): Double;
Reads eight bytes from stdin and decodes a Double value. It does so by reading a Long and decoding it with lbits2d.

def 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.

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.

def writebool(b: Bool);
Writes a Bool value to stdout. Writes 1 if argument is true and 0 if argument is false.

def writebyte(b: Int);
Writes byte to stdout. The byte is represented by low 8 bits of given value.

def writeshort(s: Int);
Writes short value (or character) to stdout. The value is represented by low 16 bits of given value and is written as two bytes.

def writeint(i: Int);
Writes Int value to stdout. Four bytes are written.

def writelong(l: Long);
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.

def writedouble(d: Double);
Writes Double value to stdout. It does so by converting given value to Long using d2lbits and writing resulting eight bytes.

def writeutf(str: String);
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.