 
 (ns uxbox.util.transit
   (:require [cognitect.transit :as t]
+            [catacumba.handlers.parse :as cparse]
             [uxbox.util.time :as dt])
-  (:import java.io.ByteArrayInputStream
+  (:import ratpack.http.TypedData
+           ratpack.handling.Context
+           java.io.ByteArrayInputStream
            java.io.ByteArrayOutputStream))
 
 ;; --- Handlers

(def ^:private +write-handlers+
  dt/+write-handlers+)

;; --- Public Api

(defn reader
  ([istream]

  [writer data]
  (t/write writer data))


;; --- Catacumba Extension

(defmethod cparse/parse-body :application/transit+json
  [^Context ctx ^TypedData body]
  (let [reader (reader (.getInputStream body) {:type :json})]
    (read! reader)))

;; --- High-Level Api

(defn decode
  ([data]
   (decode data nil))
