implement GuestType for arrays
@@ -153,3 +153,30 @@ impl<'a, T> GuestType<'a> for GuestPtr<'a, T> {
ptr.cast::<u32>().write(val.offset())
}
}
+
+// Support pointers-to-arrays where pointers are always 32-bits in wasm land
+impl<'a, T> GuestType<'a> for GuestPtr<'a, [T]>
+where
+ T: GuestType<'a>,
+{
+ fn guest_size() -> u32 {
+ u32::guest_size() * 2
+ }
+
+ fn guest_align() -> usize {
+ u32::guest_align()
+ }
+
+ fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError> {
+ let offset = ptr.cast::<u32>().read()?;
+ let len = ptr.cast::<u32>().add(1)?.read()?;
+ Ok(GuestPtr::new(ptr.mem(), offset).as_array(len))
+ }
+
+ fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError> {
+ let (offs, len) = val.offset();
+ let len_ptr = ptr.cast::<u32>().add(1)?;
+ ptr.cast::<u32>().write(offs)?;
+ len_ptr.write(len)
+ }
+}
