From 23602dfa18c5f6b6cda17c50c168d54fc50c4647 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Mon, 20 Sep 2021 19:41:44 -0500 Subject: [PATCH] Add array serdes --- src/coffi/ffi.clj | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/coffi/ffi.clj b/src/coffi/ffi.clj index 4d587d9..d8c52e4 100644 --- a/src/coffi/ffi.clj +++ b/src/coffi/ffi.clj @@ -551,6 +551,28 @@ [_segment [_padding _size]] nil) +;;; Array types + +(defmethod c-layout ::array + [[_array type count]] + (MemoryLayout/sequenceLayout + count + (c-layout type))) + +(defmethod serialize-into ::array + [obj [_array type count] segment scope] + (dorun + (map #(serialize-into %1 type %2 scope) + obj + (slice-segments (slice segment 0 (* count (size-of type))) + (size-of type))))) + +(defmethod deserialize-from ::array + [segment [_array type count]] + (map #(deserialize-from % type) + (slice-segments (slice segment 0 (* count (size-of type))) + (size-of type)))) + ;;; FFI Code loading and function access (defn load-system-library