Description

An I/O port that supports different endian formats.

Author

Ivan Raikov

Version

Requires

Usage

(require-extension endian-port)

Download

endian-port.egg

Documentation

endian-port is a module that supports reading and writing of integers, IEEE floating-point numbers, and byte vectors while taking into account byte order. It is based on routines from the C++ advanced I/O library and TIFF reader written by Oleg Kiselyov.

Endian port data structures

record: (define-record endian-port fileno filename byte-order)

A record that represents and endian port. Field fileno is the file handle for that port. Field filename is the file name for that port. Field byte-order can be one of (MSB) or (LSB). The type byte-order is defined in the C module endian-lowio.

Endian port routines

procedure: open-endian-port:: MODE * FILENAME -> ENDIAN-PORT

Opens an endian port to the specified file. Mode can be one of 'read or 'write. In write mode, the file is created if it doesn't exist, otherwise the new data is appended to its end. The default endianness of the newly created endian port is MSB.

procedure: port->endian-port:: PORT -> ENDIAN-PORT

Creates an endian port to the file specified by the given port. The default endianness of the newly created endian port is MSB.

procedure: close-endian-port:: ENDIAN-PORT -> UNDEFINED

Closes the endian port.

procedure: endian-port-set-bigendian!:: EPORT -> UNDEFINED

Sets the endianness of the given endian port to MSB.

procedure: endian-port-set-littleendian!:: EPORT -> UNDEFINED

Sets the endianness of the given endian port to LSB.

procedure: endian-port-setpos:: EPORT * INTEGER [* WHENCE] -> UNDEFINED

Sets the file position of the given endian port to the specified position. The optional argument WHENCE is one of seek/set, seek/cur, seek/end. The default is seek/set (current position).

procedure: endian-port-pos:: EPORT -> INTEGER

Returns the current file position of the given endian port, relative to the beginning of the file.

procedure: endian-port-eof?:: EPORT -> BOOLEAN

Returns true if the current file position of the given endian port is at the end of the file, false otherwise

Routines for reading
procedure: endian-port-read-int1:: EPORT [* BYTE-ORDER] -> UINTEGER

Reads an unsigned integer of size 1 byte. Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-read-int2:: EPORT [* BYTE-ORDER] -> UINTEGER

Reads an unsigned integer of size 2 bytes. Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-read-int4:: EPORT [* BYTE-ORDER] -> UINTEGER

Reads an unsigned integer of size 4 bytes. Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-read-int8:: EPORT [* BYTE-ORDER] -> UINTEGER

Reads an unsigned integer of size 8 bytes. Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-read-ieee-float32:: EPORT [* BYTE-ORDER] -> UINTEGER

Reads an IEEE 754 single precision floating-point number. Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-read-ieee-float64:: EPORT [* BYTE-ORDER] -> UINTEGER

Reads an IEEE 754 double precision floating-point number. Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-read-bit-vector:: PORT * SIZE (in bits) [* BYTE-ORDER] -> BIT-VECTOR

Reads a bit vector of the specified size (in bits) and returns an iset bit vector (see module iset). Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-read-byte-vector:: PORT * SIZE [* BYTE-ORDER] -> BYTE-VECTOR

Reads a byte vector of the specified size and returns a Scheme byte vector. Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

Routines for writing
procedure: endian-port-write-int1:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER

Writes an unsigned integer of size 1 byte. Returns the number of bytes written (always 1). Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-write-int2:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER

Writes an unsigned integer of size 2 bytes. Returns the number of bytes written (always 2). Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-write-int4:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER

Writes an unsigned integer of size 4 bytes. Returns the number of bytes written (always 4). Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-write-int8:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER

Writes an unsigned integer of size 8 bytes. Returns the number of bytes written (always 8). Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-write-ieee-float32:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER

Writes an IEEE 754 single precision floating-point number. Returns the number of bytes written (always 4) bytes. Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-write-ieee-float64:: EPORT * WORD [* BYTE-ORDER] -> UINTEGER

Writes an IEEE 754 double precision floating-point number. Returns the number of bytes written (always 8) bytes. Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-write-byte-vector:: EPORT * BYTE-VECTOR [* BYTE-ORDER] -> UINTEGER

Writes the given byte vector and returns the number of bytes written. The argument must be a Scheme byte vector object. Optional argument BYTE-ORDER is one of (MSB) or (LSB). If byte order is not specified, the procedure uses the byte order setting of the given endian port.

procedure: endian-port-write-bit-vector:: EPORT * BIT-VECTOR [* BIT-ORDER] -> UINTEGER

Writes the given bit vector and returns the number of bytes written. The argument must be a bit vector as defined in the iset module. Optional argument BIT-ORDER is one of (MSB) or (LSB). If bit order is not specified, the procedure uses the byte order setting of the given endian port.

Note that here the "byte order" type is interpreted as bit order: the order argument specifies that the bits are ordered in MSB or LSB order, not the bytes that comprise the bit vector.

Examples

License

Copyright 2005-2008 Ivan Raikov and the Georgia Institute of Technology

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

A full copy of the GPL license can be found at
<http://www.gnu.org/licenses/>.