use std::ffi::CStr; use crate::{ result::{FfiError, FfiResult}, value_ex::{FfiValueRefUntyped, FfiValueUntyped}, FfiSlice, FfiSliceRef, FfiValue, FfiValueRef, }; use super::{ObjectABI, VTable}; #[repr(C)] pub struct Operation { inner: FfiValueUntyped, vtable: &'static VTable, } impl Operation { pub fn operation_kind(&self) -> &'static str { todo!() } pub fn serialize(&self) -> Vec { todo!() } pub fn deserialize_from>(buffer: &[u8]) -> Result { todo!() } } impl ObjectABI for Operation { type VTable = OperationVTable; } pub struct OperationVTable { pub operation_kind: &'static CStr, pub operation_serialize: unsafe extern "C" fn(this: FfiValueRef) -> FfiResult, FfiError>, pub operation_deserialize: unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> FfiResult, pub success_serialize: unsafe extern "C" fn(success: FfiValueRefUntyped) -> FfiResult, FfiError>, pub success_deserialize: unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> FfiResult, pub failure_serialize: unsafe extern "C" fn(failure: FfiValueRefUntyped) -> FfiResult, FfiError>, pub failure_deserialize: unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> FfiResult, } impl OperationVTable { pub const fn new>() -> Self { todo!() } pub fn serialize(&self, operation: Operation) -> Result, FfiError> { todo!() } pub fn deserialize(&self, buffer: &[u8]) -> Result { todo!() } pub fn serialize_success(&self, success: FfiValueUntyped) -> Result, FfiError> { todo!() } pub fn deserialize_success(&self, buffer: &[u8]) -> Result { todo!() } pub fn serialize_failure(&self, failure: FfiValueUntyped) -> Result, FfiError> { todo!() } pub fn deserialize_failure(&self, buffer: &[u8]) -> Result { todo!() } } pub trait IntoOperationVTable: Sized { const VTABLE: &'static VTable = VTable::new(&OperationVTable::new::()); fn operation_kind() -> &'static CStr; unsafe extern "C" fn operation_serialize( this: FfiValueRef, ) -> FfiResult, FfiError>; unsafe extern "C" fn operation_deserialize( buffer: FfiSliceRef<[u8]>, ) -> FfiResult; unsafe extern "C" fn success_serialize( success: FfiValueRefUntyped, ) -> FfiResult, FfiError>; unsafe extern "C" fn success_deserialize( buffer: FfiSliceRef<[u8]>, ) -> FfiResult; unsafe extern "C" fn failure_serialize( failure: FfiValueRefUntyped, ) -> FfiResult, FfiError>; unsafe extern "C" fn failure_deserialize( buffer: FfiSliceRef<[u8]>, ) -> FfiResult; }