|
145 | 145 | 51 [:reader-md [[:bytes {:read 2}]]] |
146 | 146 | 52 [:reader-lg [[:bytes {:read 4}]]] |
147 | 147 |
|
148 | | - 53 [:bytes-0 []] |
149 | | - 7 [:bytes-sm [[:bytes {:read 1}]]] |
150 | | - 15 [:bytes-md [[:bytes {:read 2}]]] |
151 | | - 2 [:bytes-lg [[:bytes {:read 4}]]] |
152 | | - |
153 | 148 | 17 [:vec-0 []] |
154 | 149 | 113 [:vec-2 [[:elements 2]]] |
155 | 150 | 114 [:vec-3 [[:elements 3]]] |
|
182 | 177 | 28 [:sorted-set-lg [[:elements {:read 4}]]] |
183 | 178 | 31 [:sorted-map-lg [[:elements {:read 4 :multiplier 2}]]] |
184 | 179 | 26 [:queue-lg [[:elements {:read 4}]]] |
185 | | - 115 [:objects-lg [[:elements {:read 4}]]] |
186 | 180 |
|
187 | 181 | 25 [:meta [[:elements 1]]] |
188 | 182 | 58 [:regex [[:elements 1]]] |
|
196 | 190 | 70 [:ratio [[:bytes {:read 4}] |
197 | 191 | [:bytes {:read 4}]]] |
198 | 192 |
|
| 193 | + ;; Arrays |
| 194 | + 53 [:byte-array-0 []] |
| 195 | + 7 [:byte-array-sm [[:elements {:read 1}]]] |
| 196 | + 15 [:byte-array-md [[:elements {:read 2}]]] |
| 197 | + 2 [:byte-array-lg [[:elements {:read 4}]]] |
| 198 | + 109 [:int-array-lg [[:elements {:read 4}]]] ; Added vX.Y.Z (YYYY-MM-DD) |
| 199 | + 108 [:long-array-lg [[:elements {:read 4}]]] ; Added vX.Y.Z (YYYY-MM-DD) |
| 200 | + 107 [:string-array-lg [[:elements {:read 4}]]] ; Added vX.Y.Z (YYYY-MM-DD) |
| 201 | + 115 [:object-array-lg [[:elements {:read 4}]]] |
| 202 | + |
199 | 203 | ;; Serializable |
200 | 204 | 75 [:sz-quarantined-sm [[:bytes {:read 1}] [:elements 1]]] |
201 | 205 | 76 [:sz-quarantined-md [[:bytes {:read 2}] [:elements 1]]] |
|
641 | 645 | (defn- write-bytes [^DataOutput out ^bytes ba] |
642 | 646 | (let [len (alength ba)] |
643 | 647 | (if (zero? len) |
644 | | - (write-id out id-bytes-0) |
| 648 | + (write-id out id-byte-array-0) |
645 | 649 | (do |
646 | 650 | (enc/cond |
647 | | - (sm-count? len) (do (write-id out id-bytes-sm) (write-sm-count out len)) |
648 | | - (md-count? len) (do (write-id out id-bytes-md) (write-md-count out len)) |
649 | | - :else (do (write-id out id-bytes-lg) (write-lg-count out len))) |
| 651 | + (sm-count? len) (do (write-id out id-byte-array-sm) (write-sm-count out len)) |
| 652 | + (md-count? len) (do (write-id out id-byte-array-md) (write-md-count out len)) |
| 653 | + :else (do (write-id out id-byte-array-lg) (write-lg-count out len))) |
650 | 654 |
|
651 | 655 | (.write out ba 0 len))))) |
652 | 656 |
|
| 657 | +(defmacro ^:private -run! [proc coll] `(do (reduce #(~proc %2) nil ~coll) nil)) |
| 658 | +(defmacro ^:private -run-kv! [proc m] `(do (reduce-kv #(~proc %2 %3) nil ~m) nil)) |
| 659 | + |
| 660 | +(defn- write-array-lg [^DataOutput out array array-len id] |
| 661 | + (write-id out id) |
| 662 | + (write-lg-count out array-len) |
| 663 | + (-run! (fn [in] (-freeze-with-meta! in out)) array)) |
| 664 | + |
653 | 665 | (defn- write-biginteger [out ^BigInteger n] (write-bytes-lg out (.toByteArray n))) |
654 | 666 |
|
655 | 667 | (defn- write-str-sm* [^DataOutput out ^String s] (write-bytes-sm* out (.getBytes s StandardCharsets/UTF_8))) |
|
729 | 741 | (<= y range-uint) (do (write-id out id-long-neg-lg) (.writeInt out (+ y Integer/MIN_VALUE))) |
730 | 742 | :else (do (write-id out id-long-xl) (.writeLong out n)))))) |
731 | 743 |
|
732 | | -(defmacro ^:private -run! [proc coll] `(do (reduce #(~proc %2) nil ~coll) nil)) |
733 | | -(defmacro ^:private -run-kv! [proc m] `(do (reduce-kv #(~proc %2 %3) nil ~m) nil)) |
734 | | - |
735 | 744 | (defn- write-vec [^DataOutput out v] |
736 | 745 | (let [cnt (count v)] |
737 | 746 | (if (zero? cnt) |
|
879 | 888 |
|
880 | 889 | (-run! (fn [in] (-freeze-with-meta! in out)) s))))) |
881 | 890 |
|
882 | | -(defn- write-objects [^DataOutput out ^objects ary] |
883 | | - (let [len (alength ary)] |
884 | | - (write-id out id-objects-lg) |
885 | | - (write-lg-count out len) |
886 | | - (-run! (fn [in] (-freeze-with-meta! in out)) ary))) |
887 | | - |
888 | 891 | (defn- write-serializable [^DataOutput out x ^String class-name] |
889 | 892 | (when-debug (println (str "write-serializable: " (type x)))) |
890 | 893 | (let [class-name-ba (.getBytes class-name StandardCharsets/UTF_8) |
|
1096 | 1099 | (.writeLong out (.getLeastSignificantBits x)))) |
1097 | 1100 |
|
1098 | 1101 | (freezer Boolean nil true (if (boolean x) (write-id out id-true) (write-id out id-false))) |
1099 | | -(freezer (Class/forName "[B") nil true (write-bytes out x)) |
1100 | | -(freezer (Class/forName "[Ljava.lang.Object;") nil true (write-objects out x)) |
1101 | 1102 | (freezer String nil true (write-str out x)) |
1102 | 1103 | (freezer Keyword nil true (write-kw out x)) |
1103 | 1104 | (freezer Symbol nil true (write-sym out x)) |
|
1107 | 1108 | (do (write-id out id-double-0)) |
1108 | 1109 | (do (write-id out id-double) (.writeDouble out x)))) |
1109 | 1110 |
|
| 1111 | +;; Arrays |
| 1112 | +(freezer (Class/forName "[B") nil true (write-bytes out x)) |
| 1113 | +(freezer (Class/forName "[Ljava.lang.Object;") nil true (write-array-lg out x (alength ^"[Ljava.lang.Object;" x) id-object-array-lg)) |
| 1114 | + |
| 1115 | +(when (impl/target-release>= 350) |
| 1116 | + (freezer (Class/forName "[I") nil true (write-array-lg out x (alength ^"[I" x) id-int-array-lg)) |
| 1117 | + (freezer (Class/forName "[J") nil true (write-array-lg out x (alength ^"[J" x) id-long-array-lg)) |
| 1118 | + (freezer (Class/forName "[Ljava.lang.String;") nil true (write-array-lg out x (alength ^"[Ljava.lang.String;" x) id-string-array-lg))) |
| 1119 | + |
1110 | 1120 | (freezer PersistentQueue nil true (write-counted-coll out id-queue-lg x)) |
1111 | 1121 | (freezer PersistentTreeSet nil true (write-counted-coll out id-sorted-set-lg x)) |
1112 | 1122 | (freezer PersistentTreeMap nil true (write-kvs out id-sorted-map-lg x)) |
|
1330 | 1340 | ([^DataInput in len] (let [ba (byte-array len)] (.readFully in ba 0 len) ba)) |
1331 | 1341 | ([^DataInput in ] |
1332 | 1342 | (enc/case-eval (.readByte in) |
1333 | | - id-bytes-0 (byte-array 0) |
1334 | | - id-bytes-sm (read-bytes in (read-sm-count in)) |
1335 | | - id-bytes-md (read-bytes in (read-md-count in)) |
1336 | | - id-bytes-lg (read-bytes in (read-lg-count in))))) |
| 1343 | + id-byte-array-0 (byte-array 0) |
| 1344 | + id-byte-array-sm (read-bytes in (read-sm-count in)) |
| 1345 | + id-byte-array-md (read-bytes in (read-md-count in)) |
| 1346 | + id-byte-array-lg (read-bytes in (read-lg-count in))))) |
| 1347 | + |
| 1348 | +(defmacro ^:private read-array [in thaw-type array array-type] |
| 1349 | + (let [thawed-sym (with-meta 'thawed-sym {:tag thaw-type}) |
| 1350 | + array-sym (with-meta 'array-sym {:tag array-type})] |
| 1351 | + `(let [~array-sym ~array] |
| 1352 | + (enc/reduce-n |
| 1353 | + (fn [_# idx#] |
| 1354 | + (let [~thawed-sym (thaw-from-in! ~in)] |
| 1355 | + (aset ~'array-sym idx# ~'thawed-sym))) |
| 1356 | + nil (alength ~'array-sym)) |
| 1357 | + ~'array-sym))) |
1337 | 1358 |
|
1338 | 1359 | (defn- read-str-sm* [^DataInput in] (String. ^bytes (read-bytes in (read-sm-count* in)) StandardCharsets/UTF_8)) |
1339 | 1360 | (defn- read-str-sm [^DataInput in] (String. ^bytes (read-bytes in (read-sm-count in)) StandardCharsets/UTF_8)) |
|
1382 | 1403 | (let [rf rf2 ] (rf (enc/reduce-n (fn [acc _] (rf acc (thaw-from-in! in) (thaw-from-in! in))) init n))))))) |
1383 | 1404 |
|
1384 | 1405 | (defn- read-kvs-depr [to ^DataInput in] (read-kvs-into to in (quot (.readInt in) 2))) |
1385 | | -(defn- read-objects [^objects ary ^DataInput in] |
1386 | | - (enc/reduce-n |
1387 | | - (fn [^objects ary i] |
1388 | | - (aset ary i (thaw-from-in! in)) |
1389 | | - ary) |
1390 | | - ary (alength ary))) |
1391 | 1406 |
|
1392 | 1407 | (def ^:private class-method-sig (into-array Class [IPersistentMap])) |
1393 | 1408 |
|
|
1580 | 1595 | id-cached-sm (thaw-cached (read-sm-count in) in) |
1581 | 1596 | id-cached-md (thaw-cached (read-md-count in) in) |
1582 | 1597 |
|
1583 | | - id-bytes-0 (byte-array 0) |
1584 | | - id-bytes-sm (read-bytes in (read-sm-count in)) |
1585 | | - id-bytes-md (read-bytes in (read-md-count in)) |
1586 | | - id-bytes-lg (read-bytes in (read-lg-count in)) |
| 1598 | + id-byte-array-0 (byte-array 0) |
| 1599 | + id-byte-array-sm (read-bytes in (read-sm-count in)) |
| 1600 | + id-byte-array-md (read-bytes in (read-md-count in)) |
| 1601 | + id-byte-array-lg (read-bytes in (read-lg-count in)) |
1587 | 1602 |
|
1588 | | - id-objects-lg (read-objects (object-array (read-lg-count in)) in) |
| 1603 | + id-int-array-lg (read-array in int (int-array (read-lg-count in)) "[I") |
| 1604 | + id-long-array-lg (read-array in long (long-array (read-lg-count in)) "[J") |
| 1605 | + id-string-array-lg (read-array in String (make-array String (read-lg-count in)) "[Ljava.lang.String;") |
| 1606 | + id-object-array-lg (read-array in Object (object-array (read-lg-count in)) "[Ljava.lang.Object;") |
1589 | 1607 |
|
1590 | 1608 | id-str-0 "" |
1591 | 1609 | id-str-sm* (read-str in (read-sm-count* in)) |
|
2039 | 2057 | :uri (java.net.URI. "https://clojure.org") |
2040 | 2058 | :defrecord (StressRecord. "data") |
2041 | 2059 | :deftype (StressType. "data") |
| 2060 | + |
2042 | 2061 | :bytes (byte-array [(byte 1) (byte 2) (byte 3)]) |
2043 | 2062 | :objects (object-array [1 "two" {:data "data"}]) |
2044 | 2063 |
|
| 2064 | + ;; TODO (target-release>= 350) |
| 2065 | + ;; :byte-array (byte-array [(byte 1) (byte 2) (byte 3) (byte 4)]) |
| 2066 | + ;; :int-array (int-array [1 2 3 4]) |
| 2067 | + ;; :long-array (long-array [1 2 3 4]) |
| 2068 | + ;; :object-array (object-array [1 "two" {:data "data"}]) |
| 2069 | + ;; :string-array (into-array String ["a" "b" "c"]) |
| 2070 | + |
2045 | 2071 | :util-date (java.util.Date. 1577884455500) |
2046 | 2072 | :sql-date (java.sql.Date. 1577884455500) |
2047 | 2073 | :instant (enc/compile-if java.time.Instant (java.time.Instant/parse "2020-01-01T13:14:15.50Z") ::skip) |
|
0 commit comments