Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
gloss problem
(use 'gloss.io 'gloss.core)
(defcodec r {:m (string :utf-8 :length 4)
:t :uint32
:s :uint32
:d (string :utf-8)})
(def g (encode r {:m "food" :t 2 :s 4 :d "barf"}))
;;user> g
;;(#<HeapByteBuffer java.nio.HeapByteBuffer[pos=0 lim=4 cap=4]> #<HeapByteBuffer java.nio.HeapByteBuffer[pos=0 lim=4 cap=4]> #<HeapByteBuffer java.nio.HeapByteBuffer[pos=0 lim=4 cap=4]> #<HeapByteBuffer java.nio.HeapByteBuffer[pos=0 lim=4 cap=4]>)
(decode r g)
;;Insufficient bytes to decode frame.
;; [Thrown class java.lang.Exception]
;; same issue with code from the gloss wiki
(defcodec animal (enum :int16 :dog :cat :horse))
(defcodec pet
{:name (string :utf-8 :delimiter "\n")
:type animal})
(def goober (encode pet {:name "goober" :type :cat}))
(decode pet goober)
Insufficient bytes to decode frame.
[Thrown class java.lang.Exception]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment