Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.

Commit 86edfee

Browse files
Shayan Fouladipbalduino
authored andcommitted
Refactor clj->ion-binary to use clj->ion
1 parent c5c45dd commit 86edfee

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/dandelion/core.clj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@
2929
(.makeReadOnly value)
3030
value))
3131

32-
(defn clj->ion-binary
33-
"Transforms a Clojure value to a byte array of Ion binary"
34-
[clj-value]
35-
(with-open [os (ByteArrayOutputStream.)
36-
writer (.build (IonBinaryWriterBuilder/standard) os)
37-
reader (.build (IonReaderBuilder/standard) (json/write-str clj-value))]
38-
(.writeValues writer reader)
39-
(.finish writer)
40-
(.toByteArray os)))
41-
4232
(defn clj->ion
4333
"Transforms a Clojure value, usually a Map to an immutable IonValue."
4434
[clj-value]
4535
(-> clj-value
4636
(json/write-str :key-fn preserve-ns)
4737
json->ion))
4838

39+
(defn clj->ion-binary
40+
"Transforms a Clojure value to a byte array of Ion binary"
41+
[clj-value]
42+
(let [ion-value (clj->ion clj-value)]
43+
(with-open [os (ByteArrayOutputStream.)
44+
writer (.build (IonBinaryWriterBuilder/standard) os)]
45+
(.writeTo ion-value writer)
46+
(.finish writer)
47+
(.toByteArray os))))
48+
4949
(defn ion->clj
5050
"Transforms a IonValue to a Clojure value"
5151
([ion-value]

0 commit comments

Comments
 (0)