Allow (::pointer ::int) style types to serde properly

This commit is contained in:
Joshua Suskalo 2021-09-16 16:15:56 -05:00
parent 81bbbf3433
commit 75951c5019

View file

@ -235,7 +235,11 @@
(defmethod serialize* ::pointer (defmethod serialize* ::pointer
[obj type scope] [obj type scope]
(alloc-instance (serialize obj (second type) scope))) (if (sequential? type)
(let [segment (alloc-instance (second type) scope)]
(serialize-into obj (second type) segment scope)
(address-of segment))
obj))
(defmulti serialize-into (defmulti serialize-into
"Writes a serialized version of the `obj` to the given `segment`. "Writes a serialized version of the `obj` to the given `segment`.
@ -310,6 +314,8 @@
(let [segment (alloc-instance type scope)] (let [segment (alloc-instance type scope)]
(serialize-into obj type segment scope))))) (serialize-into obj type segment scope)))))
(declare deserialize)
(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
@ -350,8 +356,11 @@
(MemoryAccess/getDouble segment)) (MemoryAccess/getDouble segment))
(defmethod deserialize-from ::pointer (defmethod deserialize-from ::pointer
[segment _type] [segment type]
(MemoryAccess/getAddress segment)) (if (sequential? type)
(deserialize (slice-global (MemoryAccess/getAddress segment) (size-of (second type)))
(second type))
(MemoryAccess/getAddress segment)))
(defmulti deserialize* (defmulti deserialize*
"Deserializes a primitive object into a Clojure data structure. "Deserializes a primitive object into a Clojure data structure.
@ -367,6 +376,13 @@
[obj _type] [obj _type]
obj) obj)
(defmethod deserialize* ::pointer
[addr type]
(if (sequential? type)
(deserialize (slice-global addr (size-of (second type)))
(second type))
addr))
(defn deserialize (defn deserialize
"Deserializes an arbitrary type. "Deserializes an arbitrary type.