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/operation.rs⁩ - ⁨3212⁩ bytes
Raw
1 use std::ffi::CStr;
2
3 use crate::{
4 result::{FfiError, FfiResult},
5 value_ex::{FfiValueRefUntyped, FfiValueUntyped},
6 FfiSlice, FfiSliceRef, FfiValue, FfiValueRef,
7 };
8
9 use super::{ObjectABI, VTable};
10
11 #[repr(C)]
12 pub struct Operation {
13 inner: FfiValueUntyped,
14 vtable: &'static VTable<Operation>,
15 }
16
17 impl Operation {
18 pub fn operation_kind(&self) -> &'static str {
19 todo!()
20 }
21
22 pub fn serialize(&self) -> Vec<u8> {
23 todo!()
24 }
25
26 pub fn deserialize_from<O, T: IntoOperationVTable<O>>(buffer: &[u8]) -> Result<Self, FfiError> {
27 todo!()
28 }
29 }
30
31 impl ObjectABI for Operation {
32 type VTable = OperationVTable;
33 }
34
35 pub struct OperationVTable {
36 pub operation_kind: &'static CStr,
37 pub operation_serialize:
38 unsafe extern "C" fn(this: FfiValueRef<Operation>) -> FfiResult<FfiSlice<[u8]>, FfiError>,
39 pub operation_deserialize:
40 unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> FfiResult<Operation, FfiError>,
41 pub success_serialize:
42 unsafe extern "C" fn(success: FfiValueRefUntyped) -> FfiResult<FfiSlice<[u8]>, FfiError>,
43 pub success_deserialize:
44 unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> FfiResult<FfiValueUntyped, FfiError>,
45 pub failure_serialize:
46 unsafe extern "C" fn(failure: FfiValueRefUntyped) -> FfiResult<FfiSlice<[u8]>, FfiError>,
47 pub failure_deserialize:
48 unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> FfiResult<FfiValueUntyped, FfiError>,
49 }
50
51 impl OperationVTable {
52 pub const fn new<O, T: IntoOperationVTable<O>>() -> Self {
53 todo!()
54 }
55
56 pub fn serialize(&self, operation: Operation) -> Result<Vec<u8>, FfiError> {
57 todo!()
58 }
59
60 pub fn deserialize(&self, buffer: &[u8]) -> Result<Operation, FfiError> {
61 todo!()
62 }
63
64 pub fn serialize_success(&self, success: FfiValueUntyped) -> Result<Vec<u8>, FfiError> {
65 todo!()
66 }
67
68 pub fn deserialize_success(&self, buffer: &[u8]) -> Result<FfiValueUntyped, FfiError> {
69 todo!()
70 }
71
72 pub fn serialize_failure(&self, failure: FfiValueUntyped) -> Result<Vec<u8>, FfiError> {
73 todo!()
74 }
75
76 pub fn deserialize_failure(&self, buffer: &[u8]) -> Result<FfiValueUntyped, FfiError> {
77 todo!()
78 }
79 }
80
81 pub trait IntoOperationVTable<O>: Sized {
82 const VTABLE: &'static VTable<Operation> = VTable::new(&OperationVTable::new::<O, Self>());
83
84 fn operation_kind() -> &'static CStr;
85 unsafe extern "C" fn operation_serialize(
86 this: FfiValueRef<Operation>,
87 ) -> FfiResult<FfiSlice<[u8]>, FfiError>;
88 unsafe extern "C" fn operation_deserialize(
89 buffer: FfiSliceRef<[u8]>,
90 ) -> FfiResult<Operation, FfiError>;
91 unsafe extern "C" fn success_serialize(
92 success: FfiValueRefUntyped,
93 ) -> FfiResult<FfiSlice<[u8]>, FfiError>;
94 unsafe extern "C" fn success_deserialize(
95 buffer: FfiSliceRef<[u8]>,
96 ) -> FfiResult<FfiValueUntyped, FfiError>;
97 unsafe extern "C" fn failure_serialize(
98 failure: FfiValueRefUntyped,
99 ) -> FfiResult<FfiSlice<[u8]>, FfiError>;
100 unsafe extern "C" fn failure_deserialize(
101 buffer: FfiSliceRef<[u8]>,
102 ) -> FfiResult<FfiValueUntyped, FfiError>;
103 }
104