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

ambee/giterated

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

Spinning

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨1788060

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