[nop] Housekeeping

This commit is contained in:
Peter Taoussanis 2024-05-26 14:27:51 +02:00
parent bb178f66fc
commit c0d1da1bb4
4 changed files with 27 additions and 23 deletions

View file

@ -19,6 +19,8 @@ Notes:
\- [Peter Taoussanis](https://www.taoensso.com)
---
# `v3.4.1` (2024-05-02)
> **Dep**: Nippy is [on Clojars](https://clojars.org/com.taoensso/nippy/versions/3.4.1).

View file

@ -1,5 +1,5 @@
<a href="https://www.taoensso.com/clojure" title="More stuff by @ptaoussanis at www.taoensso.com"><img src="https://www.taoensso.com/open-source.png" alt="Taoensso open source" width="340"/></a>
[**Documentation**](#documentation) | [Latest releases](#latest-releases) | [Get support][GitHub issues]
[**API**][cljdoc docs] | [**Wiki**][GitHub wiki] | [Latest releases](#latest-releases) | [Get support][GitHub issues]
# Nippy

View file

@ -25,7 +25,7 @@
PersistentQueue PersistentTreeMap PersistentTreeSet PersistentList
MapEntry LazySeq IRecord ISeq IType]))
(enc/assert-min-encore-version [3 112 0])
(enc/assert-min-encore-version [3 127 0])
(comment
(set! *unchecked-math* :warn-on-boxed)
@ -300,14 +300,14 @@
- `payload-spec` examples:
- nil ; No spec available (e.g. unpredictable payload)
- [] ; Type has no payload
- [[:bytes 4]] ; Type has a payload of exactly 4 bytes
- [[:bytes 2] [:elements 2]] ; Type has a payload of exactly 2 bytes, then
; 2 elements
- [[:bytes 4]] ; Type has payload of exactly 4 bytes
- [[:bytes 2] [:elements 2]] ; Type has payload of exactly 2 bytes,
; followed by 2 elements
- [[:bytes {:read 2}]
[:elements {:read 4 :multiplier 2 :unsigned? true}]]
; Type has payload of <short-count> bytes, then
; Type has payload of <short-count> bytes, followed by
; <unsigned-int-count>*2 (multiplier) elements
Note that `payload-spec` can be handy for skipping over items in
@ -1254,7 +1254,7 @@
- :compressor nil
- :encryptor nil
- :no-header? true"
[x]
^bytes [x]
(let [baos (ByteArrayOutputStream. 64)
dos (DataOutputStream. baos)]
(with-cache (-freeze-with-meta! x dos))
@ -1263,11 +1263,13 @@
(defn freeze
"Serializes arg (any Clojure data type) to a byte array.
To freeze custom types, extend the Clojure reader or see `extend-freeze`."
([x] (freeze x nil))
([x {:as opts
:keys [compressor encryptor password serializable-allowlist incl-metadata?]
:or {compressor :auto
encryptor aes128-gcm-encryptor}}]
(^bytes [x] (freeze x nil))
(^bytes
[x
{:as opts
:keys [compressor encryptor password serializable-allowlist incl-metadata?]
:or {compressor :auto
encryptor aes128-gcm-encryptor}}]
(call-with-bindings :freeze opts
(fn []

View file

@ -11,10 +11,10 @@
(def ^:dynamic *thaw-opts* nil)
(do
(defmacro with-freeze-opts [opts & body] `(binding [*freeze-opts* ~opts ] ~@body))
(defmacro with-freeze-opts+ [opts & body] `(binding [*freeze-opts* (enc/fast-merge *freeze-opts* ~opts)] ~@body))
(defmacro with-thaw-opts [opts & body] `(binding [*thaw-opts* ~opts ] ~@body))
(defmacro with-thaw-opts+ [opts & body] `(binding [*thaw-opts* (enc/fast-merge *thaw-opts* ~opts)] ~@body)))
(defmacro with-freeze-opts [opts & body] `(binding [*freeze-opts* ~opts ] ~@body))
(defmacro with-freeze-opts+ [opts & body] `(binding [*freeze-opts* (enc/merge *freeze-opts* ~opts)] ~@body))
(defmacro with-thaw-opts [opts & body] `(binding [*thaw-opts* ~opts ] ~@body))
(defmacro with-thaw-opts+ [opts & body] `(binding [*thaw-opts* (enc/merge *thaw-opts* ~opts)] ~@body)))
(deftype WrappedForFreezing [val opts])
(defn wrapped-for-freezing? [x] (instance? WrappedForFreezing x))
@ -27,7 +27,7 @@
See also `tools/freeze`."
([x ] (wrap-for-freezing x nil))
([x wrap-opts]
(let [captured-opts (enc/fast-merge *freeze-opts* wrap-opts)] ; wrap > dynamic
(let [captured-opts (enc/merge *freeze-opts* wrap-opts)] ; wrap > dynamic
(if (instance? WrappedForFreezing x)
(let [^WrappedForFreezing x x]
(if (= (.-opts x) captured-opts)
@ -46,13 +46,13 @@
See also `tools/wrap-for-freezing`."
([x ] (freeze x nil))
([x default-opts]
(let [default-opts (get default-opts :default-opts default-opts) ; Back compatibility
active-opts (enc/fast-merge default-opts *freeze-opts*)] ; dynamic > default
(let [default-opts (get default-opts :default-opts default-opts) ; Back compatibility
active-opts (enc/merge default-opts *freeze-opts*)] ; dynamic > default
(if (instance? WrappedForFreezing x)
(let [^WrappedForFreezing x x]
(nippy/freeze (.-val x) (enc/fast-merge active-opts (.-opts x)))) ; captured > active!
(nippy/freeze x active-opts)))))
(nippy/freeze (.-val x) (enc/merge active-opts (.-opts x)))) ; captured > active!
(nippy/freeze x active-opts)))))
(defn thaw
"Like `nippy/thaw` but uses as options the following, merged in
@ -62,8 +62,8 @@
2. `tools/*thaw-opts*` dynamic value (default nil)."
([ba ] (thaw ba nil))
([ba default-opts]
(let [default-opts (get default-opts :default-opts default-opts) ; Back compatibility
active-opts (enc/fast-merge default-opts *thaw-opts*)] ; dynamic > default
(let [default-opts (get default-opts :default-opts default-opts) ; Back compatibility
active-opts (enc/merge default-opts *thaw-opts*)] ; dynamic > default
(nippy/thaw ba active-opts))))