2021-07-05 23:17:12 +08:00
|
|
|
use flowy_derive::ProtoBuf;
|
2021-07-07 22:24:26 +08:00
|
|
|
use flowy_sys::prelude::DispatchRequest;
|
2021-07-05 23:17:12 +08:00
|
|
|
use std::convert::TryFrom;
|
|
|
|
|
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct FFIRequest {
|
|
|
|
#[pb(index = 1)]
|
2021-07-07 22:24:26 +08:00
|
|
|
pub(crate) event: String,
|
2021-07-05 23:17:12 +08:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
2021-07-07 22:24:26 +08:00
|
|
|
pub(crate) payload: Vec<u8>,
|
2021-07-05 23:17:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FFIRequest {
|
|
|
|
pub fn from_u8_pointer(pointer: *const u8, len: usize) -> Self {
|
|
|
|
let bytes = unsafe { std::slice::from_raw_parts(pointer, len) }.to_vec();
|
|
|
|
let request: FFIRequest = FFIRequest::try_from(&bytes).unwrap();
|
|
|
|
request
|
|
|
|
}
|
|
|
|
}
|
2021-07-07 22:24:26 +08:00
|
|
|
|
|
|
|
impl std::convert::Into<DispatchRequest> for FFIRequest {
|
|
|
|
fn into(self) -> DispatchRequest { DispatchRequest::new(self.event).payload(self.payload) }
|
|
|
|
}
|