Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
You can edit this page using
wiki syntax
for markup.
Article contents:
[[tags: eggs]] [[toc:]] == endian-sequence === Description {{endian-sequence}} is a library of endian-specific procedures for converting byte sequences to numeric values and vectors. An endian sequence associates a byte sequence (from the [[byte-sequence]] egg) with a byte order ({{MSB}} or {{LSB}}). This egg was called {{endian-blob}} in CHICKEN 4 and 5. In CHICKEN 6 it was renamed to {{endian-sequence}} and rebuilt on top of {{byte-sequence}} and bytevectors. All procedure names that contained {{endian-blob}} now contain {{endian-sequence}} instead; for example, {{endian-blob->uint2}} is now {{endian-sequence->uint2}} and {{byte-blob->endian-blob}} is now {{byte-sequence->endian-sequence}}. === Author Ivan Raikov === Repository [[https://github.com/iraikov/chicken-endian-blob|https://github.com/iraikov/chicken-endian-blob]] === Requirements * [[byte-sequence]] === Usage <enscript highlight="scheme"> (import srfi-4 byte-sequence endian-sequence) (define s (uint2->endian-sequence #x0102 MSB)) (byte-sequence->list (endian-sequence->byte-sequence s)) ; => (1 2) (endian-sequence->uint2 s) ; => 258 (endian-sequence->u16vector (u16vector->endian-sequence (u16vector 100 200) LSB)) ; => #u16(100 200) </enscript> === Library Procedures ==== Predicates and constants <procedure>(endian-sequence? X) => BOOL</procedure> Returns {{#t}} if the given object is an endian sequence, {{#f}} otherwise. <constant>MSB</constant><br> <constant>LSB</constant> These constants specify most-significant or least-significant byte order, respectively. ==== Converting to and from byte sequences <procedure>(byte-sequence->endian-sequence BYTE-SEQUENCE [BYTE-ORDER]) => ENDIAN-SEQUENCE</procedure> Returns an endian sequence containing the given byte sequence. Optional argument {{BYTE-ORDER}} is one of {{MSB}} or {{LSB}}. Default is {{MSB}}. <procedure>(endian-sequence->byte-sequence ENDIAN-SEQUENCE) => BYTE-SEQUENCE</procedure> Returns the byte sequence contained in the given endian sequence. <procedure>(endian-sequence-length ENDIAN-SEQUENCE) => INTEGER</procedure> Returns the length of the given endian sequence in bytes. <procedure>(endian-sequence-mode ENDIAN-SEQUENCE) => BYTE-ORDER</procedure> Returns the byte order ({{MSB}} or {{LSB}}) of the given endian sequence. ==== Converting to and from numbers and numeric vectors ===== Signed integers <procedure>(endian-sequence->sint1 ENDIAN-SEQUENCE) => NUMBER</procedure><br> <procedure>(endian-sequence->sint2 ENDIAN-SEQUENCE) => NUMBER</procedure><br> <procedure>(endian-sequence->sint4 ENDIAN-SEQUENCE) => NUMBER</procedure><br> <procedure>(sint1->endian-sequence NUMBER [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(sint2->endian-sequence NUMBER [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(sint4->endian-sequence NUMBER [MODE]) => ENDIAN-SEQUENCE</procedure> These procedures convert between endian sequences and signed integers of size 1, 2, or 4 bytes, respectively. Exceptions are thrown if the given endian sequences are of incorrect size, or if the given numbers are too big to fit in the specified size. Optional argument {{MODE}} indicates the endianness of the resulting endian sequence and can be one of {{MSB}} or {{LSB}}. Default is {{MSB}}. ===== Unsigned integers <procedure>(endian-sequence->uint1 ENDIAN-SEQUENCE) => NUMBER</procedure><br> <procedure>(endian-sequence->uint2 ENDIAN-SEQUENCE) => NUMBER</procedure><br> <procedure>(endian-sequence->uint4 ENDIAN-SEQUENCE) => NUMBER</procedure><br> <procedure>(uint1->endian-sequence NUMBER [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(uint2->endian-sequence NUMBER [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(uint4->endian-sequence NUMBER [MODE]) => ENDIAN-SEQUENCE</procedure> These procedures convert between endian sequences and unsigned integers of size 1, 2, or 4 bytes, respectively. Exceptions are thrown if the given endian sequences are of incorrect size, or if the given numbers are too big to fit in the specified size. Optional argument {{MODE}} indicates the endianness of the resulting endian sequence and can be one of {{MSB}} or {{LSB}}. Default is {{MSB}}. ===== IEEE floating point numbers <procedure>(endian-sequence->ieee_float32 ENDIAN-SEQUENCE) => NUMBER</procedure><br> <procedure>(endian-sequence->ieee_float64 ENDIAN-SEQUENCE) => NUMBER</procedure><br> <procedure>(ieee_float32->endian-sequence NUMBER [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(ieee_float64->endian-sequence NUMBER [MODE]) => ENDIAN-SEQUENCE</procedure> These procedures convert between endian sequences and IEEE floating point numbers of single or double precision, respectively. Infinities and NaNs are preserved in both directions. Exceptions are thrown if the given endian sequences are of incorrect size (4 bytes for single precision, 8 bytes for double precision). Optional argument {{MODE}} indicates the endianness of the resulting endian sequence and can be one of {{MSB}} or {{LSB}}. Default is {{MSB}}. ===== SRFI-4 vectors <procedure>(endian-sequence->s8vector ENDIAN-SEQUENCE) => S8VECTOR</procedure><br> <procedure>(endian-sequence->s16vector ENDIAN-SEQUENCE) => S16VECTOR</procedure><br> <procedure>(endian-sequence->s32vector ENDIAN-SEQUENCE) => S32VECTOR</procedure><br> <procedure>(endian-sequence->u8vector ENDIAN-SEQUENCE) => U8VECTOR</procedure><br> <procedure>(endian-sequence->u16vector ENDIAN-SEQUENCE) => U16VECTOR</procedure><br> <procedure>(endian-sequence->u32vector ENDIAN-SEQUENCE) => U32VECTOR</procedure><br> <procedure>(endian-sequence->f32vector ENDIAN-SEQUENCE) => F32VECTOR</procedure><br> <procedure>(endian-sequence->f64vector ENDIAN-SEQUENCE) => F64VECTOR</procedure><br> <procedure>(s8vector->endian-sequence S8VECTOR [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(s16vector->endian-sequence S16VECTOR [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(s32vector->endian-sequence S32VECTOR [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(u8vector->endian-sequence U8VECTOR [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(u16vector->endian-sequence U16VECTOR [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(u32vector->endian-sequence U32VECTOR [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(f32vector->endian-sequence F32VECTOR [MODE]) => ENDIAN-SEQUENCE</procedure><br> <procedure>(f64vector->endian-sequence F64VECTOR [MODE]) => ENDIAN-SEQUENCE</procedure> These procedures convert between endian sequences and the corresponding SRFI-4 vector type. When converting to a vector, the length of the endian sequence must be a positive multiple of the element size of that vector type. Optional argument {{MODE}} indicates the endianness of the resulting endian sequence and can be one of {{MSB}} or {{LSB}}. Default is {{MSB}}. === Version History * 3.0 Ported to CHICKEN 6; renamed from endian-blob to endian-sequence, now built on byte-sequence and bytevectors; fixed decoding of IEEE infinities and NaNs * 2.0 Ported to CHICKEN 5 * 1.4 Removed dependency on ansidecl.h (thanks to Peter Bex) * 1.3 Added procedure endian-blob-length * 1.2 Fixed a bug in uint2->endian-blob (thanks to Shawn Rutledge) * 1.1 Some small optimizations * 1.0 Initial release === License Copyright 2009-2026 Ivan Raikov. endian-sequence is based on routines from the C++ advanced I/O library and TIFF reader written by Oleg Kiselyov, as well as the floating-point I/O routines from GDB. endian-sequence 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. endian-sequence 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/>.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you multiply 5 by 3?