funcool

A channel for discussing and asking questions about Funcool libraries https://github.com/funcool/
niwinz 2015-12-08T12:02:48.000156Z

[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

niwinz 2015-12-08T12:25:50.000158Z

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

👍 1
niwinz 2015-12-08T12:25:56.000159Z

maybe some will find it useful

niwinz 2015-12-08T12:26:42.000160Z

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

2015-12-08T16:05:58.000162Z

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

2015-12-08T16:06:13.000163Z

I get the exception:

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

2015-12-08T16:07:03.000164Z

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

niwinz 2015-12-08T17:08:53.000165Z

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

niwinz 2015-12-08T17:09:13.000166Z

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

niwinz 2015-12-08T17:09:40.000167Z

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

niwinz 2015-12-08T17:10:14.000168Z

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

niwinz 2015-12-08T17:10:40.000169Z

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

niwinz 2015-12-08T17:11:52.000170Z

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

2015-12-08T17:18:33.000171Z

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

2015-12-08T17:19:55.000172Z

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

2015-12-08T17:21:01.000173Z

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?

niwinz 2015-12-08T17:25:37.000174Z

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:

niwinz 2015-12-08T17:25:44.000175Z

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

niwinz 2015-12-08T17:26:54.000177Z

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

2015-12-08T17:28:13.000178Z

YES

2015-12-08T17:29:22.000179Z

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

2015-12-08T17:30:54.000181Z

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

2015-12-08T17:31:37.000182Z

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

(def buffer (buf/allocate 24))

niwinz 2015-12-08T18:21:15.000184Z

buffer is the concept

niwinz 2015-12-08T18:21:25.000185Z

it there are different implementations

niwinz 2015-12-08T18:21:35.000186Z

bytebuffer is the JDK native buffer implementation

niwinz 2015-12-08T18:21:48.000187Z

netty has its own and is also supported in octet

niwinz 2015-12-08T18:22:00.000188Z

as it is cross platform

niwinz 2015-12-08T18:22:23.000189Z

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

2015-12-08T18:34:24.000190Z

got it now 👍:skin-tone-3: