smee / binary

Clojure API for binary format I/O using java's stream apis
74 stars 10 forks source link

Public BinaryIO protocol or codec for `nil` #19

Open darkleaf opened 5 years ago

darkleaf commented 5 years ago

Thanks for awesome library!

I need to serialize no value in some cases. For example:

(b/header :int-be
          (fn header->body-codec [length]
            (if (= -1 length)
              codec/null
              (b/blob :length length)))
          "not used")

So I add null codec. But it's ugly:

;; hack
(def null
  (b/compile-codec
   (byte-array 0)
   (constantly (byte-array 0))
   (constantly nil)))

Is it possible to make public BinaryIO protocol or add nil primitive codec?