pub trait Transport {
type TXState;
type RXState;
fn tx_begin_call(
&mut self,
method: MethodId
) -> Result<Self::TXState, RPCError>;
fn tx_add_param(
&mut self,
name: &'static str,
value: impl Serialize,
state: &mut Self::TXState
) -> Result<(), RPCError>;
fn tx_finalize(&mut self, state: &mut Self::TXState) -> Result<(), RPCError>;
fn tx_response(&mut self, value: impl Serialize) -> Result<(), RPCError>;
fn rx_begin_call(
&mut self
) -> Result<(PartialMethodId, Self::RXState), RPCError>;
fn rx_read_param<T>(
&mut self,
name: &'static str,
state: &mut Self::RXState
) -> Result<T, RPCError>
where
for<'de> T: Deserialize<'de>;
fn rx_response<T>(&mut self) -> Result<T, RPCError>
where
for<'de> T: Deserialize<'de>;
}
Expand description
Trait for RPC transport. ESSRPC attempts to make as few assumptions about the transport as possible. A transport may work across a network, via any IPC mechanism, or purely in memory within a single process.
Required Associated Types§
Required Methods§
sourcefn tx_begin_call(&mut self, method: MethodId) -> Result<Self::TXState, RPCError>
fn tx_begin_call(&mut self, method: MethodId) -> Result<Self::TXState, RPCError>
Begin calling the given method. The transport may begin transmitting over the wire,
or it may may wait until the call to tx_finalize
.
sourcefn tx_add_param(
&mut self,
name: &'static str,
value: impl Serialize,
state: &mut Self::TXState
) -> Result<(), RPCError>
fn tx_add_param(
&mut self,
name: &'static str,
value: impl Serialize,
state: &mut Self::TXState
) -> Result<(), RPCError>
Add a parameter to a method call started with
tx_begin_call
. This method is guaranteed to be called only
after tx_begin_call
and to be called appropriately for each
parameter of the method passed to tx_begin_call
. state
is
the object returned by tx_begin_call
. Parameters are always
added and read in order, so transmitting the name is not a requirement.
sourcefn tx_finalize(&mut self, state: &mut Self::TXState) -> Result<(), RPCError>
fn tx_finalize(&mut self, state: &mut Self::TXState) -> Result<(), RPCError>
Finalize transmission of a method call. Called only after
tx_begin_call
and appropriate calls to tx_add_param
. If
the transport has not yet transmitted the method identifier
and parameters over the wire, it should do so at this time.
sourcefn tx_response(&mut self, value: impl Serialize) -> Result<(), RPCError>
fn tx_response(&mut self, value: impl Serialize) -> Result<(), RPCError>
Transmit a response (from the server side) to a method call.
sourcefn rx_begin_call(
&mut self
) -> Result<(PartialMethodId, Self::RXState), RPCError>
fn rx_begin_call(
&mut self
) -> Result<(PartialMethodId, Self::RXState), RPCError>
Begin reading a method cal on the server. Returns the method name or identifier and internal state.
sourcefn rx_read_param<T>(
&mut self,
name: &'static str,
state: &mut Self::RXState
) -> Result<T, RPCError>where
for<'de> T: Deserialize<'de>,
fn rx_read_param<T>(
&mut self,
name: &'static str,
state: &mut Self::RXState
) -> Result<T, RPCError>where
for<'de> T: Deserialize<'de>,
Read a method parameter after a an rx_begin_call
. Parameters
are always read in order, so some transports may choose to
ignore the name.
sourcefn rx_response<T>(&mut self) -> Result<T, RPCError>where
for<'de> T: Deserialize<'de>,
fn rx_response<T>(&mut self) -> Result<T, RPCError>where
for<'de> T: Deserialize<'de>,
Read the return value of a method call. Always called after tx_finalize
.