Fork me on GitHub
#funcool
<
2015-12-08
>
niwinz12:12:48

[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

niwinz12:12:50

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

niwinz12:12:56

maybe some will find it useful

niwinz12:12:42

It is based on some ideas from one talk of clojureXchang and some own ideas (mine and my friends)

hoopes16:12:58

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))))

hoopes16:12:13

I get the exception:

IllegalArgumentException Don't know how to create ISeq from: java.nio.HeapByteBuffer  clojure.lang.RT.seqFrom (RT.java:528)

hoopes16:12:03

Seems to be the wrong type for b - what data type should I be converted b to? Thanks!

niwinz17:12:53

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)})

niwinz17:12:13

and it will return a buffer (you should not create it, into already does it for you

niwinz17:12:40

in case you want write data to an existing buffer, you should use write! function

niwinz17:12:14

(o/write! b {:model-field (byte 0)} spec)

niwinz17:12:40

The {:model-field (byte 0)} used in my example is a sample data, you should replace it with your data in your code..

niwinz17:12:52

@hoopes: if you explain better that you intend to do in your code, maybe I can give you better help.

hoopes17:12:33

i'm trying to take a byte array i recv over the network, and convert it into something useful to work with

hoopes17:12:55

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

hoopes17:12:01

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?

niwinz17:12:37

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:

niwinz17:12:44

(let [b (ByteBuffer/wrap incoming-array)
      spec (o/spec :model-field o/byte)]
  (o/read b spec))
;; => {:model-field 4}

niwinz17:12:54

The read function takes a buffer and spec and tries read data from buffer following the spec 😉

hoopes17:12:22

oh man - thanks again - you're hooking me up, i really appreciate your time

hoopes17:12:54

in that section, buffer is referring just to some ByteBuffer?

hoopes17:12:37

i was reading that following the previous section, which had something like

(def buffer (buf/allocate 24))

niwinz18:12:15

buffer is the concept

niwinz18:12:25

it there are different implementations

niwinz18:12:35

bytebuffer is the JDK native buffer implementation

niwinz18:12:48

netty has its own and is also supported in octet

niwinz18:12:00

as it is cross platform

niwinz18:12:23

the ES2015 (ES6) typed arrays are also supported in the clojurescript

hoopes18:12:24

got it now 👍:skin-tone-3: