nibbles is a library for accessing multibyte integers from octet arrays and streams. While such accessors are straightforward to write, nibbles aims to centralize such facilities and also provide optimizations for them when appropriate.
nibbles can be downloaded at http://www.method-combination.net/lisp/files/nibbles.tar.gz. The latest version is 0.9.
It comes with an ASDF system definition, so (ASDF:OOS 'ASDF:LOAD-OP :NIBBLES) should be all that you need to get started.
nibbles is released under a MIT-like license; you can do pretty much anything you want to with the code except claim that you wrote it.
This family of functions accesses an unsigned 16-bit, 32-bit or 64-bit value stored in little-endian order starting at index in vector. vector must be a (VECTOR (UNSIGNED-BYTE 8)). These functions are SETFable. For instance:
CL-USER> (nibbles:ub16ref/le (coerce #(42 53) '(vector (unsigned-byte 8))) 0) 13610 CL-USER> (format nil "~X" *) "352A"
As the above, only the value is accessed in big-endian order. For instance:
CL-USER> (nibbles:ub16ref/be (coerce #(42 53) '(vector (unsigned-byte 8))) 0) 10805 CL-USER> (format nil "~X" *) "2A35"
As the above, only the value accessed is a signed value. For instance:
CL-USER> (nibbles:sb16ref/be (coerce #(81 92) '(vector (unsigned-byte 8))) 0) 20828 CL-USER> (nibbles:sb16ref/be (coerce #(129 135) '(vector (unsigned-byte 8))) 0) -32377 CL-USER> (format nil "~X ~X" ** *) "515C -7E79" CL-USER> (nibbles:sb16ref/le (coerce #(81 92) '(vector (unsigned-byte 8))) 0) 23633 CL-USER> (nibbles:sb16ref/le (coerce #(129 135) '(vector (unsigned-byte 8))) 0) -30847 CL-USER> (format nil "~X ~X" ** *) "5C51 -787F"
This family of functions reads an unsigned 16-bit, 32-bit, or 64-bit value from stream in little-endian order. stream must have an element-type of (UNSIGNED-BYTE 8).
As the above, only the value is read in big-endian order.
As the above, only the value is signed, rather than unsigned.
This family of functions writes an unsigned 16-bit, 32-bit, or 64-bit integer to stream in little-endian order. stream must have an element-type of (UNSIGNED-BYTE 8). The value written is returned.
As the above, only the value is read in big-endian order.
As the above, only the value is signed, rather than unsigned.