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>

source

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(...).

Trait Implementations§

source§

impl<'a> TInputProtocol for TStoredInputProtocol<'a>

source§

fn read_message_begin(&mut self) -> Result<TMessageIdentifier>

Read the beginning of a Thrift message.
source§

fn read_message_end(&mut self) -> Result<()>

Read the end of a Thrift message.
source§

fn read_struct_begin(&mut self) -> Result<Option<TStructIdentifier>>

Read the beginning of a Thrift struct.
source§

fn read_struct_end(&mut self) -> Result<()>

Read the end of a Thrift struct.
source§

fn read_field_begin(&mut self) -> Result<TFieldIdentifier>

Read the beginning of a Thrift struct field.
source§

fn read_field_end(&mut self) -> Result<()>

Read the end of a Thrift struct field.
source§

fn read_bytes(&mut self) -> Result<Vec<u8>>

Read a fixed-length byte array.
source§

fn read_bool(&mut self) -> Result<bool>

Read a bool.
source§

fn read_i8(&mut self) -> Result<i8>

Read a word.
source§

fn read_i16(&mut self) -> Result<i16>

Read a 16-bit signed integer.
source§

fn read_i32(&mut self) -> Result<i32>

Read a 32-bit signed integer.
source§

fn read_i64(&mut self) -> Result<i64>

Read a 64-bit signed integer.
source§

fn read_double(&mut self) -> Result<f64>

Read a 64-bit float.
source§

fn read_string(&mut self) -> Result<String>

Read a fixed-length string (not null terminated).
source§

fn read_list_begin(&mut self) -> Result<TListIdentifier>

Read the beginning of a list.
source§

fn read_list_end(&mut self) -> Result<()>

Read the end of a list.
source§

fn read_set_begin(&mut self) -> Result<TSetIdentifier>

Read the beginning of a set.
source§

fn read_set_end(&mut self) -> Result<()>

Read the end of a set.
source§

fn read_map_begin(&mut self) -> Result<TMapIdentifier>

Read the beginning of a map.
source§

fn read_map_end(&mut self) -> Result<()>

Read the end of a map.
source§

fn read_byte(&mut self) -> Result<u8>

Read an unsigned byte. Read more
source§

fn skip(&mut self, field_type: TType) -> Result<()>

Skip a field with type field_type recursively until the default maximum skip depth is reached.
source§

fn skip_till_depth(&mut self, field_type: TType, depth: i8) -> Result<()>

Skip a field with type field_type recursively up to depth levels.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.