<HTML><HEAD><TITLE>nibbles</TITLE><LINKTYPE="text/css"TITLE="default"REL="stylesheet"MEDIA="screen"HREF="style.css"/></HEAD><BODY><H1>nibbles</H1><P>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.</P><H2>Installation</H2><P>nibbles can be downloaded at <AHREF="http://www.method-combination.net/lisp/files/nibbles.tar.gz">http://www.method-combination.net/lisp/files/nibbles.tar.gz</A>. The latest version is 0.1.</P><P>It comes with an ASDF system definition, so <TT>(ASDF:OOS
'ASDF:LOAD-OP :NIBBLES)</TT> should be all that you need to get started.</P><H2>License</H2><P>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.</P><H2>Integer array accessors</H2><DIVCLASS="lisp-symbol"><ANAME="ub16ref/le"></A><TT><STRONG>ub16ref/le</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/><ANAME="ub32ref/le"></A><TT><STRONG>ub32ref/le</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/><ANAME="ub64ref/le"></A><TT><STRONG>ub64ref/le</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/></DIV><P>This family of functions accesses an unsigned 16-bit, 32-bit or
64-bit value stored in little-endian order starting at <EM>index</EM> in <EM>vector</EM>. <EM>vector</EM> must be a <TT>(VECTOR (UNSIGNED-BYTE 8))</TT>. These functions are SETFable. For instance:</P><PRE>CL-USER> (nibbles:ub16ref/le (coerce #(42 53) '(vector (unsigned-byte 8))) 0)
13610
CL-USER> (format nil "~X" *)
"352A"</PRE><DIVCLASS="lisp-symbol"><ANAME="ub16ref/be"></A><TT><STRONG>ub16ref/be</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/><ANAME="ub32ref/be"></A><TT><STRONG>ub32ref/be</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/><ANAME="ub64ref/be"></A><TT><STRONG>ub64ref/be</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/></DIV><P>As the above, only the value is accessed in big-endian order. For instance:</P><PRE>CL-USER> (nibbles:ub16ref/be (coerce #(42 53) '(vector (unsigned-byte 8))) 0)
10805
CL-USER> (format nil "~X" *)
"2A35"</PRE><DIVCLASS="lisp-symbol"><ANAME="sb16ref/le"></A><TT><STRONG>sb16ref/le</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/><ANAME="sb32ref/le"></A><TT><STRONG>sb32ref/le</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/><ANAME="sb64ref/le"></A><TT><STRONG>sb64ref/le</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/></DIV><DIVCLASS="lisp-symbol"><ANAME="sb16ref/be"></A><TT><STRONG>sb16ref/be</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/><ANAME="sb32ref/be"></A><TT><STRONG>sb32ref/be</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/><ANAME="sb64ref/be"></A><TT><STRONG>sb64ref/be</STRONG><EM>vector</EM><EM>index</EM> =><EM>value</EM></TT><BR/></DIV><P>As the above, only the value accessed is a signed value. For instance:</P><PRE>CL-USER> (nibbles:sb16ref/be (coerce #(81 92) '(vector (unsigned-byte 8))) 0)
"-787F 5C51"</PRE><H2>Stream readers</H2><DIVCLASS="lisp-symbol"><ANAME="read-ub16/le"></A><TT><STRONG>read-ub16/le</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="read-ub32/le"></A><TT><STRONG>read-ub32/le</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="read-ub64/le"></A><TT><STRONG>read-ub64/le</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/></DIV><P>This family of functions reads an unsigned 16-bit, 32-bit, or
64-bit value from <EM>stream</EM> in little-endian order. <EM>stream</EM>
must have an element-type of <TT>(UNSIGNED-BYTE 8)</TT>.</P><DIVCLASS="lisp-symbol"><ANAME="read-ub16/be"></A><TT><STRONG>read-ub16/be</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="read-ub32/be"></A><TT><STRONG>read-ub32/be</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="read-ub64/be"></A><TT><STRONG>read-ub64/be</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/></DIV><P>As the above, only the value is read in big-endian order.</P><DIVCLASS="lisp-symbol"><ANAME="read-sb16/le"></A><TT><STRONG>read-sb16/le</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="read-sb32/le"></A><TT><STRONG>read-sb32/le</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="read-sb64/le"></A><TT><STRONG>read-sb64/le</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/></DIV><DIVCLASS="lisp-symbol"><ANAME="read-sb16/be"></A><TT><STRONG>read-sb16/be</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="read-sb32/be"></A><TT><STRONG>read-sb32/be</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="read-sb64/be"></A><TT><STRONG>read-sb64/be</STRONG><EM>stream</EM> =><EM>value</EM></TT><BR/></DIV><P>As the above, only the value is signed, rather than unsigned.</P><H2>Stream writers</H2><DIVCLASS="lisp-symbol"><ANAME="write-ub16/le"></A><TT><STRONG>write-ub16/le</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="write-ub32/le"></A><TT><STRONG>write-ub32/le</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="write-ub64/le"></A><TT><STRONG>write-ub64/le</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/></DIV><P>This family of functions writes an unsigned 16-bit, 32-bit, or
64-bit <EM>integer</EM> to <EM>stream</EM> in little-endian order. <EM>stream</EM>
must have an element-type of <TT>(UNSIGNED-BYTE 8)</TT>. The value written
is returned.</P><DIVCLASS="lisp-symbol"><ANAME="write-ub16/be"></A><TT><STRONG>write-ub16/be</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="write-ub32/be"></A><TT><STRONG>write-ub32/be</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="write-ub64/be"></A><TT><STRONG>write-ub64/be</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/></DIV><P>As the above, only the value is read in big-endian order.</P><DIVCLASS="lisp-symbol"><ANAME="write-sb16/le"></A><TT><STRONG>write-sb16/le</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="write-sb32/le"></A><TT><STRONG>write-sb32/le</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="write-sb64/le"></A><TT><STRONG>write-sb64/le</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/></DIV><DIVCLASS="lisp-symbol"><ANAME="write-sb16/be"></A><TT><STRONG>write-sb16/be</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="write-sb32/be"></A><TT><STRONG>write-sb32/be</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/><ANAME="write-sb64/be"></A><TT><STRONG>write-sb64/be</STRONG><EM>integer</EM><EM>stream</EM> =><EM>value</EM></TT><BR/></DIV><P>As the above, only the value is signed, rather than unsigned.</P></BODY></HTML>