An Overview of the Bytebuffer API

Library for packing and unpacking binary data. Simplifies using java.util.ByteBuffer objects.


by unknown author
Detailed API documentation
Library for packing and unpacking binary data. Simplifies working
with java.nio.ByteBuffer objects.

Notable features:

1. Handles signed and unsigned values pleasantly. Usually reading or
writing unsigned fields with ByteBuffers is a pain because Java
doesn't have unsigned primitives. The unsigned take-* functions here
actually return a type that is one step larger than the requested
type, ex. take-ushort returns an int, and take-uint returns a
bigint. The larger types are big enough to handle the entire unsigned
range of the smaller type. Similarly, although there are not separate
signed and unsigned version, the put-* functions will accept any
number type and truncate it so both positive and negative numbers can
be stored. TODO: Should add an overflow check to avoid overflows in
put-* functions?

2. Provides pack and unpack functions inspired by Python's struct
module. Use simple format strings, similar to printf's, to define how
fields are layed out in the buffer.

 (pack buff "isbb" 123 43 23 3) ; puts an int, a short and two bytes into buff
 (.flip buff) ; assuming nothing else was written to the buffer
 (unpack buff "isbb") => (123 43 24 3)

3. Provides pack-bits and unpack-bits functions for working with bit
fields within numbers. These are useful for pulling apart flag fields.
See also: java.nio.ByteBuffer Documentation
Public variables and functions: byte-buffer pack pack-bits put-byte put-int put-long put-short take-byte take-int take-long take-short take-ubyte take-uint take-ulong take-ushort unpack unpack-bits with-buffer
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.