mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
add frontend folder
This commit is contained in:
38
frontend/rust-lib/dart-ffi/Cargo.toml
Normal file
38
frontend/rust-lib/dart-ffi/Cargo.toml
Normal file
@ -0,0 +1,38 @@
|
||||
[package]
|
||||
name = "dart-ffi"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[lib]
|
||||
name = "dart_ffi"
|
||||
# this value will change depending on the target os
|
||||
# default staticlib
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
allo-isolate = {version = "^0.1", features = ["catch-unwind",]}
|
||||
byteorder = {version = "1.3.4"}
|
||||
ffi-support = {version = "0.4.2"}
|
||||
protobuf = {version = "2.20.0"}
|
||||
lazy_static = {version = "1.4.0"}
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread"] }
|
||||
log = "0.4.14"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = {version = "1.0"}
|
||||
bytes = { version = "1.0" }
|
||||
parking_lot = "0.11"
|
||||
|
||||
lib-dispatch = {path = "../lib-dispatch" }
|
||||
flowy-sdk = {path = "../flowy-sdk"}
|
||||
flowy-derive = {path = "../flowy-derive"}
|
||||
dart-notify = {path = "../dart-notify" }
|
||||
backend-service = { path = "../backend-service" }
|
||||
|
||||
|
||||
[features]
|
||||
flutter = ["dart-notify/dart"]
|
||||
http_server = ["flowy-sdk/http_server", "flowy-sdk/use_bunyan"]
|
||||
#use_serde = ["bincode"]
|
||||
#use_protobuf= ["protobuf"]
|
2
frontend/rust-lib/dart-ffi/Flowy.toml
Normal file
2
frontend/rust-lib/dart-ffi/Flowy.toml
Normal file
@ -0,0 +1,2 @@
|
||||
proto_crates = ["src/model"]
|
||||
event_files = []
|
15
frontend/rust-lib/dart-ffi/binding.h
Normal file
15
frontend/rust-lib/dart-ffi/binding.h
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int64_t init_sdk(char *path);
|
||||
|
||||
void async_command(int64_t port, const uint8_t *input, uintptr_t len);
|
||||
|
||||
const uint8_t *sync_command(const uint8_t *input, uintptr_t len);
|
||||
|
||||
int32_t set_stream_port(int64_t port);
|
||||
|
||||
void link_me_please(void);
|
26
frontend/rust-lib/dart-ffi/src/c.rs
Normal file
26
frontend/rust-lib/dart-ffi/src/c.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use byteorder::{BigEndian, ByteOrder};
|
||||
use std::mem::forget;
|
||||
|
||||
pub fn forget_rust(buf: Vec<u8>) -> *const u8 {
|
||||
let ptr = buf.as_ptr();
|
||||
forget(buf);
|
||||
ptr
|
||||
}
|
||||
|
||||
#[allow(unused_attributes)]
|
||||
#[allow(dead_code)]
|
||||
pub fn reclaim_rust(ptr: *mut u8, length: u32) {
|
||||
unsafe {
|
||||
let len: usize = length as usize;
|
||||
Vec::from_raw_parts(ptr, len, len);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extend_front_four_bytes_into_bytes(bytes: &[u8]) -> Vec<u8> {
|
||||
let mut output = Vec::with_capacity(bytes.len() + 4);
|
||||
let mut marker_bytes = [0; 4];
|
||||
BigEndian::write_u32(&mut marker_bytes, bytes.len() as u32);
|
||||
output.extend_from_slice(&marker_bytes);
|
||||
output.extend_from_slice(bytes);
|
||||
output
|
||||
}
|
96
frontend/rust-lib/dart-ffi/src/lib.rs
Normal file
96
frontend/rust-lib/dart-ffi/src/lib.rs
Normal file
@ -0,0 +1,96 @@
|
||||
mod c;
|
||||
mod model;
|
||||
mod protobuf;
|
||||
mod util;
|
||||
|
||||
use crate::{
|
||||
c::{extend_front_four_bytes_into_bytes, forget_rust},
|
||||
model::{FFIRequest, FFIResponse},
|
||||
};
|
||||
use flowy_sdk::*;
|
||||
use lazy_static::lazy_static;
|
||||
use lib_dispatch::prelude::*;
|
||||
use parking_lot::RwLock;
|
||||
use std::{ffi::CStr, os::raw::c_char, sync::Arc};
|
||||
|
||||
lazy_static! {
|
||||
static ref FLOWY_SDK: RwLock<Option<Arc<FlowySDK>>> = RwLock::new(None);
|
||||
}
|
||||
|
||||
fn dispatch() -> Arc<EventDispatch> { FLOWY_SDK.read().as_ref().unwrap().dispatch() }
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn init_sdk(path: *mut c_char) -> i64 {
|
||||
let c_str: &CStr = unsafe { CStr::from_ptr(path) };
|
||||
let path: &str = c_str.to_str().unwrap();
|
||||
|
||||
let server_config = ServerConfig::default();
|
||||
let config = FlowySDKConfig::new(path, server_config, "appflowy").log_filter("debug");
|
||||
*FLOWY_SDK.write() = Some(Arc::new(FlowySDK::new(config)));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn async_command(port: i64, input: *const u8, len: usize) {
|
||||
let request: ModuleRequest = FFIRequest::from_u8_pointer(input, len).into();
|
||||
log::trace!(
|
||||
"[FFI]: {} Async Event: {:?} with {} port",
|
||||
&request.id,
|
||||
&request.event,
|
||||
port
|
||||
);
|
||||
|
||||
let _ = EventDispatch::async_send_with_callback(dispatch(), request, move |resp: EventResponse| {
|
||||
log::trace!("[FFI]: Post data to dart through {} port", port);
|
||||
Box::pin(post_to_flutter(resp, port))
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sync_command(input: *const u8, len: usize) -> *const u8 {
|
||||
let request: ModuleRequest = FFIRequest::from_u8_pointer(input, len).into();
|
||||
log::trace!("[FFI]: {} Sync Event: {:?}", &request.id, &request.event,);
|
||||
let _response = EventDispatch::sync_send(dispatch(), request);
|
||||
|
||||
// FFIResponse { }
|
||||
let response_bytes = vec![];
|
||||
let result = extend_front_four_bytes_into_bytes(&response_bytes);
|
||||
forget_rust(result)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn set_stream_port(port: i64) -> i32 {
|
||||
dart_notify::dart::DartStreamSender::set_port(port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn link_me_please() {}
|
||||
|
||||
use backend_service::config::ServerConfig;
|
||||
use lib_dispatch::prelude::ToBytes;
|
||||
|
||||
#[inline(always)]
|
||||
async fn post_to_flutter(response: EventResponse, port: i64) {
|
||||
let isolate = allo_isolate::Isolate::new(port);
|
||||
match isolate
|
||||
.catch_unwind(async {
|
||||
let ffi_resp = FFIResponse::from(response);
|
||||
ffi_resp.into_bytes().unwrap().to_vec()
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(_success) => {
|
||||
log::trace!("[FFI]: Post data to dart success");
|
||||
},
|
||||
Err(e) => {
|
||||
if let Some(msg) = e.downcast_ref::<&str>() {
|
||||
log::error!("[FFI]: {:?}", msg);
|
||||
} else {
|
||||
log::error!("[FFI]: allo_isolate post panic");
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
26
frontend/rust-lib/dart-ffi/src/model/ffi_request.rs
Normal file
26
frontend/rust-lib/dart-ffi/src/model/ffi_request.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use bytes::Bytes;
|
||||
use flowy_derive::ProtoBuf;
|
||||
use lib_dispatch::prelude::ModuleRequest;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct FFIRequest {
|
||||
#[pb(index = 1)]
|
||||
pub(crate) event: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub(crate) payload: Vec<u8>,
|
||||
}
|
||||
|
||||
impl FFIRequest {
|
||||
pub fn from_u8_pointer(pointer: *const u8, len: usize) -> Self {
|
||||
let buffer = unsafe { std::slice::from_raw_parts(pointer, len) }.to_vec();
|
||||
let bytes = Bytes::from(buffer);
|
||||
let request: FFIRequest = FFIRequest::try_from(bytes).unwrap();
|
||||
request
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::Into<ModuleRequest> for FFIRequest {
|
||||
fn into(self) -> ModuleRequest { ModuleRequest::new(self.event).payload(self.payload) }
|
||||
}
|
44
frontend/rust-lib/dart-ffi/src/model/ffi_response.rs
Normal file
44
frontend/rust-lib/dart-ffi/src/model/ffi_response.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use lib_dispatch::prelude::{EventResponse, Payload, StatusCode};
|
||||
|
||||
#[derive(ProtoBuf_Enum, Clone, Copy)]
|
||||
pub enum FFIStatusCode {
|
||||
Ok = 0,
|
||||
Err = 1,
|
||||
Internal = 2,
|
||||
}
|
||||
|
||||
impl std::default::Default for FFIStatusCode {
|
||||
fn default() -> FFIStatusCode { FFIStatusCode::Ok }
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct FFIResponse {
|
||||
#[pb(index = 1)]
|
||||
payload: Vec<u8>,
|
||||
|
||||
#[pb(index = 2)]
|
||||
code: FFIStatusCode,
|
||||
}
|
||||
|
||||
impl std::convert::From<EventResponse> for FFIResponse {
|
||||
fn from(resp: EventResponse) -> Self {
|
||||
let payload = match resp.payload {
|
||||
Payload::Bytes(bytes) => bytes.to_vec(),
|
||||
Payload::None => vec![],
|
||||
};
|
||||
|
||||
let code = match resp.status_code {
|
||||
StatusCode::Ok => FFIStatusCode::Ok,
|
||||
StatusCode::Err => FFIStatusCode::Err,
|
||||
StatusCode::Internal => FFIStatusCode::Internal,
|
||||
};
|
||||
|
||||
// let msg = match resp.error {
|
||||
// None => "".to_owned(),
|
||||
// Some(e) => format!("{:?}", e),
|
||||
// };
|
||||
|
||||
FFIResponse { payload, code }
|
||||
}
|
||||
}
|
5
frontend/rust-lib/dart-ffi/src/model/mod.rs
Normal file
5
frontend/rust-lib/dart-ffi/src/model/mod.rs
Normal file
@ -0,0 +1,5 @@
|
||||
mod ffi_request;
|
||||
mod ffi_response;
|
||||
|
||||
pub use ffi_request::*;
|
||||
pub use ffi_response::*;
|
4
frontend/rust-lib/dart-ffi/src/protobuf/mod.rs
Normal file
4
frontend/rust-lib/dart-ffi/src/protobuf/mod.rs
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
mod model;
|
||||
pub use model::*;
|
||||
|
250
frontend/rust-lib/dart-ffi/src/protobuf/model/ffi_request.rs
Normal file
250
frontend/rust-lib/dart-ffi/src/protobuf/model/ffi_request.rs
Normal file
@ -0,0 +1,250 @@
|
||||
// This file is generated by rust-protobuf 2.22.1. Do not edit
|
||||
// @generated
|
||||
|
||||
// https://github.com/rust-lang/rust-clippy/issues/702
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(clippy::all)]
|
||||
|
||||
#![allow(unused_attributes)]
|
||||
#![cfg_attr(rustfmt, rustfmt::skip)]
|
||||
|
||||
#![allow(box_pointers)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(missing_docs)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(trivial_casts)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(unused_results)]
|
||||
//! Generated file from `ffi_request.proto`
|
||||
|
||||
/// Generated files are compatible only with the same version
|
||||
/// of protobuf runtime.
|
||||
// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1;
|
||||
|
||||
#[derive(PartialEq,Clone,Default)]
|
||||
pub struct FFIRequest {
|
||||
// message fields
|
||||
pub event: ::std::string::String,
|
||||
pub payload: ::std::vec::Vec<u8>,
|
||||
// special fields
|
||||
pub unknown_fields: ::protobuf::UnknownFields,
|
||||
pub cached_size: ::protobuf::CachedSize,
|
||||
}
|
||||
|
||||
impl<'a> ::std::default::Default for &'a FFIRequest {
|
||||
fn default() -> &'a FFIRequest {
|
||||
<FFIRequest as ::protobuf::Message>::default_instance()
|
||||
}
|
||||
}
|
||||
|
||||
impl FFIRequest {
|
||||
pub fn new() -> FFIRequest {
|
||||
::std::default::Default::default()
|
||||
}
|
||||
|
||||
// string event = 1;
|
||||
|
||||
|
||||
pub fn get_event(&self) -> &str {
|
||||
&self.event
|
||||
}
|
||||
pub fn clear_event(&mut self) {
|
||||
self.event.clear();
|
||||
}
|
||||
|
||||
// Param is passed by value, moved
|
||||
pub fn set_event(&mut self, v: ::std::string::String) {
|
||||
self.event = v;
|
||||
}
|
||||
|
||||
// Mutable pointer to the field.
|
||||
// If field is not initialized, it is initialized with default value first.
|
||||
pub fn mut_event(&mut self) -> &mut ::std::string::String {
|
||||
&mut self.event
|
||||
}
|
||||
|
||||
// Take field
|
||||
pub fn take_event(&mut self) -> ::std::string::String {
|
||||
::std::mem::replace(&mut self.event, ::std::string::String::new())
|
||||
}
|
||||
|
||||
// bytes payload = 2;
|
||||
|
||||
|
||||
pub fn get_payload(&self) -> &[u8] {
|
||||
&self.payload
|
||||
}
|
||||
pub fn clear_payload(&mut self) {
|
||||
self.payload.clear();
|
||||
}
|
||||
|
||||
// Param is passed by value, moved
|
||||
pub fn set_payload(&mut self, v: ::std::vec::Vec<u8>) {
|
||||
self.payload = v;
|
||||
}
|
||||
|
||||
// Mutable pointer to the field.
|
||||
// If field is not initialized, it is initialized with default value first.
|
||||
pub fn mut_payload(&mut self) -> &mut ::std::vec::Vec<u8> {
|
||||
&mut self.payload
|
||||
}
|
||||
|
||||
// Take field
|
||||
pub fn take_payload(&mut self) -> ::std::vec::Vec<u8> {
|
||||
::std::mem::replace(&mut self.payload, ::std::vec::Vec::new())
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::Message for FFIRequest {
|
||||
fn is_initialized(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> {
|
||||
while !is.eof()? {
|
||||
let (field_number, wire_type) = is.read_tag_unpack()?;
|
||||
match field_number {
|
||||
1 => {
|
||||
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.event)?;
|
||||
},
|
||||
2 => {
|
||||
::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.payload)?;
|
||||
},
|
||||
_ => {
|
||||
::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
|
||||
},
|
||||
};
|
||||
}
|
||||
::std::result::Result::Ok(())
|
||||
}
|
||||
|
||||
// Compute sizes of nested messages
|
||||
#[allow(unused_variables)]
|
||||
fn compute_size(&self) -> u32 {
|
||||
let mut my_size = 0;
|
||||
if !self.event.is_empty() {
|
||||
my_size += ::protobuf::rt::string_size(1, &self.event);
|
||||
}
|
||||
if !self.payload.is_empty() {
|
||||
my_size += ::protobuf::rt::bytes_size(2, &self.payload);
|
||||
}
|
||||
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
|
||||
self.cached_size.set(my_size);
|
||||
my_size
|
||||
}
|
||||
|
||||
fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
|
||||
if !self.event.is_empty() {
|
||||
os.write_string(1, &self.event)?;
|
||||
}
|
||||
if !self.payload.is_empty() {
|
||||
os.write_bytes(2, &self.payload)?;
|
||||
}
|
||||
os.write_unknown_fields(self.get_unknown_fields())?;
|
||||
::std::result::Result::Ok(())
|
||||
}
|
||||
|
||||
fn get_cached_size(&self) -> u32 {
|
||||
self.cached_size.get()
|
||||
}
|
||||
|
||||
fn get_unknown_fields(&self) -> &::protobuf::UnknownFields {
|
||||
&self.unknown_fields
|
||||
}
|
||||
|
||||
fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields {
|
||||
&mut self.unknown_fields
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn (::std::any::Any) {
|
||||
self as &dyn (::std::any::Any)
|
||||
}
|
||||
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
|
||||
self as &mut dyn (::std::any::Any)
|
||||
}
|
||||
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
|
||||
self
|
||||
}
|
||||
|
||||
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
|
||||
Self::descriptor_static()
|
||||
}
|
||||
|
||||
fn new() -> FFIRequest {
|
||||
FFIRequest::new()
|
||||
}
|
||||
|
||||
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
|
||||
static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT;
|
||||
descriptor.get(|| {
|
||||
let mut fields = ::std::vec::Vec::new();
|
||||
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
|
||||
"event",
|
||||
|m: &FFIRequest| { &m.event },
|
||||
|m: &mut FFIRequest| { &mut m.event },
|
||||
));
|
||||
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>(
|
||||
"payload",
|
||||
|m: &FFIRequest| { &m.payload },
|
||||
|m: &mut FFIRequest| { &mut m.payload },
|
||||
));
|
||||
::protobuf::reflect::MessageDescriptor::new_pb_name::<FFIRequest>(
|
||||
"FFIRequest",
|
||||
fields,
|
||||
file_descriptor_proto()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn default_instance() -> &'static FFIRequest {
|
||||
static instance: ::protobuf::rt::LazyV2<FFIRequest> = ::protobuf::rt::LazyV2::INIT;
|
||||
instance.get(FFIRequest::new)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::Clear for FFIRequest {
|
||||
fn clear(&mut self) {
|
||||
self.event.clear();
|
||||
self.payload.clear();
|
||||
self.unknown_fields.clear();
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::fmt::Debug for FFIRequest {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
||||
::protobuf::text_format::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::reflect::ProtobufValue for FFIRequest {
|
||||
fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
|
||||
::protobuf::reflect::ReflectValueRef::Message(self)
|
||||
}
|
||||
}
|
||||
|
||||
static file_descriptor_proto_data: &'static [u8] = b"\
|
||||
\n\x11ffi_request.proto\"<\n\nFFIRequest\x12\x14\n\x05event\x18\x01\x20\
|
||||
\x01(\tR\x05event\x12\x18\n\x07payload\x18\x02\x20\x01(\x0cR\x07payloadJ\
|
||||
\x98\x01\n\x06\x12\x04\0\0\x05\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\
|
||||
\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x12\
|
||||
\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x15\n\x0c\n\x05\x04\0\x02\0\x05\
|
||||
\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x10\n\x0c\
|
||||
\n\x05\x04\0\x02\0\x03\x12\x03\x03\x13\x14\n\x0b\n\x04\x04\0\x02\x01\x12\
|
||||
\x03\x04\x04\x16\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\t\n\x0c\n\
|
||||
\x05\x04\0\x02\x01\x01\x12\x03\x04\n\x11\n\x0c\n\x05\x04\0\x02\x01\x03\
|
||||
\x12\x03\x04\x14\x15b\x06proto3\
|
||||
";
|
||||
|
||||
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;
|
||||
|
||||
fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto {
|
||||
::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap()
|
||||
}
|
||||
|
||||
pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto {
|
||||
file_descriptor_proto_lazy.get(|| {
|
||||
parse_descriptor_proto()
|
||||
})
|
||||
}
|
301
frontend/rust-lib/dart-ffi/src/protobuf/model/ffi_response.rs
Normal file
301
frontend/rust-lib/dart-ffi/src/protobuf/model/ffi_response.rs
Normal file
@ -0,0 +1,301 @@
|
||||
// This file is generated by rust-protobuf 2.22.1. Do not edit
|
||||
// @generated
|
||||
|
||||
// https://github.com/rust-lang/rust-clippy/issues/702
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(clippy::all)]
|
||||
|
||||
#![allow(unused_attributes)]
|
||||
#![cfg_attr(rustfmt, rustfmt::skip)]
|
||||
|
||||
#![allow(box_pointers)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(missing_docs)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(trivial_casts)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(unused_results)]
|
||||
//! Generated file from `ffi_response.proto`
|
||||
|
||||
/// Generated files are compatible only with the same version
|
||||
/// of protobuf runtime.
|
||||
// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1;
|
||||
|
||||
#[derive(PartialEq,Clone,Default)]
|
||||
pub struct FFIResponse {
|
||||
// message fields
|
||||
pub payload: ::std::vec::Vec<u8>,
|
||||
pub code: FFIStatusCode,
|
||||
// special fields
|
||||
pub unknown_fields: ::protobuf::UnknownFields,
|
||||
pub cached_size: ::protobuf::CachedSize,
|
||||
}
|
||||
|
||||
impl<'a> ::std::default::Default for &'a FFIResponse {
|
||||
fn default() -> &'a FFIResponse {
|
||||
<FFIResponse as ::protobuf::Message>::default_instance()
|
||||
}
|
||||
}
|
||||
|
||||
impl FFIResponse {
|
||||
pub fn new() -> FFIResponse {
|
||||
::std::default::Default::default()
|
||||
}
|
||||
|
||||
// bytes payload = 1;
|
||||
|
||||
|
||||
pub fn get_payload(&self) -> &[u8] {
|
||||
&self.payload
|
||||
}
|
||||
pub fn clear_payload(&mut self) {
|
||||
self.payload.clear();
|
||||
}
|
||||
|
||||
// Param is passed by value, moved
|
||||
pub fn set_payload(&mut self, v: ::std::vec::Vec<u8>) {
|
||||
self.payload = v;
|
||||
}
|
||||
|
||||
// Mutable pointer to the field.
|
||||
// If field is not initialized, it is initialized with default value first.
|
||||
pub fn mut_payload(&mut self) -> &mut ::std::vec::Vec<u8> {
|
||||
&mut self.payload
|
||||
}
|
||||
|
||||
// Take field
|
||||
pub fn take_payload(&mut self) -> ::std::vec::Vec<u8> {
|
||||
::std::mem::replace(&mut self.payload, ::std::vec::Vec::new())
|
||||
}
|
||||
|
||||
// .FFIStatusCode code = 2;
|
||||
|
||||
|
||||
pub fn get_code(&self) -> FFIStatusCode {
|
||||
self.code
|
||||
}
|
||||
pub fn clear_code(&mut self) {
|
||||
self.code = FFIStatusCode::Ok;
|
||||
}
|
||||
|
||||
// Param is passed by value, moved
|
||||
pub fn set_code(&mut self, v: FFIStatusCode) {
|
||||
self.code = v;
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::Message for FFIResponse {
|
||||
fn is_initialized(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> {
|
||||
while !is.eof()? {
|
||||
let (field_number, wire_type) = is.read_tag_unpack()?;
|
||||
match field_number {
|
||||
1 => {
|
||||
::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.payload)?;
|
||||
},
|
||||
2 => {
|
||||
::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.code, 2, &mut self.unknown_fields)?
|
||||
},
|
||||
_ => {
|
||||
::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
|
||||
},
|
||||
};
|
||||
}
|
||||
::std::result::Result::Ok(())
|
||||
}
|
||||
|
||||
// Compute sizes of nested messages
|
||||
#[allow(unused_variables)]
|
||||
fn compute_size(&self) -> u32 {
|
||||
let mut my_size = 0;
|
||||
if !self.payload.is_empty() {
|
||||
my_size += ::protobuf::rt::bytes_size(1, &self.payload);
|
||||
}
|
||||
if self.code != FFIStatusCode::Ok {
|
||||
my_size += ::protobuf::rt::enum_size(2, self.code);
|
||||
}
|
||||
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
|
||||
self.cached_size.set(my_size);
|
||||
my_size
|
||||
}
|
||||
|
||||
fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
|
||||
if !self.payload.is_empty() {
|
||||
os.write_bytes(1, &self.payload)?;
|
||||
}
|
||||
if self.code != FFIStatusCode::Ok {
|
||||
os.write_enum(2, ::protobuf::ProtobufEnum::value(&self.code))?;
|
||||
}
|
||||
os.write_unknown_fields(self.get_unknown_fields())?;
|
||||
::std::result::Result::Ok(())
|
||||
}
|
||||
|
||||
fn get_cached_size(&self) -> u32 {
|
||||
self.cached_size.get()
|
||||
}
|
||||
|
||||
fn get_unknown_fields(&self) -> &::protobuf::UnknownFields {
|
||||
&self.unknown_fields
|
||||
}
|
||||
|
||||
fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields {
|
||||
&mut self.unknown_fields
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn (::std::any::Any) {
|
||||
self as &dyn (::std::any::Any)
|
||||
}
|
||||
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
|
||||
self as &mut dyn (::std::any::Any)
|
||||
}
|
||||
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
|
||||
self
|
||||
}
|
||||
|
||||
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
|
||||
Self::descriptor_static()
|
||||
}
|
||||
|
||||
fn new() -> FFIResponse {
|
||||
FFIResponse::new()
|
||||
}
|
||||
|
||||
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
|
||||
static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT;
|
||||
descriptor.get(|| {
|
||||
let mut fields = ::std::vec::Vec::new();
|
||||
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>(
|
||||
"payload",
|
||||
|m: &FFIResponse| { &m.payload },
|
||||
|m: &mut FFIResponse| { &mut m.payload },
|
||||
));
|
||||
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum<FFIStatusCode>>(
|
||||
"code",
|
||||
|m: &FFIResponse| { &m.code },
|
||||
|m: &mut FFIResponse| { &mut m.code },
|
||||
));
|
||||
::protobuf::reflect::MessageDescriptor::new_pb_name::<FFIResponse>(
|
||||
"FFIResponse",
|
||||
fields,
|
||||
file_descriptor_proto()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn default_instance() -> &'static FFIResponse {
|
||||
static instance: ::protobuf::rt::LazyV2<FFIResponse> = ::protobuf::rt::LazyV2::INIT;
|
||||
instance.get(FFIResponse::new)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::Clear for FFIResponse {
|
||||
fn clear(&mut self) {
|
||||
self.payload.clear();
|
||||
self.code = FFIStatusCode::Ok;
|
||||
self.unknown_fields.clear();
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::fmt::Debug for FFIResponse {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
||||
::protobuf::text_format::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::reflect::ProtobufValue for FFIResponse {
|
||||
fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
|
||||
::protobuf::reflect::ReflectValueRef::Message(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone,PartialEq,Eq,Debug,Hash)]
|
||||
pub enum FFIStatusCode {
|
||||
Ok = 0,
|
||||
Err = 1,
|
||||
Internal = 2,
|
||||
}
|
||||
|
||||
impl ::protobuf::ProtobufEnum for FFIStatusCode {
|
||||
fn value(&self) -> i32 {
|
||||
*self as i32
|
||||
}
|
||||
|
||||
fn from_i32(value: i32) -> ::std::option::Option<FFIStatusCode> {
|
||||
match value {
|
||||
0 => ::std::option::Option::Some(FFIStatusCode::Ok),
|
||||
1 => ::std::option::Option::Some(FFIStatusCode::Err),
|
||||
2 => ::std::option::Option::Some(FFIStatusCode::Internal),
|
||||
_ => ::std::option::Option::None
|
||||
}
|
||||
}
|
||||
|
||||
fn values() -> &'static [Self] {
|
||||
static values: &'static [FFIStatusCode] = &[
|
||||
FFIStatusCode::Ok,
|
||||
FFIStatusCode::Err,
|
||||
FFIStatusCode::Internal,
|
||||
];
|
||||
values
|
||||
}
|
||||
|
||||
fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor {
|
||||
static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT;
|
||||
descriptor.get(|| {
|
||||
::protobuf::reflect::EnumDescriptor::new_pb_name::<FFIStatusCode>("FFIStatusCode", file_descriptor_proto())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::marker::Copy for FFIStatusCode {
|
||||
}
|
||||
|
||||
impl ::std::default::Default for FFIStatusCode {
|
||||
fn default() -> Self {
|
||||
FFIStatusCode::Ok
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::reflect::ProtobufValue for FFIStatusCode {
|
||||
fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
|
||||
::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self))
|
||||
}
|
||||
}
|
||||
|
||||
static file_descriptor_proto_data: &'static [u8] = b"\
|
||||
\n\x12ffi_response.proto\"K\n\x0bFFIResponse\x12\x18\n\x07payload\x18\
|
||||
\x01\x20\x01(\x0cR\x07payload\x12\"\n\x04code\x18\x02\x20\x01(\x0e2\x0e.\
|
||||
FFIStatusCodeR\x04code*.\n\rFFIStatusCode\x12\x06\n\x02Ok\x10\0\x12\x07\
|
||||
\n\x03Err\x10\x01\x12\x0c\n\x08Internal\x10\x02J\xab\x02\n\x06\x12\x04\0\
|
||||
\0\n\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\
|
||||
\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x13\n\x0b\n\x04\x04\0\x02\0\
|
||||
\x12\x03\x03\x04\x16\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\t\n\x0c\
|
||||
\n\x05\x04\0\x02\0\x01\x12\x03\x03\n\x11\n\x0c\n\x05\x04\0\x02\0\x03\x12\
|
||||
\x03\x03\x14\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x1b\n\x0c\n\
|
||||
\x05\x04\0\x02\x01\x06\x12\x03\x04\x04\x11\n\x0c\n\x05\x04\0\x02\x01\x01\
|
||||
\x12\x03\x04\x12\x16\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x19\x1a\n\
|
||||
\n\n\x02\x05\0\x12\x04\x06\0\n\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\
|
||||
\x12\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\
|
||||
\x01\x12\x03\x07\x04\x06\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\t\n\n\
|
||||
\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x0c\n\x0c\n\x05\x05\0\x02\x01\
|
||||
\x01\x12\x03\x08\x04\x07\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\n\x0b\
|
||||
\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x11\n\x0c\n\x05\x05\0\x02\x02\
|
||||
\x01\x12\x03\t\x04\x0c\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\x0f\x10b\
|
||||
\x06proto3\
|
||||
";
|
||||
|
||||
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;
|
||||
|
||||
fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto {
|
||||
::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap()
|
||||
}
|
||||
|
||||
pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto {
|
||||
file_descriptor_proto_lazy.get(|| {
|
||||
parse_descriptor_proto()
|
||||
})
|
||||
}
|
7
frontend/rust-lib/dart-ffi/src/protobuf/model/mod.rs
Normal file
7
frontend/rust-lib/dart-ffi/src/protobuf/model/mod.rs
Normal file
@ -0,0 +1,7 @@
|
||||
// Auto-generated, do not edit
|
||||
|
||||
mod ffi_response;
|
||||
pub use ffi_response::*;
|
||||
|
||||
mod ffi_request;
|
||||
pub use ffi_request::*;
|
@ -0,0 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
message FFIRequest {
|
||||
string event = 1;
|
||||
bytes payload = 2;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
syntax = "proto3";
|
||||
|
||||
message FFIResponse {
|
||||
bytes payload = 1;
|
||||
FFIStatusCode code = 2;
|
||||
}
|
||||
enum FFIStatusCode {
|
||||
Ok = 0;
|
||||
Err = 1;
|
||||
Internal = 2;
|
||||
}
|
1
frontend/rust-lib/dart-ffi/src/util.rs
Normal file
1
frontend/rust-lib/dart-ffi/src/util.rs
Normal file
@ -0,0 +1 @@
|
||||
|
Reference in New Issue
Block a user