pub struct RpcServiceImplDefines<'a> {
pub service: &'a RpcService,
pub extra_args: &'a [(&'a str, &'a str)],
pub on_invalid_request_cb: &'a str,
pub is_size_prefixed: bool,
pub default_message_limit: &'a str,
}
Expand description
Generates module file interface to parse and forward flatbuffer requests to user’s created modules’ functions
Generated code has following requirements:
§Dependencies
flatbuffers
- To parse and generate flatbufferxxhash-rust
- To generate efficient method dispatcher using 128bit hashes. Needs featuresxxh3
andconst_xxh3
§User modules
Assuming schema has two methods daily
and transform_new_image
, file will import following
modules and functions:
mod daily;
pub use daily::daily;
mod transform_new_image;
pub use transform_new_image::transform_new_image;
§Module function signature:
pub async fn daily<'a, 'b>(
rpc_argument: &Request,
mandatory_flatbuffer_builder: &'b mut FlatBufferBuilder<'a>,
extra_arg: &ExtraArgument,
) -> Result<ResponseBuilder<'a, 'b>, CommonError> {
§Result type
In above example ResponseBuilder
MUST be builder struct generated by flatc
which uses mandatory_flatbuffer_builder
§Error type
In above example CommonError
must implement following method:
impl Error {
#[inline]
///Creates flatbuffer error object
pub fn to_interface<'a>(
&self,
builder: &mut flatbuffers::FlatBufferBuilder<'a>,
) -> flatbuffers::WIPOffset<interface::Error<'a>> {
todo!()
}
}
Where interface::Error
MUST be flatbuffer struct generated by flatc
§Dispatch signature
As result following signature will be generated:
pub async fn dispatch(extra_arg: &ExtraArgument, method: &str, input: &[u8], builder: &mut flatbuffers::FlatBufferBuilder<'_>) -> Option<Result<(), ()>>;
Where return result indicates following:
None
- Unknown method
Some(Ok(()))
- RPC call dispatched successfully, result is written to builder
Some(Err(()))
- RPC call failed, error is written to builder
Fields§
§service: &'a RpcService
Service definition
extra_args: &'a [(&'a str, &'a str)]
Extra arguments to define in dispatch
and pass to every RPC method
Following names are used by code generator:
method
input
builder
on_invalid_request_cb: &'a str
Callback to be called when RPC input cannot be parsed
Must have following signature
fn on_invalid_request(builder: &mut flatbuffers::FlatBufferBuilder, error: flatbuffers::InvalidFlatbuffer) -> Option<Result<(), ()>>;
is_size_prefixed: bool
Specifies whether flatbuffers input and output MUST be prefixed with size
.
Namely it increases size of message by adding header with size when set to true
.
default_message_limit: &'a str
Defines constant to limit flatbuffer message size.
Trait Implementations§
Source§impl<'a> Clone for RpcServiceImplDefines<'a>
impl<'a> Clone for RpcServiceImplDefines<'a>
Source§fn clone(&self) -> RpcServiceImplDefines<'a>
fn clone(&self) -> RpcServiceImplDefines<'a>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more