Update ba inspector

This commit is contained in:
Peter Taoussanis 2015-09-29 23:06:33 +07:00
parent 7faaf48ee7
commit c5901730ea

View file

@ -882,29 +882,31 @@
;;;; Tools ;;;; Tools
(defn inspect-ba "Alpha - subject to change" (defn inspect-ba "Alpha - subject to change"
[ba & [thaw-opts]] ([ba ] (inspect-ba ba nil))
(if-not (enc/bytes? ba) :not-ba ([ba thaw-opts]
(when (enc/bytes? ba)
(let [[first2bytes nextbytes] (enc/ba-split ba 2) (let [[first2bytes nextbytes] (enc/ba-split ba 2)
known-wrapper ?known-wrapper
(cond (cond
(enc/ba= first2bytes (.getBytes "\u0000<" "UTF8")) :carmine/bin (enc/ba= first2bytes (.getBytes "\u0000<" "UTF8")) :carmine/bin
(enc/ba= first2bytes (.getBytes "\u0000>" "UTF8")) :carmine/clj) (enc/ba= first2bytes (.getBytes "\u0000>" "UTF8")) :carmine/clj)
unwrapped-ba (if known-wrapper nextbytes ba) unwrapped-ba (if ?known-wrapper nextbytes ba)
[data-ba nippy-header] (or (try-parse-header unwrapped-ba) [data-ba ?nippy-header] (or (try-parse-header unwrapped-ba)
[unwrapped-ba :no-header])] [unwrapped-ba :no-header])]
{:known-wrapper known-wrapper {:?known-wrapper ?known-wrapper
:nippy-v2-header nippy-header ; Nippy v1.x didn't have a header :?header ?nippy-header
:thawable? (try (thaw unwrapped-ba thaw-opts) true :thawable? (try (thaw unwrapped-ba thaw-opts) true
(catch Exception _ false)) (catch Exception _ false))
:unwrapped-ba unwrapped-ba :unwrapped-ba unwrapped-ba
:data-ba data-ba :data-ba data-ba
:unwrapped-len (alength ^bytes unwrapped-ba) :unwrapped-len (alength ^bytes unwrapped-ba)
:ba-len (alength ^bytes ba) :ba-len (alength ^bytes ba)
:data-len (alength ^bytes data-ba)}))) :data-len (alength ^bytes data-ba)}))))
(comment (inspect-ba (freeze "hello")) (comment
(inspect-ba (freeze "hello"))
(seq (:data-ba (inspect-ba (freeze "hello"))))) (seq (:data-ba (inspect-ba (freeze "hello")))))
;;;; Deprecated ;;;; Deprecated