pub struct RpcClient<S> { /* private fields */ }Expand description
A minimal Cap’n Proto RPC client for tunnel registration.
Implements the exact wire sequence cloudflared uses on its control
stream: bootstrap to obtain the peer’s main interface, then
call/return/finish for each registration method. Question ids are
allocated monotonically from 0 and the bootstrapped capability is
tracked as import id 0.
All capnp message construction and decoding happens in synchronous
helpers so no non-Send capnp state is held across an await, keeping
every future Send.
Implementations§
Source§impl<S: AsyncStream + Unpin> RpcClient<S>
impl<S: AsyncStream + Unpin> RpcClient<S>
Sourcepub fn into_inner(self) -> S
pub fn into_inner(self) -> S
Returns the underlying stream (the connection stays open).
Sourcepub async fn bootstrap(&mut self) -> Result<u32, RpcError>
pub async fn bootstrap(&mut self) -> Result<u32, RpcError>
Sends Message::bootstrap and waits for the return carrying the
peer’s main interface. Returns the import id to use for calls.
Sourcepub async fn call<T>(
&mut self,
import_identifier: u32,
interface_identifier: u64,
method_identifier: u16,
fill_parameters: impl FnOnce(&mut Builder<'_>) -> Result<(), RpcError>,
decode: impl FnOnce(Reader<'_>) -> Result<T, RpcError>,
) -> Result<T, RpcError>
pub async fn call<T>( &mut self, import_identifier: u32, interface_identifier: u64, method_identifier: u16, fill_parameters: impl FnOnce(&mut Builder<'_>) -> Result<(), RpcError>, decode: impl FnOnce(Reader<'_>) -> Result<T, RpcError>, ) -> Result<T, RpcError>
Performs a method call on an imported capability, decodes the results
payload with decode, then sends finish for the question.