Add general serialization function
This commit is contained in:
parent
375d016254
commit
bf611f3106
1 changed files with 13 additions and 5 deletions
|
|
@ -303,6 +303,19 @@
|
||||||
[obj _type segment _scope]
|
[obj _type segment _scope]
|
||||||
(MemoryAccess/setAddress segment obj))
|
(MemoryAccess/setAddress segment obj))
|
||||||
|
|
||||||
|
(defn serialize
|
||||||
|
"Serializes an arbitrary type.
|
||||||
|
|
||||||
|
For types which have a primitive representation, this serializes into that
|
||||||
|
representation. For types which do not, it allocates a new segment and
|
||||||
|
serializes into that."
|
||||||
|
([obj type] (serialize obj type (connected-scope)))
|
||||||
|
([obj type scope]
|
||||||
|
(if (primitive-type type)
|
||||||
|
(serialize* obj type scope)
|
||||||
|
(let [segment (alloc-instance type scope)]
|
||||||
|
(serialize-into obj type segment scope)))))
|
||||||
|
|
||||||
(defmulti deserialize-from
|
(defmulti deserialize-from
|
||||||
"Deserializes the given segment into a Clojure data structure."
|
"Deserializes the given segment into a Clojure data structure."
|
||||||
(fn
|
(fn
|
||||||
|
|
@ -385,11 +398,6 @@
|
||||||
deserialize-from)
|
deserialize-from)
|
||||||
obj type))
|
obj type))
|
||||||
|
|
||||||
(defn serialize
|
|
||||||
"Serializes the `obj` into a newly-allocated [[MemorySegment]]."
|
|
||||||
([obj type] (serialize obj type (ResourceScope/newImplicitScope)))
|
|
||||||
([obj type scope] (serialize-into obj type (alloc-instance type scope) scope)))
|
|
||||||
|
|
||||||
(defn load-system-library
|
(defn load-system-library
|
||||||
"Loads the library named `libname` from the system's load path."
|
"Loads the library named `libname` from the system's load path."
|
||||||
[libname]
|
[libname]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue