From 75951c5019ca219f06b5807909f86a2d3b2f61f0 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 16 Sep 2021 16:15:56 -0500 Subject: [PATCH] Allow (::pointer ::int) style types to serde properly --- src/coffi/ffi.clj | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/coffi/ffi.clj b/src/coffi/ffi.clj index 8c1cff2..33a7e35 100644 --- a/src/coffi/ffi.clj +++ b/src/coffi/ffi.clj @@ -235,7 +235,11 @@ (defmethod serialize* ::pointer [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 "Writes a serialized version of the `obj` to the given `segment`. @@ -310,6 +314,8 @@ (let [segment (alloc-instance type scope)] (serialize-into obj type segment scope))))) +(declare deserialize) + (defmulti deserialize-from "Deserializes the given segment into a Clojure data structure." (fn @@ -350,8 +356,11 @@ (MemoryAccess/getDouble segment)) (defmethod deserialize-from ::pointer - [segment _type] - (MemoryAccess/getAddress segment)) + [segment type] + (if (sequential? type) + (deserialize (slice-global (MemoryAccess/getAddress segment) (size-of (second type))) + (second type)) + (MemoryAccess/getAddress segment))) (defmulti deserialize* "Deserializes a primitive object into a Clojure data structure. @@ -367,6 +376,13 @@ [obj _type] obj) +(defmethod deserialize* ::pointer + [addr type] + (if (sequential? type) + (deserialize (slice-global addr (size-of (second type))) + (second type)) + addr)) + (defn deserialize "Deserializes an arbitrary type.