Add all the c-string type stuff together in one place
This commit is contained in:
parent
6758fdebe1
commit
81bbbf3433
1 changed files with 28 additions and 26 deletions
|
|
@ -163,10 +163,6 @@
|
||||||
[type]
|
[type]
|
||||||
(c-prim-layout type))
|
(c-prim-layout type))
|
||||||
|
|
||||||
(defmethod c-layout ::c-string
|
|
||||||
[_type]
|
|
||||||
CLinker/C_POINTER)
|
|
||||||
|
|
||||||
(defmulti primitive-type
|
(defmulti primitive-type
|
||||||
"Gets the primitive type that is used to pass as an argument for the `type`.
|
"Gets the primitive type that is used to pass as an argument for the `type`.
|
||||||
|
|
||||||
|
|
@ -181,10 +177,6 @@
|
||||||
[type]
|
[type]
|
||||||
(primitive-types type))
|
(primitive-types type))
|
||||||
|
|
||||||
(defmethod primitive-type ::c-string
|
|
||||||
[_type]
|
|
||||||
::pointer)
|
|
||||||
|
|
||||||
(def java-prim-layout
|
(def java-prim-layout
|
||||||
"Map of primitive type names to the Java types for a method handle."
|
"Map of primitive type names to the Java types for a method handle."
|
||||||
{::byte Byte/TYPE
|
{::byte Byte/TYPE
|
||||||
|
|
@ -206,10 +198,6 @@
|
||||||
[type]
|
[type]
|
||||||
(java-prim-layout type MemorySegment))
|
(java-prim-layout type MemorySegment))
|
||||||
|
|
||||||
(defmethod java-layout ::c-string
|
|
||||||
[_type]
|
|
||||||
MemoryAddress)
|
|
||||||
|
|
||||||
(defn size-of
|
(defn size-of
|
||||||
"The size in bytes of the given `type`."
|
"The size in bytes of the given `type`."
|
||||||
[type]
|
[type]
|
||||||
|
|
@ -265,10 +253,6 @@
|
||||||
[obj type segment scope]
|
[obj type segment scope]
|
||||||
(type-dispatch type)))
|
(type-dispatch type)))
|
||||||
|
|
||||||
(defmethod serialize* ::c-string
|
|
||||||
[obj _type scope]
|
|
||||||
(address-of (CLinker/toCString (str obj) ^ResourceScope scope)))
|
|
||||||
|
|
||||||
(defmethod serialize-into :default
|
(defmethod serialize-into :default
|
||||||
[obj type segment scope]
|
[obj type segment scope]
|
||||||
(if-some [prim-layout (primitive-type type)]
|
(if-some [prim-layout (primitive-type type)]
|
||||||
|
|
@ -383,16 +367,6 @@
|
||||||
[obj _type]
|
[obj _type]
|
||||||
obj)
|
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
|
(defn deserialize
|
||||||
"Deserializes an arbitrary type.
|
"Deserializes an arbitrary type.
|
||||||
|
|
||||||
|
|
@ -406,6 +380,34 @@
|
||||||
deserialize-from)
|
deserialize-from)
|
||||||
obj type)))
|
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
|
#_(defn seq-of
|
||||||
"Constructs a lazy sequence of `type` elements deserialized from `segment`."
|
"Constructs a lazy sequence of `type` elements deserialized from `segment`."
|
||||||
[type segment]
|
[type segment]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue