Add native support for java.time.Duration
This commit is contained in:
parent
5097e16727
commit
6dd21e0e15
2 changed files with 42 additions and 11 deletions
|
|
@ -107,7 +107,9 @@ nippy/stress-data
|
||||||
:ratio 22/7
|
:ratio 22/7
|
||||||
:uuid (java.util.UUID/randomUUID)
|
:uuid (java.util.UUID/randomUUID)
|
||||||
:date (java.util.Date.)
|
:date (java.util.Date.)
|
||||||
|
|
||||||
:time-instant (java.time.Instant/now) ; JVM 8+
|
:time-instant (java.time.Instant/now) ; JVM 8+
|
||||||
|
:time-duration (java.time.Duration/ofSeconds 100) ; ''
|
||||||
|
|
||||||
:objects (object-array [1 "two" {:data "data"}])
|
:objects (object-array [1 "two" {:data "data"}])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,7 @@
|
||||||
68 :cached-md
|
68 :cached-md
|
||||||
|
|
||||||
79 :time-instant ; JVM 8+
|
79 :time-instant ; JVM 8+
|
||||||
|
83 :time-duration ; ''
|
||||||
|
|
||||||
;;; DEPRECATED (only support thawing)
|
;;; DEPRECATED (only support thawing)
|
||||||
5 :reader-lg2 ; == :reader-lg, used only for back-compatible thawing
|
5 :reader-lg2 ; == :reader-lg, used only for back-compatible thawing
|
||||||
|
|
@ -1198,6 +1199,12 @@
|
||||||
(.writeInt out (.getNano x)))
|
(.writeInt out (.getNano x)))
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
|
(enc/compile-if java.time.Duration
|
||||||
|
(id-freezer java.time.Duration id-time-duration
|
||||||
|
(.writeLong out (.getSeconds x))
|
||||||
|
(.writeInt out (.getNano x)))
|
||||||
|
nil)
|
||||||
|
|
||||||
(freezer Object
|
(freezer Object
|
||||||
(when-debug (println (str "freeze-fallback: " (type x))))
|
(when-debug (println (str "freeze-fallback: " (type x))))
|
||||||
(if-let [ff *freeze-fallback*]
|
(if-let [ff *freeze-fallback*]
|
||||||
|
|
@ -1675,14 +1682,30 @@
|
||||||
id-uuid (UUID. (.readLong in) (.readLong in))
|
id-uuid (UUID. (.readLong in) (.readLong in))
|
||||||
|
|
||||||
id-time-instant
|
id-time-instant
|
||||||
|
(let [secs (.readLong in)
|
||||||
|
nanos (.readInt in)]
|
||||||
|
|
||||||
(enc/compile-if java.time.Instant
|
(enc/compile-if java.time.Instant
|
||||||
(java.time.Instant/ofEpochSecond (.readLong in) (.readInt in))
|
(java.time.Instant/ofEpochSecond secs nanos)
|
||||||
{:nippy/unthawable
|
{:nippy/unthawable
|
||||||
{:type :class
|
{:type :class
|
||||||
:cause :class-not-found
|
:cause :class-not-found
|
||||||
|
|
||||||
:class-name "java.time.Instant"
|
:class-name "java.time.Instant"
|
||||||
:content {:epoch-second (.readLong in) :nano (.readInt in)}}})
|
:content {:epoch-second secs :nano nanos}}}))
|
||||||
|
|
||||||
|
id-time-duration
|
||||||
|
(let [secs (.readLong in)
|
||||||
|
nanos (.readInt in)]
|
||||||
|
|
||||||
|
(enc/compile-if java.time.Duration
|
||||||
|
(java.time.Duration/ofSeconds secs nanos)
|
||||||
|
{:nippy/unthawable
|
||||||
|
{:type :class
|
||||||
|
:cause :class-not-found
|
||||||
|
|
||||||
|
:class-name "java.time.Duration"
|
||||||
|
:content {:seconds secs :nanos nanos}}}))
|
||||||
|
|
||||||
;; Deprecated ------------------------------------------------------
|
;; Deprecated ------------------------------------------------------
|
||||||
id-boolean-depr1 (.readBoolean in)
|
id-boolean-depr1 (.readBoolean in)
|
||||||
|
|
@ -2008,11 +2031,17 @@
|
||||||
:uri (URI. "https://clojure.org/reference/data_structures")
|
:uri (URI. "https://clojure.org/reference/data_structures")
|
||||||
:uuid (java.util.UUID/randomUUID)
|
:uuid (java.util.UUID/randomUUID)
|
||||||
:date (java.util.Date.)
|
:date (java.util.Date.)
|
||||||
|
|
||||||
:time-instant ; JVM 8+
|
:time-instant ; JVM 8+
|
||||||
(enc/compile-if java.time.Instant
|
(enc/compile-if java.time.Instant
|
||||||
(java.time.Instant/now)
|
(java.time.Instant/now)
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
|
:time-duration ; JVM 8+
|
||||||
|
(enc/compile-if java.time.Duration
|
||||||
|
(java.time.Duration/ofSeconds 100 100)
|
||||||
|
nil)
|
||||||
|
|
||||||
:objects (object-array [1 "two" {:data "data"}])
|
:objects (object-array [1 "two" {:data "data"}])
|
||||||
|
|
||||||
:stress-record (StressRecord. "data")
|
:stress-record (StressRecord. "data")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue