Uninhibited library for handling any kind binary format or protocol.
See README for an overview.
Uninhibited library for handling any kind binary format or protocol. See README for an overview.
(base64-decode string)
Decodes a string into a buffer
according to the Base64 basic scheme (RFC 4648 section 4)
Decodes a string into a [[buffer]] according to the Base64 basic scheme (RFC 4648 section 4)
(base64-encode buffer)
(base64-encode buffer offset)
(base64-encode buffer offset n-bytes)
Encodes a buffer
into a string according to the Base64 basic scheme (RFC 4648 section 4)
Encodes a [[buffer]] into a string according to the Base64 basic scheme (RFC 4648 section 4)
(bits-f32 f32)
Converts a 32-bit float to an integer preserving the bit pattern.
Opposite of f32
.
Converts a 32-bit float to an integer preserving the bit pattern. Opposite of [[f32]].
(bits-f64 f64)
Converts a 64-bit float to an integer preserving the bit pattern.
Opposite of f32
.
Converts a 64-bit float to an integer preserving the bit pattern. Opposite of [[f32]].
(buffer n-bytes)
Allocates a new buffer having n-bytes
bytes.
In Clojurescript, corresponds to a JS ArrayBuffer
.
In Clojure on the JVM, corresponds to a plain byte array.
In order to do anything interesting with this library, it needs to be wrapped in a [[view]].
Allocates a new buffer having `n-bytes` bytes. In Clojurescript, corresponds to a JS `ArrayBuffer`. In Clojure on the JVM, corresponds to a plain byte array. In order to do anything interesting with this library, it needs to be wrapped in a [[view]].
(buffer* & b8s)
Macro for instanting a new buffer populated by the given bytes.
For allocating a zeroed one, see buffer
.
Macro for instanting a new buffer populated by the given bytes. For allocating a zeroed one, see [[buffer]].
(copy-buffer src-buffer)
(copy-buffer dest-buffer src-buffer)
(copy-buffer dest-buffer dest-offset src-buffer)
(copy-buffer dest-buffer dest-offset src-buffer src-offset)
(copy-buffer dest-buffer dest-offset src-buffer src-offset n-bytes)
Copies a buffer to another buffer.
Copies a buffer to another buffer.
(f32 bits)
(f32 b8-1 b8-2 b8-3 b8-4)
Interprets bits from an integer (at least 32 bits) as a 32-bit float.
Opposite of bits-f32
.
Interprets bits from an integer (at least 32 bits) as a 32-bit float. Opposite of [[bits-f32]].
(f64 bits)
(f64 b8-1 b8-2 b8-3 b8-4 b8-5 b8-6 b8-7 b8-8)
Interprets bits from a 64-bits integer as a 64-bit float.
Opposite of [[bits-64]].
Interprets bits from a 64-bits integer as a 64-bit float. Opposite of [[bits-64]].
(growing-view buffer)
(growing-view buffer next-size)
Creates a growing view, starting with the given buffer.
A growing view will reallocate a bigger buffer everytime it reaches the end of the current one, but ONLY WHEN WRITING.
This is a simple strategy for when the size is unknown in advance, but it has proven to be rather optimal and ultimately efficient for the most common use cases. Even more so if the size can be roughly estimated.
The size of the bigger buffer is decided by calling next-size
which is a function old-size
-> new-size
.
Thus the user can be in full control of the process. When not provided, size is always multiplied by 1.5.
Creates a growing view, starting with the given buffer. A growing view will reallocate a bigger buffer everytime it reaches the end of the current one, but ONLY WHEN WRITING. This is a simple strategy for when the size is unknown in advance, but it has proven to be rather optimal and ultimately efficient for the most common use cases. Even more so if the size can be roughly estimated. The size of the bigger buffer is decided by calling `next-size` which is a function `old-size` -> `new-size`. Thus the user can be in full control of the process. When not provided, size is always multiplied by 1.5.
(growing? x)
Returns true if x
is a growing view instead of a fixed one.
See growing-view
.
Returns true if `x` is a growing view instead of a fixed one. See [[growing-view]].
(i16 bits)
(i16 b8-1 b8-2)
Casts the given bits
(any integer) into a 16-bit signed integer.
Or recombines the given bytes in big endian order.
Casts the given `bits` (any integer) into a 16-bit signed integer. Or recombines the given bytes in big endian order.
(i32 bits)
(i32 b8-1 b8-2 b8-3 b8-4)
Casts the given bits
(any integer) into a 32-bit signed integer.
Or recombines the given bytes in big endian order.
Casts the given `bits` (any integer) into a 32-bit signed integer. Or recombines the given bytes in big endian order.
(i64 b8-1 b8-2 b8-3 b8-4 b8-5 b8-6 b8-7 b8-8)
Recombines the given byets in big endian order to form a 64-bit signed integer.
Recombines the given byets in big endian order to form a 64-bit signed integer.
(i8 u8)
Casts the given bits
(any integer) into a 8-bit signed integer.
Casts the given `bits` (any integer) into a 8-bit signed integer.
Reading primitive values at an absolute position, without disturbing the current one.
Reading primitive values at an absolute position, without disturbing the current one.
(ra-u8 view position)
Reads an unsigned 8-bit interger from an absolute position
.
Reads an unsigned 8-bit interger from an absolute `position`.
(ra-i32 view position)
Reads a signed 32-bit integer from an absolute position
.
Reads a signed 32-bit integer from an absolute `position`.
(ra-f64 view position)
Reads a 64-bit float at from absolute position
.
Reads a 64-bit float at from absolute `position`.
(ra-string view position n-bytes)
(ra-string view decoder position n-bytes)
Reads a string consisting of n-bytes
bytes from an absolute position
.
A decoder may be provided (default is UTF-8).
Cf. text-decoder
Reads a string consisting of `n-bytes` bytes from an absolute `position`. A decoder may be provided (default is UTF-8). Cf. [[text-decoder]]
(ra-f32 view position)
Reads a 32-bit float at from absolute position
.
Reads a 32-bit float at from absolute `position`.
(ra-u16 view position)
Reads an unsigned 16-bit integer from an absolute position
.
Reads an unsigned 16-bit integer from an absolute `position`.
(ra-i8 view position)
Reads a signed 8-bit integer from an absolute position
.
Reads a signed 8-bit integer from an absolute `position`.
(ra-i64 view position)
Reads a signed 64-bit integer from an absolute position
.
Reads a signed 64-bit integer from an absolute `position`.
(ra-buffer view position n-bytes)
(ra-buffer view position n-bytes buffer)
(ra-buffer view position n-bytes buffer offset)
Reads n-bytes from an absolute position
and returns them in a new buffer or in the
given one at the specified offset
(or 0).
Reads n-bytes from an absolute `position` and returns them in a new buffer or in the given one at the specified `offset` (or 0).
(ra-u32 view position)
Reads an unsigned 32-bit integer from an absolute position
.
Reads an unsigned 32-bit integer from an absolute `position`.
(ra-i16 view position)
Reads a signed 16-bit integer from an absolute position
.
Reads a signed 16-bit integer from an absolute `position`.
Writing primitive values at an absolute position, without disturbing the current one.
When writing integers, sign is irrelevant and truncation is automatic.
Writing primitive values at an absolute position, without disturbing the current one. When writing integers, sign is irrelevant and truncation is automatic.
(wa-b16 view position integer)
Writes a 16-bit integer to an absolute position
.
Writes a 16-bit integer to an absolute `position`.
(wa-b32 view position integer)
Writes a 32-bit integer to an absolute position
.
Writes a 32-bit integer to an absolute `position`.
(wa-b64 view position integer)
Writes a 64-bit integer to an absolute position
.
Writes a 64-bit integer to an absolute `position`.
(wa-b8 view position integer)
Writes an 8-bit integer to an absolute position.
Writes an 8-bit integer to an absolute position.
(wa-buffer view position buffer)
(wa-buffer view position buffer offset)
(wa-buffer view position buffer offset n-bytes)
Copies the given buffer
to an absolute position
.
An offset
in the buffer as well as a number of bytes to copy (n-bytes
) may be provided.
Copies the given `buffer` to an absolute `position`. An `offset` in the buffer as well as a number of bytes to copy (`n-bytes`) may be provided.
(wa-f32 view position floating)
Writes a 32-bit float to an absolute position
.
Writes a 32-bit float to an absolute `position`.
(wa-f64 view position floating)
Writes a 64-bit float to an absolute position
.
Writes a 64-bit float to an absolute `position`.
(wa-string view position string)
Writes a string (encoded as UTF-8) to an absolute position
.
Unlike other functions which are implemented as a fluent interface, this function returns
a tuple indicating how many bytes and chars have been written, and if the process is finished:
[finished? n-bytes n-chars]
.
With that information, the user can continue writing if needed. On the JVM, the tuple contains a 4th
item which is a CharBuffer
containing the rest of the unwritten string which can be passed in place
of the string
argument.
Growing views will automatically grow and only one call will be sufficient.
Writes a string (encoded as UTF-8) to an absolute `position`. Unlike other functions which are implemented as a fluent interface, this function returns a tuple indicating how many bytes and chars have been written, and if the process is finished: `[finished? n-bytes n-chars]`. With that information, the user can continue writing if needed. On the JVM, the tuple contains a 4th item which is a `CharBuffer` containing the rest of the unwritten string which can be passed in place of the `string` argument. Growing views will automatically grow and only one call will be sufficient.
Retrieving or modifying the endianess.
Retrieving or modifying the endianess.
(endianess view)
(endianess view new-endianess)
Arity 1 returns the current endianess, arity 2 sets it.
Accepted values are :little-endian
and :big-endian
.
Arity 1 returns the current endianess, arity 2 sets it. Accepted values are `:little-endian` and `:big-endian`.
Only applicable to growing views
which are capable of growing size dynamically.
See growing-view
.
Only applicable to `growing views` which are capable of growing size dynamically. See [[growing-view]].
(garantee growing-view n-bytes)
Garantees that at least n-bytes
bytes can be written.
The growing view will automatically grow its size if needed.
This function is rather a lower-level one, the common user will probably never use it directly.
Garantees that at least `n-bytes` bytes can be written. The growing view will automatically grow its size if needed. This function is rather a lower-level one, the common user will probably never use it directly.
(integer floating)
Truncates a float value to 64-bit unsigned integer (eg. 42.0
to 42
).
Truncates a float value to 64-bit unsigned integer (eg. `42.0` to `42`).
Reading primitive values from the current position, advancing it as needed. For instance, reading a 32-bit integer will advance the current position by 4 bytes.
Reading primitive values from the current position, advancing it as needed. For instance, reading a 32-bit integer will advance the current position by 4 bytes.
(rr-i8 view)
Reads a signed 8-bit integer from the current position.
Reads a signed 8-bit integer from the current position.
(rr-i32 view)
Reads a signed 32-bit integer from the current position.
Reads a signed 32-bit integer from the current position.
(rr-i64 view)
Reads a signed 64-bit integer from the current position.
Reads a signed 64-bit integer from the current position.
(rr-buffer view n-bytes)
(rr-buffer view n-bytes buffer)
(rr-buffer view n-bytes buffer offset)
Reads n-bytes and returns them in a new buffer or in the given one at the specified offset
(or 0).
Reads n-bytes and returns them in a new buffer or in the given one at the specified `offset` (or 0).
(rr-u8 view)
Reads an unsigned 8-bit integer from the current position.
Reads an unsigned 8-bit integer from the current position.
(rr-u16 view)
Reads an unsigned 16-bit integer from the current position.
Reads an unsigned 16-bit integer from the current position.
(rr-f32 view)
Reads a 32-bit float from the current position.
Reads a 32-bit float from the current position.
(rr-f64 view)
Reads a 64-bit float from the current position.
Reads a 64-bit float from the current position.
(rr-string view n-bytes)
(rr-string view decoder n-bytes)
Reads a string consisting of n-bytes
from the current position.
A decoder may be provided (default is UTF-8).
See text-decoder
Reads a string consisting of `n-bytes` from the current position. A decoder may be provided (default is UTF-8). See [[text-decoder]]
(rr-i16 view)
Reads a signed 16-bit integer from the current position.
Reads a signed 16-bit integer from the current position.
(rr-u32 view)
Reads an unsigned 32-bit integer from the current position.
Reads an unsigned 32-bit integer from the current position.
Writing primitive values to the current position, advancing it as needed. For instance, reading a 64-bit float will advance the current position by 8 bytes.
When writing integers, sign is irrelevant and truncation is automatic.
Writing primitive values to the current position, advancing it as needed. For instance, reading a 64-bit float will advance the current position by 8 bytes. When writing integers, sign is irrelevant and truncation is automatic.
(wr-b16 view integer)
Writes a 16-bit integer to the current position.
Writes a 16-bit integer to the current position.
(wr-b32 view integer)
Writes a 32-bit integer to the current position.
Writes a 32-bit integer to the current position.
(wr-b64 view integer)
Writes a 64-bit integer to the current position.
Writes a 64-bit integer to the current position.
(wr-b8 view integer)
Writes an 8-bit integer to the current position.
Writes an 8-bit integer to the current position.
(wr-buffer view buffer)
(wr-buffer view buffer offset)
(wr-buffer view buffer offset n-bytes)
Copies the given buffer
to the current position.
An offset
in the buffer as well as a number of bytes to copy (n-bytes
) may be provided.
Copies the given `buffer` to the current position. An `offset` in the buffer as well as a number of bytes to copy (`n-bytes`) may be provided.
(wr-f32 view floating)
Writes a 32-bit float to the current position.
Writes a 32-bit float to the current position.
(wr-f64 view floating)
Writes a 64-bit float to the current position.
Writes a 64-bit float to the current position.
(wr-string view string)
Writes a string to the current position, encoded at UTF-8.
Cf. [[wa-string]] about the returned value
Writes a string to the current position, encoded at UTF-8. Cf. [[wa-string]] about the returned value
Additional functions related to views (growing ones as well).
Additional functions related to views (growing ones as well).
(garanteed? view n-bytes)
Is it possible to write at least n-bytes
bytes?
Growing views always return true since they can grow automatically.
Is it possible to write at least `n-bytes` bytes? Growing views always return true since they can grow automatically.
(offset view)
Returns the offset in the original buffer this view starts from.
Views can be counted using Clojure's count
which expresses the number of bytes wrapped by the view
starting from the offset.
Returns the offset in the original buffer this view starts from. Views can be counted using Clojure's `count` which expresses the number of bytes wrapped by the view starting from the offset.
(position view)
Returns the current position.
Returns the current position.
(seek view position)
Modifies the current position.
Modifies the current position.
(skip view n-bytes)
Advances the current position by n-bytes
bytes.
Advances the current position by `n-bytes` bytes.
(to-buffer view)
Returns the buffer wrapped by the view.
Also see [[offset]].
Returns the buffer wrapped by the view. Also see [[offset]].
Building a new view.
Building a new view.
(view view)
(view view offset)
(view view offset n-bytes)
A view can be created from a buffer (see buffer
) or from another view.
An offset
as well as a size (n-bytes
) may be provided.
(def my-buffer
(binf/buffer 100))
;; View with an offset of 50 bytes, 40 bytes long
(def my-view
(binf/view my-buffer
50
40))
;; View from a view, offset of 60 bytes in the original buffer (50 + 10), 20 bytes long
(def inner-view
(binf/view my-view
10
20))
A view can be created from a buffer (see [[buffer]]) or from another view. An `offset` as well as a size (`n-bytes`) may be provided. ```clojure (def my-buffer (binf/buffer 100)) ;; View with an offset of 50 bytes, 40 bytes long (def my-view (binf/view my-buffer 50 40)) ;; View from a view, offset of 60 bytes in the original buffer (50 + 10), 20 bytes long (def inner-view (binf/view my-view 10 20)) ```
(remaining view)
Returns the number of bytes remaining until the end of the view.
In the context of a growing view, this value means the number of bytes before hitting the end of the currently
allocated buffer, which matters for reading. When writing, this value indicates the number of bytes remaining
before reallocating a bigger buffer. See growing-view
.
Returns the number of bytes remaining until the end of the view. In the context of a growing view, this value means the number of bytes before hitting the end of the currently allocated buffer, which matters for reading. When writing, this value indicates the number of bytes remaining before reallocating a bigger buffer. See [[growing-view]].
(text-decode buffer)
(text-decode text-decoder buffer)
Interprets the given buffer
as a string.
A decoder may be provided (see text-decoder
).
Interprets the given `buffer` as a string. A decoder may be provided (see [[text-decoder]]).
(text-decoder)
(text-decoder encoding)
Some functions accepts a text decoder.
Available encodings are: :iso-8859-1
, :utf-8
, :utf-16-be
, :utf-16-le
Default is UTF-8 but argument is non-nilable.
Some functions accepts a text decoder. Available encodings are: `:iso-8859-1`, `:utf-8`, `:utf-16-be`, `:utf-16-le` Default is UTF-8 but argument is non-nilable.
(text-encode string)
Returns a buffer containing the given string
encoded in UTF-8.
Returns a buffer containing the given `string` encoded in UTF-8.
(u16 bits)
(u16 b8-1 b8-2)
Casts the given bits
(any integer) into a 16-bit unsigned integer.
Or recombines the given bytes in big endian order.
Casts the given `bits` (any integer) into a 16-bit unsigned integer. Or recombines the given bytes in big endian order.
(u32 bits)
(u32 b8-1 b8-2 b8-3 b8-4)
Casts the given bits
(any integer) into a 32-bit unsigned integer.
Or recombines the given bytes in big endian order.
Casts the given `bits` (any integer) into a 32-bit unsigned integer. Or recombines the given bytes in big endian order.
(u8 integer)
Casts the given bits
(any integer) into a 8-bit unsigned integer.
Casts the given `bits` (any integer) into a 8-bit unsigned integer.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close