Struct thrift::protocol::TStoredInputProtocol
source · pub struct TStoredInputProtocol<'a> { /* private fields */ }
Expand description
TInputProtocol
required to use a TMultiplexedProcessor
.
A TMultiplexedProcessor
reads incoming message identifiers to determine to
which TProcessor
requests should be forwarded. However, once read, those
message identifier bytes are no longer on the wire. Since downstream
processors expect to read message identifiers from the given input protocol
we need some way of supplying a TMessageIdentifier
with the service-name
stripped. This implementation stores the received TMessageIdentifier
(without the service name) and passes it to the wrapped TInputProtocol
when TInputProtocol::read_message_begin(...)
is called. It delegates all
other calls directly to the wrapped TInputProtocol
.
This type should not be used by application code.
Examples
Create and use a TStoredInputProtocol
.
use thrift::protocol::{TInputProtocol, TMessageIdentifier, TMessageType, TOutputProtocol};
use thrift::protocol::{TBinaryInputProtocol, TBinaryOutputProtocol, TStoredInputProtocol};
use thrift::server::TProcessor;
use thrift::transport::{TIoChannel, TTcpChannel};
// sample processor
struct ActualProcessor;
impl TProcessor for ActualProcessor {
fn process(
&self,
_: &mut dyn TInputProtocol,
_: &mut dyn TOutputProtocol
) -> thrift::Result<()> {
unimplemented!()
}
}
let processor = ActualProcessor {};
// construct the shared transport
let mut channel = TTcpChannel::new();
channel.open("localhost:9090").unwrap();
let (i_chan, o_chan) = channel.split().unwrap();
// construct the actual input and output protocols
let mut i_prot = TBinaryInputProtocol::new(i_chan, true);
let mut o_prot = TBinaryOutputProtocol::new(o_chan, true);
// message identifier received from remote and modified to remove the service name
let new_msg_ident = TMessageIdentifier::new("service_call", TMessageType::Call, 1);
// construct the proxy input protocol
let mut proxy_i_prot = TStoredInputProtocol::new(&mut i_prot, new_msg_ident);
let res = processor.process(&mut proxy_i_prot, &mut o_prot);
Implementations§
source§impl<'a> TStoredInputProtocol<'a>
impl<'a> TStoredInputProtocol<'a>
sourcepub fn new(
wrapped: &mut dyn TInputProtocol,
message_ident: TMessageIdentifier
) -> TStoredInputProtocol<'_>
pub fn new( wrapped: &mut dyn TInputProtocol, message_ident: TMessageIdentifier ) -> TStoredInputProtocol<'_>
Create a TStoredInputProtocol
that delegates all calls other than
TInputProtocol::read_message_begin(...)
to a wrapped
TInputProtocol
. message_ident
is the modified message identifier -
with service name stripped - that will be passed to
wrapped.read_message_begin(...)
.