From eea1b43da39c38205b0e5abdfc21227cc3774b9d Mon Sep 17 00:00:00 2001 From: Kristin Rutenkolk Date: Fri, 11 Oct 2024 22:26:41 +0200 Subject: [PATCH] fix nested types serdes --- src/clj/coffi/mem.clj | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/clj/coffi/mem.clj b/src/clj/coffi/mem.clj index ac15fec..4b4cc79 100644 --- a/src/clj/coffi/mem.clj +++ b/src/clj/coffi/mem.clj @@ -1600,7 +1600,7 @@ 'floats [::array ::byte] 'doubles [::array ::byte]} _type - _type)) + (keyword (str *ns*) (str _type)))) (defn coffitype->array-fn [_type] (get @@ -1659,6 +1659,7 @@ (generate-deserialize field-type (+ global-offset offset)))) (reduce concat) (cons (symbol (str (name typename) "."))) + (list) )))) (defmulti generate-serialize (fn [& xs] (if (vector? (first xs)) (first (first xs)) (first xs)))) @@ -1689,8 +1690,9 @@ (->> typelist (map-indexed (fn [index [offset [_ field-type]]] - (generate-serialize field-type (list (symbol (str "." (name (nth fieldnames index)))) source-form) (+ global-offset offset)))) - (cons `do))))) + (generate-serialize field-type (list (symbol (str "." (name (nth fieldnames index)))) 'source-obj) (+ global-offset offset)))) + (concat [`let ['source-obj source-form]]) + )))) (defmacro defstruct "Defines a struct type. all members need a type hint. @@ -1721,9 +1723,9 @@ (register-new-struct-serialization coffi-typename struct-layout) `(do (defrecord ~typename ~typed-symbols) - (defmethod c-layout ~coffi-typename [~'_] ~struct-layout) + (defmethod c-layout ~coffi-typename [~'_] (c-layout ~struct-layout)) (defmethod deserialize-from ~coffi-typename ~['segment '_type] - ~(generate-deserialize coffi-typename 0)) + ~(first (generate-deserialize coffi-typename 0))) (defmethod serialize-into ~coffi-typename ~[(with-meta 'source-obj {:tag typename}) '_type 'segment '_] ~(generate-serialize coffi-typename (with-meta 'source-obj {:tag typename}) 0)) )