Core namespace for handling views.
See README for an overview.
Core namespace for handling views. See README for an overview.
(backing-buffer view)
Returns the buffer of view
if it does wrap one, nil otherwise.
It is possible to implement some protocols of this library over something that does not have a backing buffer.
Actually, on the JVM, a DirectByteBuffer
is an example of a supported view which operates over native memory
instead of a Java byte array (ie. a "buffer").
Returns the buffer of `view` if it does wrap one, nil otherwise. It is possible to implement some protocols of this library over something that does not have a backing buffer. Actually, on the JVM, a `DirectByteBuffer` is an example of a supported view which operates over native memory instead of a Java byte array (ie. a "buffer").
(buffer-offset view)
Returns the offset relative to the backing buffer, nil if there is not any.
See backing-buffer
for background.
Returns the offset relative to the backing buffer, nil if there is not any. See [[backing-buffer]] for background.
(endian-get view)
Returns the endianess of the given view
, either :big-endian
or :little-endian
.
Returns the endianess of the given `view`, either `:big-endian` or `:little-endian`.
(endian-set view endianess)
Sets the endianess of the given view
, either :big-endian
or :little-endian
.
Sets the endianess of the given `view`, either `:big-endian` or `:little-endian`.
(garanteed? view n-byte)
Returns true if the view
can consume at least n-byte
bytes from the current position.
Returns true if the `view` can consume at least `n-byte` bytes from the current position.
(grow view n-additional-byte)
Returns a new view with n-additional-byte
added, copying entirely the given view
.
It is particularly useful when writing data of yet unknown length, providing the ability of growing as needed.
Returns a new view with `n-additional-byte` added, copying entirely the given `view`. It is particularly useful when writing data of yet unknown length, providing the ability of growing as needed.
(limit view)
Returns the number of bytes a view or a buffer contains.
Returns the number of bytes a view or a buffer contains.
(position view)
Returns the current position.
Returns the current position.
(ra-bool view position)
Reads a boolean value from an absolute position
.
Reads a boolean value from an absolute `position`.
(ra-buffer this position n-byte)
(ra-buffer this position n-byte buffer)
(ra-buffer view position n-byte buffer offset)
Reads n-byte
bytes from an absolute position
and returns them in a new buffer or in the
given buffer
at the specified offset
(defaults to 0).
Reads `n-byte` bytes from an absolute `position` and returns them in a new buffer or in the given `buffer` at the specified `offset` (defaults to 0).
(ra-f32 view position)
Reads a 32-bit float from an absolute position
.
Reads a 32-bit float from an absolute `position`.
(ra-f64 view position)
Reads a 64-bit float from an absolute position
.
Reads a 64-bit float 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`.
(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-i64 view position)
Reads a signed 64-bit integer from an absolute position
.
Reads a signed 64-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-string view position n-byte)
(ra-string view decoder position n-byte)
Reads a string consisting of n-byte
bytes from an absolute position
.
A string decoder may be provided (default is UTF-8).
Reads a string consisting of `n-byte` bytes from an absolute `position`. A string decoder may be provided (default is UTF-8). See [[helins.binf.string/decoder]].
(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-u32 view position)
Reads an unsigned 32-bit integer from an absolute position
.
Reads an unsigned 32-bit integer from an absolute `position`.
(ra-u64 view position)
Reads an unsigned 64-bit integer from an absolute position
.
Reads an unsigned 64-bit integer from an absolute `position`.
(ra-u8 view position)
Reads an unsigned 8-bit integer from an absolute position
.
Reads an unsigned 8-bit integer from an absolute `position`.
(remaining view)
Returns the number of bytes remaining until the end of the view given the current position.
Returns the number of bytes remaining until the end of the view given the current position.
(rr-bool view)
Reads a boolean value from the current position.
Reads a boolean value from the current position.
(rr-buffer view n-byte)
(rr-buffer view n-byte buffer)
(rr-buffer view n-byte buffer offset)
Reads n-byte
and returns them in a new buffer or in the given one at the specified offset
(defaults to 0).
Reads `n-byte` and returns them in a new buffer or in the given one at the specified `offset` (defaults to 0).
(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-i16 view)
Reads a signed 16-bit integer from the current position.
Reads a signed 16-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-i8 view)
Reads a signed 8-bit integer from the current position.
Reads a signed 8-bit integer from the current position.
(rr-string view n-byte)
(rr-string view decoder n-byte)
Reads a string consisting of n-byte
bytes from the current position.
A non-nil decoder may be provided (default is UTF-8).
Reads a string consisting of `n-byte` bytes from the current position. A non-nil decoder may be provided (default is UTF-8). See [[helins.binf.string/decoder]].
(rr-u16 view)
Reads an unsigned 16-bit integer from the current position.
Reads an unsigned 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.
(rr-u64 view)
Reads an unsigned 64-bit integer from the current position.
Reads an unsigned 64-bit integer from the current position.
(rr-u8 view)
Reads an unsigned 8-bit integer from the current position.
Reads an unsigned 8-bit integer from the current position.
(seek view position)
Modifies the current position.
Modifies the current position.
(skip view n-byte)
Advances the current position by n-byte
bytes.
Advances the current position by `n-byte` bytes.
(view viewable)
(view viewable offset)
(view viewable offset n-byte)
A view can be created from a buffer (see helins.binf.buffer/alloc
) or from another view.
An offset
as well as a size (n-byte
) may be provided.
(def my-buffer
(binf.buffer/alloc 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 [[helins.binf.buffer/alloc]]) or from another view. An `offset` as well as a size (`n-byte`) may be provided. ```clojure (def my-buffer (binf.buffer/alloc 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)) ```
(wa-b16 view position int)
Writes a 16-bit integer to an absolute position
.
Writes a 16-bit integer to an absolute `position`.
(wa-b32 view position int)
Writes a 32-bit integer to an absolute position
.
Writes a 32-bit integer to an absolute `position`.
(wa-b64 view position int64)
Writes a 64-bit integer to an absolute position
.
Writes a 64-bit integer to an absolute `position`.
(wa-b8 view position int)
Writes an 8-bit integer to an absolute position.
Writes an 8-bit integer to an absolute position.
(wa-bool view position true?)
Writes a boolean value to an absolute position
.
Writes a boolean value to an absolute `position`.
(wa-buffer view position buffer)
(wa-buffer view position buffer offset)
(wa-buffer view position buffer offset n-byte)
Copies the given buffer
to an absolute position
.
An offset
in the buffer as well as a number of bytes to copy (n-byte
) 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-byte`) 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 wa-*
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-byte 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.
Writes a string (encoded as UTF-8) to an absolute `position`. Unlike other `wa-*` 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-byte 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.
(wr-b16 view int)
Writes a 16-bit integer to the current position.
Writes a 16-bit integer to the current position.
(wr-b32 view int)
Writes a 32-bit integer to the current position.
Writes a 32-bit integer to the current position.
(wr-b64 view int)
Writes a 64-bit integer to the current position.
Writes a 64-bit integer to the current position.
(wr-b8 view int)
Writes an 8-bit integer to the current position.
Writes an 8-bit integer to the current position.
(wr-bool view true?)
Writes a boolean value from the current position.
Writes a boolean value from the current position.
(wr-buffer view buffer)
(wr-buffer view buffer offset)
(wr-buffer view buffer offset n-byte)
Copies the given buffer
to the current position.
An offset
in the buffer as well as a number of bytes to copy (n-byte
) 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-byte`) 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
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close