Transit problems with msgpack

60 views
Skip to first unread message

Casper

unread,
Nov 24, 2015, 8:28:20 AM11/24/15
to Clojure

So I have some code that is acting up when using msgpack. I have made a minimal example below, that shows the problem. The code returns -17 (long) when using :msgpack, but decodes correctly when using :json.


My impression was that :msgpack was base64 encoded and could be represented as a string (and logged and so on). Is that not the case, or is something else messing me up when I slurp the ByteArrayInputStream?


Code:


(require '[cognitect.transit :as transit])

(import [java.io ByteArrayInputStream ByteArrayOutputStream])


;; Write data to a stream

(def out (ByteArrayOutputStream.))

(transit/write (transit/writer out :msgpack) {:a [1 2]})


;; Read data from a stream -> string via slurp -> back to InputStream

(def string (slurp (ByteArrayInputStream. (.toByteArray out))))

(prn "Encoded string" string)

(def in (ByteArrayInputStream. 

          (.getBytes string "UTF-8")))

(def reader (transit/reader in :msgpack))

(transit/read reader)


Any idea what is going on? 


/Casper


Reply all
Reply to author
Forward
0 new messages