Unsigned Long and ByteBuffer-based bitwise operation primitives for UUID manipulation.
Provides the same mask/ldb/dpb fundamentals as in the past, plus a 16-byte ByteBuffer abstraction for direct UUID byte manipulation.
The ByteBuffer approach has two key advantages:
Unsigned Long and ByteBuffer-based bitwise operation primitives for UUID manipulation. Provides the same mask/ldb/dpb fundamentals as in the past, plus a 16-byte ByteBuffer abstraction for direct UUID byte manipulation. The ByteBuffer approach has two key advantages: 1. Performance: ByteBuffer provides direct typed access at byte offsets via single native operations (getLong, getInt, etc.) rather than manual shift/mask loops. 2. Portability: The buffer abstraction maps naturally to JavaScript's DataView/ArrayBuffer, enabling a future cljc implementation.
(assemble-bytes v)Assemble a sequence of 8 bytes (big-endian) into a long.
Assemble a sequence of 8 bytes (big-endian) into a long.
(bit-count x)Count the number of set bits in x.
Count the number of set bits in `x`.
(buf->bytes buf)Extract the contents of a 16-byte UUID buffer as a byte array.
Extract the contents of a 16-byte UUID buffer as a byte array.
(buf->uuid buf)Convert a 16-byte UUID buffer to a java.util.UUID.
Convert a 16-byte UUID buffer to a java.util.UUID.
(buf-compare a b)Lexicographic unsigned comparison of two 16-byte UUID buffers. Returns negative if a < b, zero if equal, positive if a > b. Comparison is unsigned (treats bytes as 0-255) which matches UUID canonical string ordering.
Lexicographic unsigned comparison of two 16-byte UUID buffers. Returns negative if a < b, zero if equal, positive if a > b. Comparison is unsigned (treats bytes as 0-255) which matches UUID canonical string ordering.
(buf-hex buf)Convert a 16-byte UUID buffer to a 32-character hex string.
Convert a 16-byte UUID buffer to a 32-character hex string.
(buf-str buf)Convert a 16-byte UUID buffer to the canonical 36-character UUID string: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Byte ranges correspond to UUID fields: bytes 0-3: time-low bytes 4-5: time-mid bytes 6-7: time-high-and-version bytes 8-9: clock-seq bytes 10-15: node
Convert a 16-byte UUID buffer to the canonical 36-character UUID string: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Byte ranges correspond to UUID fields: bytes 0-3: time-low bytes 4-5: time-mid bytes 6-7: time-high-and-version bytes 8-9: clock-seq bytes 10-15: node
(buffer)(buffer msb lsb)Create a 16-byte big-endian ByteBuffer.
0-arity: zeroed buffer 2-arity: from msb and lsb longs The buffer uses absolute (position-independent) get/put operations.
Create a 16-byte big-endian ByteBuffer. 0-arity: zeroed buffer 2-arity: from msb and lsb longs The buffer uses absolute (position-independent) get/put operations.
(buffer-from-bytes arr)Create a 16-byte ByteBuffer from a byte array (at least 16 bytes).
Create a 16-byte ByteBuffer from a byte array (at least 16 bytes).
(bytes->long arr i)Read 8 bytes from arr starting at offset i, returning a long.
Read 8 bytes from `arr` starting at offset `i`, returning a long.
(dpb bitmask num value)Deposit Byte -- insert value into the bit field defined by bitmask
within num.
Deposit Byte -- insert `value` into the bit field defined by `bitmask` within `num`.
(dpb-buf buf word-offset bitmask value)Deposit bit field: insert value into the bits defined by bitmask
within the 64-bit word at word-offset in the buffer. Mutates and
returns the buffer.
Deposit bit field: insert `value` into the bits defined by `bitmask` within the 64-bit word at `word-offset` in the buffer. Mutates and returns the buffer.
(duplicate buf)Create an independent copy of a UUID buffer.
Create an independent copy of a UUID buffer.
(get-byte buf offset)Read an unsigned byte (0-255) at byte offset from buffer.
Read an unsigned byte (0-255) at byte offset from buffer.
(get-int buf offset)Read an unsigned 32-bit value at byte offset from buffer.
Read an unsigned 32-bit value at byte offset from buffer.
(get-long buf offset)Read a 64-bit long at byte offset from buffer.
Read a 64-bit long at byte offset from buffer.
(get-lsb buf)Read the least significant 64 bits (bytes 8-15) of a UUID buffer.
Read the least significant 64 bits (bytes 8-15) of a UUID buffer.
(get-msb buf)Read the most significant 64 bits (bytes 0-7) of a UUID buffer.
Read the most significant 64 bits (bytes 0-7) of a UUID buffer.
(get-short buf offset)Read an unsigned 16-bit value at byte offset from buffer.
Read an unsigned 16-bit value at byte offset from buffer.
(hex thing)Convert a long or byte sequence to a hex string. For a long, produces a 16-character zero-padded hex string.
Convert a long or byte sequence to a hex string. For a long, produces a 16-character zero-padded hex string.
(hex->buf s)Parse a 32-character hex string into a 16-byte UUID buffer.
Parse a 32-character hex string into a 16-byte UUID buffer.
(ldb bitmask num)Load Byte -- extract the bit field defined by bitmask from num.
Load Byte -- extract the bit field defined by `bitmask` from `num`.
(ldb-buf buf word-offset bitmask)Load bit field: extract bits defined by bitmask from the 64-bit word
at word-offset in the buffer.
Load bit field: extract bits defined by `bitmask` from the 64-bit word at `word-offset` in the buffer.
(long->bytes x)(long->bytes x arr i)Write x as 8 big-endian bytes. With one argument returns a new byte
array. With three arguments writes into arr at offset i.
Write `x` as 8 big-endian bytes. With one argument returns a new byte array. With three arguments writes into `arr` at offset `i`.
(mask width offset)Create a bitmask of width bits starting at bit offset.
Create a bitmask of `width` bits starting at bit `offset`.
(mask-offset m)Return the bit offset (position of least significant set bit) of a mask.
Return the bit offset (position of least significant set bit) of a mask.
(mask-width m)Return the number of set bits in a contiguous bitmask.
Return the number of set bits in a contiguous bitmask.
(octet-hex num)Convert a single byte value to a two-character uppercase hex string.
Convert a single byte value to a two-character uppercase hex string.
(pphex x)Pretty-print a long value in both hexadecimal and binary.
Pretty-print a long value in both hexadecimal and binary.
(put-byte buf offset val)Write a byte value at byte offset in buffer. Returns the buffer.
Write a byte value at byte offset in buffer. Returns the buffer.
(put-int buf offset val)Write a 32-bit value at byte offset in buffer. Returns the buffer.
Write a 32-bit value at byte offset in buffer. Returns the buffer.
(put-long buf offset val)Write a 64-bit long at byte offset in buffer. Returns the buffer.
Write a 64-bit long at byte offset in buffer. Returns the buffer.
(put-short buf offset val)Write a 16-bit value at byte offset in buffer. Returns the buffer.
Write a 16-bit value at byte offset in buffer. Returns the buffer.
(set-lsb buf val)Set the least significant 64 bits (bytes 8-15) of a UUID buffer. Returns the buffer.
Set the least significant 64 bits (bytes 8-15) of a UUID buffer. Returns the buffer.
(set-msb buf val)Set the most significant 64 bits (bytes 0-7) of a UUID buffer. Returns the buffer.
Set the most significant 64 bits (bytes 0-7) of a UUID buffer. Returns the buffer.
(uuid->buf uuid)Convert a java.util.UUID to a 16-byte ByteBuffer.
Convert a java.util.UUID to a 16-byte ByteBuffer.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |