         (into #{} l)))
 
 (defn incognito-read-handlers [read-handlers]
-  {"irecord" (partial record-reader read-handlers)
+  {"record" (record-reader read-handlers)
    "plist"   plist-reader
    "pvec"    pvec-reader
    "set"     set-reader})

(ns incognito.fressian
  (:require [incognito.base :refer [incognito-reader incognito-writer]]
            [fress.api :refer [read-object write-tag write-object]]
            [fress.reader :refer [IFressianReader readInt]]
            [fress.writer :refer [IFressianWriter writeInt]]))

(defn- record-reader [read-handlers reader]
  (let [len (readInt reader)
        tag (read-object reader)
        val (->> (range len)
                 (map (fn [_] (read-object reader)))
                 (map vec)
                 (into {}))]
    (incognito-reader @read-handlers
                      {:tag tag :value val})))

(defn- record-writer [write-handlers writer record]
  (let [{:keys [tag value]} (if (isa? (type record) incognito.base.IncognitoTaggedLiteral)
                              (into {} record) ;; carry on as map
                              (incognito-writer @write-handlers record))]
    (write-tag writer "irecord" 2)
    (writeInt writer (count value))
    (write-object writer tag)
    (doseq [e value]
      (write-object writer e))))

(defn- plist-reader [reader _ _]
  (let [len (readInt reader)]

(defn incognito-write-handlers [write-handlers]
  {cljs.core/List             plist-writer
   cljs.core/EmptyList        plist-writer
   "record"                   (record-writer write-handlers) ;; conversion to pk lib ;:record->name {SomeRecord "SomeRec"
   cljs.core/LazySeq          plist-writer
   cljs.core/PersistentVector pvec-writer})

(comment

  (do
    (prn "---->>> Start Test <<<<------")
    (defrecord SomeRecord [f1 f2]) ; map->SomeRecord is now implicitly def3ned
    (def rec (SomeRecord. "field1" "field2"))
    (def buf (fress.api/byte-stream))
    (def writer (fress.api/create-writer buf :handlers
                                         (incognito-write-handlers (atom {'incognito.fressian.SomeRecord (fn [foo] (println "foos") (assoc foo :c "donkey"))})) ))

    (prn "write object------------")
    (w/writeObject writer rec)
    (prn "read object------------")
    (prn (fress.api/read buf :handlers (incognito-read-handlers (atom {}))))
    (prn "---->>> End Test <<<<------"))



)
