JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Before

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨e432306

⁨giterated-abi/src/vtable/value.rs⁩ - ⁨1300⁩ bytes
Raw
1 use crate::{
2 result::{FfiError, FfiResult},
3 value_ex::FfiValueUntyped,
4 FfiSlice, FfiSliceRef,
5 };
6
7 use super::{ObjectABI, VTable};
8
9 #[repr(C)]
10 pub struct Value {
11 inner: FfiValueUntyped,
12 vtable: &'static VTable<Value>,
13 }
14
15 impl Value {
16 pub fn from<T: IntoValueVTable>(value: T) -> Self {
17 todo!()
18 }
19 }
20
21 impl ObjectABI for Value {
22 type VTable = ValueVTable;
23 }
24
25 pub struct ValueVTable {
26 pub serialize: unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> FfiResult<Value, FfiError>,
27 pub deserialize: unsafe extern "C" fn(this: Value) -> FfiResult<FfiSlice<[u8]>, FfiError>,
28 }
29
30 impl ValueVTable {
31 pub const fn new<V: IntoValueVTable>() -> Self {
32 Self {
33 serialize: V::serialize,
34 deserialize: V::deserialize,
35 }
36 }
37
38 pub fn serialize(&self, value: &Value) -> Result<Vec<u8>, FfiError> {
39 todo!()
40 }
41
42 pub fn deserialize(&self, buffer: &[u8]) -> Result<Value, FfiError> {
43 todo!()
44 }
45 }
46
47 pub trait IntoValueVTable: Sized {
48 const VTABLE: &'static VTable<Value> = VTable::new(&ValueVTable::new::<Self>());
49
50 unsafe extern "C" fn serialize(buffer: FfiSliceRef<[u8]>) -> FfiResult<Value, FfiError>;
51 unsafe extern "C" fn deserialize(this: Value) -> FfiResult<FfiSlice<[u8]>, FfiError>;
52 }
53