[ann] beicon 0.3.0 released. It comes with some bugfixes and great bunch of new functions. It also comes with much better externs files / https://github.com/funcool/beicon
And here a gist on how beicon can be used for manage reactivelly the state on cljs web apps: https://gist.github.com/niwinz/0301331bee4d5148330c
maybe some will find it useful
It is based on some ideas from one talk of clojureXchang and some own ideas (mine and my friends)
Hi! I'm trying to use octet to handle some binary data. I know I'm missing something simple. Here is my current function:
(defn handle [byte-arr]
(println "Handling byte str")
(let [b (ByteBuffer/wrap byte-arr)
spec (o/spec :mode-field o/byte)
buf (o/into spec b)]
(println (o/read buf spec))))
I get the exception:
IllegalArgumentException Don't know how to create ISeq from: java.nio.HeapByteBuffer clojure.lang.RT.seqFrom (RT.java:528)
Seems to be the wrong type for b - what data type should I be converted b to? Thanks!
The into
function serves for write data into ad-hoc created byte buffer. A proper example will be (o/into spec {:mode-field (byte 0)})
and it will return a buffer (you should not create it, into
already does it for you
in case you want write data to an existing buffer, you should use write!
function
(o/write! b {:model-field (byte 0)} spec)
The {:model-field (byte 0)}
used in my example is a sample data, you should replace it with your data in your code..
@hoopes: if you explain better that you intend to do in your code, maybe I can give you better help.
i'm trying to take a byte array i recv over the network, and convert it into something useful to work with
so if i had a byte array with [4] in it, in the body of that let form, i'd be able to say something like
(if (= (:mode-field buf) 4)) ..... do something
basically, take a byte array, and convert it to a map - parse the byte array into a data structure :simple_smile: does that make any sense?
If you just want read a byte array that comes from network and it is expected tha it will contain one byte, the process should be the following:
(let [b (ByteBuffer/wrap incoming-array)
spec (o/spec :model-field o/byte)]
(o/read b spec))
;; => {:model-field 4}
The read function takes a buffer and spec and tries read data from buffer following the spec 😉
YES
oh man - thanks again - you're hooking me up, i really appreciate your time
in that section, buffer is referring just to some ByteBuffer?
i was reading that following the previous section, which had something like
(def buffer (buf/allocate 24))
buffer is the concept
it there are different implementations
bytebuffer is the JDK native buffer implementation
netty has its own and is also supported in octet
as it is cross platform
the ES2015 (ES6) typed arrays are also supported in the clojurescript
got it now 👍:skin-tone-3: