Skip to content

Instantly share code, notes, and snippets.

@joshrotenberg
Created January 4, 2012 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshrotenberg/8c3da82eb9183baae5b1 to your computer and use it in GitHub Desktop.
Save joshrotenberg/8c3da82eb9183baae5b1 to your computer and use it in GitHub Desktop.
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