Polymorphic function for allocate new bytebuffers.
It allows allocate using different implementation of bytebuffers and different types of them.
As example, you may want allocate nio direct buffer of 4 bytes:
(allocate 4 {:type :direct :impl :nio})
The supported options pairs are:
:heap
, impl: :nio
(default):direct
, impl: :nio
:heap
, impl: :netty
:direct
, impl: :netty
:es6
(clojurescript) (default)This function is defined as multimethod and you can extend it with your own bytebuffer implementations if you want or need it.
Polymorphic function for allocate new bytebuffers. It allows allocate using different implementation of bytebuffers and different types of them. As example, you may want allocate nio direct buffer of 4 bytes: (allocate 4 {:type :direct :impl :nio}) The supported options pairs are: - type: `:heap`, impl: `:nio` (default) - type: `:direct`, impl: `:nio` - type: `:heap`, impl: `:netty` - type: `:direct`, impl: `:netty` - impl: `:es6` (clojurescript) (default) This function is defined as multimethod and you can extend it with your own bytebuffer implementations if you want or need it.
(bytes size)
Fixed size byte array type spec constructor.
Fixed size byte array type spec constructor.
(compose constructor types)
Create a composed typespec with user defined type constructor.
This allows define a typespec with automatic conversion between user data type and serialized data without defining yourself a datatype using low level constructions.
Let see an exameple for understand it better.
Imagine you are have this data type:
(defrecord Point [x y])
With help of compose
, create a new spec
for your datatype:
(def point-spec (buf/compose ->Point [buf/int32 buf/int32]))
Now, you can use the previously defined datatype and typespec for write into buffer:
(buf/write! buffer mypoint point-spec)
;; => 8
Or read from the buffer:
(buf/read buffer (point))
;; => #user.Point{:x 1, :y 2}
Create a composed typespec with user defined type constructor. This allows define a typespec with automatic conversion between user data type and serialized data without defining yourself a datatype using low level constructions. Let see an exameple for understand it better. Imagine you are have this data type: (defrecord Point [x y]) With help of `compose`, create a new spec for your datatype: (def point-spec (buf/compose ->Point [buf/int32 buf/int32])) Now, you can use the previously defined datatype and typespec for write into buffer: (buf/write! buffer mypoint point-spec) ;; => 8 Or read from the buffer: (buf/read buffer (point)) ;; => #user.Point{:x 1, :y 2}
(get-capacity _)
Get the read/write capacity in bytes.
Get the read/write capacity in bytes.
(into spec data)
(into spec data opts)
Returns a buffer of exact size of spec with data already serialized.
Returns a buffer of exact size of spec with data already serialized.
(read & args)
Read data from buffer following the specified
spec instance. This function is a friend of read*
and it returns only the readed data.
Read data from buffer following the specified spec instance. This function is a friend of `read*` and it returns only the readed data.
(read* buff spec)
(read* buff spec {:keys [offset] :or {offset 0}})
Read data from buffer following the specified spec instance.
This method returns a vector of readed data
and the data itself. If you need only data,
use read
function instead.
Read data from buffer following the specified spec instance. This method returns a vector of readed data and the data itself. If you need only data, use `read` function instead.
(ref-bytes ref-kw-or-index)
create a dynamic length byte array where the length of the byte array is stored in another spec within the containing indexed spec or associative spec. Example usages: (spec (int16) (int16) (ref-bytes* 1)) (spec :a (int16) :b (int32) (ref-bytes* :b)) where the first example would store the length of the byte array in the second int16 and the second example would store the length of the byte array in the int32 at key :b.
create a dynamic length byte array where the length of the byte array is stored in another spec within the containing indexed spec or associative spec. Example usages: (spec (int16) (int16) (ref-bytes* 1)) (spec :a (int16) :b (int32) (ref-bytes* :b)) where the first example would store the length of the byte array in the second int16 and the second example would store the length of the byte array in the int32 at key :b.
(ref-string ref-kw-or-index)
create a dynamic length string where the length of the string is stored in another spec within the containing indexed spec or associative spec. Example usages: (spec (int16) (int16) (ref-string* 1)) (spec :a (int16) :b (int32) (ref-string* :b)) where the first example would store the length of the string in the second int16 and the second example would store the length of the string in the int32 at key :b.
create a dynamic length string where the length of the string is stored in another spec within the containing indexed spec or associative spec. Example usages: (spec (int16) (int16) (ref-string* 1)) (spec :a (int16) :b (int32) (ref-string* :b)) where the first example would store the length of the string in the second int16 and the second example would store the length of the string in the int32 at key :b.
(repeat n type)
Creare a composed typespec that repeats n
times
a provided type
spec.
As example, create a spec with help of repeat
function:
(def spec (buf/repeat 2 buf/int32))
Write data into buffer using previously defined typespec:
(buf/write! yourbuffer [200 300] spec)
;; => 8
Or read data from your buffer using previously defined typespec:
(buf/read yourbuffer spec)
;; => [200 300]
Creare a composed typespec that repeats `n` times a provided `type` spec. As example, create a spec with help of `repeat` function: (def spec (buf/repeat 2 buf/int32)) Write data into buffer using previously defined typespec: (buf/write! yourbuffer [200 300] spec) ;; => 8 Or read data from your buffer using previously defined typespec: (buf/read yourbuffer spec) ;; => [200 300]
(size _)
Calculate the size in bytes of the object.
Calculate the size in bytes of the object.
(spec & params)
Polymorphic constructor for Spec instances.
Spec is a some kind of composition of arbitrary number of types in associative or indexed data structure.
Little example on how to create associative composition:
(spec :field1 (long)
:field2 (string 20))
An other example on how to create indexed composition that represents the same bytes representation that previous one:
(spec (long) (string 20))
The main difference between the two reprensentation is that if you read a buffer using an associative spec, the result will be clojure hash-map, and if indexed spec is used, the result will be clojure vector containing the values.
The same rules applies for writing data into a buffer.
Polymorphic constructor for Spec instances. Spec is a some kind of composition of arbitrary number of types in associative or indexed data structure. Little example on how to create associative composition: (spec :field1 (long) :field2 (string 20)) An other example on how to create indexed composition that represents the same bytes representation that previous one: (spec (long) (string 20)) The main difference between the two reprensentation is that if you read a buffer using an associative spec, the result will be clojure hash-map, and if indexed spec is used, the result will be clojure vector containing the values. The same rules applies for writing data into a buffer.
(string size)
Fixed length string type spec constructor.
Fixed length string type spec constructor.
Arbitrary length string type spec.
Arbitrary length string type spec.
Unsinged byte type spec.
Unsinged byte type spec.
Unsinged int16 type spec.
Unsinged int16 type spec.
Unsinged int32 type spec.
Unsinged int32 type spec.
Unsinged int64 type spec.
Unsinged int64 type spec.
(vector* t)
Create a arbitrary length (dynamic) array like
typespec composition for t
type.
Create a arbitrary length (dynamic) array like typespec composition for `t` type.
(write! buff data spec)
(write! buff data spec {:keys [offset] :or {offset 0}})
Write data into buffer following the specified spec instance.
Write data into buffer following the specified spec instance.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close