Add all the c-string type stuff together in one place

This commit is contained in:
Joshua Suskalo 2021-09-16 16:15:31 -05:00
parent 6758fdebe1
commit 81bbbf3433

View file

@ -163,10 +163,6 @@
[type]
(c-prim-layout type))
(defmethod c-layout ::c-string
[_type]
CLinker/C_POINTER)
(defmulti primitive-type
"Gets the primitive type that is used to pass as an argument for the `type`.
@ -181,10 +177,6 @@
[type]
(primitive-types type))
(defmethod primitive-type ::c-string
[_type]
::pointer)
(def java-prim-layout
"Map of primitive type names to the Java types for a method handle."
{::byte Byte/TYPE
@ -206,10 +198,6 @@
[type]
(java-prim-layout type MemorySegment))
(defmethod java-layout ::c-string
[_type]
MemoryAddress)
(defn size-of
"The size in bytes of the given `type`."
[type]
@ -265,10 +253,6 @@
[obj type segment scope]
(type-dispatch type)))
(defmethod serialize* ::c-string
[obj _type scope]
(address-of (CLinker/toCString (str obj) ^ResourceScope scope)))
(defmethod serialize-into :default
[obj type segment scope]
(if-some [prim-layout (primitive-type type)]
@ -383,16 +367,6 @@
[obj _type]
obj)
(defmethod deserialize-from ::c-string
[segment type]
(-> segment
(deserialize-from ::pointer)
(deserialize* type)))
(defmethod deserialize* ::c-string
[addr _type]
(CLinker/toJavaString ^MemoryAddress addr))
(defn deserialize
"Deserializes an arbitrary type.
@ -406,6 +380,34 @@
deserialize-from)
obj type)))
;; C String type
(defmethod primitive-type ::c-string
[_type]
::pointer)
(defmethod c-layout ::c-string
[_type]
CLinker/C_POINTER)
(defmethod java-layout ::c-string
[_type]
MemoryAddress)
(defmethod serialize* ::c-string
[obj _type scope]
(address-of (CLinker/toCString (str obj) ^ResourceScope scope)))
(defmethod deserialize-from ::c-string
[segment type]
(-> segment
(deserialize-from ::pointer)
(deserialize* type)))
(defmethod deserialize* ::c-string
[addr _type]
(CLinker/toJavaString ^MemoryAddress addr))
#_(defn seq-of
"Constructs a lazy sequence of `type` elements deserialized from `segment`."
[type segment]