diff --git a/CHANGELOG.md b/CHANGELOG.md index eed2d81..cb2e3b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## WIP / 2013-12-03 + +WIP + +### Features + * Added experimental `inspect-ba` fn for examining data possibly frozen by Nippy. + +### Changes + * + +### Fixes + * + + ## v2.4.1 → v2.5.0 * Refactored standard Freezable protocol implementations to de-emphasise interfaces as a matter of hygiene, Ref. http://goo.gl/IFXzvh. * BETA STATUS: Added an additional (pre-Reader) Serializable fallback. This should greatly extend the number of out-the-box-serializable types. diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index 3b5da4d..9514057 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -266,6 +266,8 @@ (defn- thaw-from-stream [^DataInputStream s] (let [type-id (.readByte s)] + #_(when debug-mode? + (println (format "DEBUG - thawing type-id: %s" type-id))) (utils/case-eval type-id id-reader (edn/read-string {:readers *data-readers*} (read-utf8 s)) @@ -531,6 +533,34 @@ :exception (try (/ 1 0) (catch Exception e e)) :ex-info (ex-info "ExInfo" {:data "data"})})) +;;;; Data recovery/analysis + +(defn inspect-ba "Alpha - subject to change." + [ba & [thaw-opts]] + (if-not (utils/bytes? ba) :not-ba + (let [[first2bytes nextbytes] (utils/ba-split ba 2) + known-wrapper + (cond + (utils/ba= first2bytes (.getBytes "\u0000<" "UTF8")) :carmine/bin + (utils/ba= first2bytes (.getBytes "\u0000>" "UTF8")) :carmine/clj) + + unwrapped-ba (if known-wrapper nextbytes ba) + [data-ba nippy-header] (or (try-parse-header unwrapped-ba) + [unwrapped-ba :no-header])] + + {:known-wrapper known-wrapper + :nippy2-header nippy-header ; Nippy v1.x didn't have a header + :thawable? (try (thaw unwrapped-ba thaw-opts) true + (catch Exception _ false)) + :unwrapped-ba unwrapped-ba + :data-ba data-ba + :unwrapped-size (alength ^bytes unwrapped-ba) + :ba-size (alength ^bytes ba) + :data-size (alength ^bytes data-ba)}))) + +(comment (inspect-ba (freeze "hello")) + (seq (:data-ba (inspect-ba (freeze "hello"))))) + ;;;; Deprecated API (defn- assert-legacy-args [compressor password] diff --git a/src/taoensso/nippy/utils.clj b/src/taoensso/nippy/utils.clj index 4f4ea8a..b695aff 100644 --- a/src/taoensso/nippy/utils.clj +++ b/src/taoensso/nippy/utils.clj @@ -74,6 +74,8 @@ (comment (memoized nil +) (memoized nil + 5 12)) +(def ^:const bytes-class (Class/forName "[B")) +(defn bytes? [x] (instance? bytes-class x)) (defn ba= [^bytes x ^bytes y] (java.util.Arrays/equals x y)) (defn ba-concat ^bytes [^bytes ba1 ^bytes ba2]