pub struct RequestMessage { /* private fields */ }
Expand description
Holds all the necessary data for a gRPC
request, including
the message, method descriptor, and optional metadata.
Implementations§
Source§impl RequestMessage
impl RequestMessage
Sourcepub fn new(
message_desc: MessageDescriptor,
method_desc: MethodDescriptor,
) -> Self
pub fn new( message_desc: MessageDescriptor, method_desc: MethodDescriptor, ) -> Self
Create a new RequestMessage
with the provided message
descriptor and method descriptor.
Sourcepub fn message_name(&self) -> String
pub fn message_name(&self) -> String
Get the name of the message.
Sourcepub fn message_descriptor(&self) -> MessageDescriptor
pub fn message_descriptor(&self) -> MessageDescriptor
Get the message descriptor associated with the RequestMessage
.
Sourcepub fn method_descriptor(&self) -> MethodDescriptor
pub fn method_descriptor(&self) -> MethodDescriptor
Get the method descriptor associated with the RequestMessage
.
Sourcepub fn message(&self) -> &DynamicMessage
pub fn message(&self) -> &DynamicMessage
Gets a reference to the message.
Sourcepub fn message_mut(&mut self) -> &mut DynamicMessage
pub fn message_mut(&mut self) -> &mut DynamicMessage
Gets a mutable reference to the message.
Sourcepub fn set_message(&mut self, message: DynamicMessage)
pub fn set_message(&mut self, message: DynamicMessage)
Set a new message for the request.
Sourcepub fn set_address(&mut self, address: &str)
pub fn set_address(&mut self, address: &str)
Sets the host address.
Examples found in repository?
examples/reflection.rs (line 21)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
async fn main() -> Result<()> {
let request = ReflectionRequest::new("http://localhost:50051");
let desc = ProtoDescriptor::from_reflection(request).await?;
let service = &desc.get_services()[0];
let method = &desc.get_methods(service)[1];
println!("Service: {:}", service.full_name());
println!("Method: {:}", method.full_name());
//
let mut req = desc.get_request(&method);
req.set_address("http://localhost:50051");
let mut req = desc.get_request(&method);
req.set_address("http://localhost:50051");
Ok(())
}
More examples
examples/metadata.rs (line 22)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
async fn main() -> Result<()> {
let desc = ProtoDescriptor::new(
vec!["/Users/philippreiter/Rust/wireman/example"],
vec!["grpc_simple/debugger.proto"],
)?;
let service = &desc.get_services()[0];
let method = &desc.get_methods(service)[1];
println!("Service: {:}", service.full_name());
println!("Method: {:}", method.full_name());
let mut req = desc.get_request(&method);
req.set_address("http://localhost:50051");
let resp = do_request(&req).await?;
println!("\nResponse:\n{:}", resp.message.to_json()?);
Ok(())
}
examples/streaming.rs (line 23)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
async fn main() -> Result<()> {
let desc = ProtoDescriptor::new(
vec!["/Users/philippreiter/Rust/wireman/example/server/streaming"],
vec!["streaming.proto"],
)?;
let service = &desc.get_services()[0];
let method = &desc.get_methods(service)[0];
if !method.is_server_streaming() {
println!("Method must be server streaming");
}
let mut request = desc.get_request(&method);
request.set_address("http://localhost:50051");
let response = call_server_streaming(&request, None).await?;
let mut pinned = std::pin::pin!(response);
let stream = pinned.as_mut().get_mut();
while let Some(message) = stream.next().await {
let message = message?;
println!("message: {:?}", message.message);
println!();
}
Ok(())
}
Sourcepub fn path(&self) -> PathAndQuery
pub fn path(&self) -> PathAndQuery
Get the URI path for gRPC
calls based on the method descriptor.
§Panics
Panics if constructing the path and query from a string fails.
Trait Implementations§
Source§impl Clone for RequestMessage
impl Clone for RequestMessage
Source§fn clone(&self) -> RequestMessage
fn clone(&self) -> RequestMessage
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for RequestMessage
impl Debug for RequestMessage
Source§impl From<RequestMessage> for Request<RequestMessage>
impl From<RequestMessage> for Request<RequestMessage>
Source§fn from(value: RequestMessage) -> Self
fn from(value: RequestMessage) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for RequestMessage
impl RefUnwindSafe for RequestMessage
impl Send for RequestMessage
impl Sync for RequestMessage
impl Unpin for RequestMessage
impl UnwindSafe for RequestMessage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request