pub struct Transcoder { /* private fields */ }Expand description
Transcodes application messages between JSON and binary protobuf, keyed by
gRPC method path (/pkg.Service/Method), and maps google.api.http REST
bindings onto gRPC methods.
Implementations§
Source§impl Transcoder
impl Transcoder
Sourcepub fn from_file_descriptor_set(bytes: &[u8]) -> Result<Self, TranscodeError>
pub fn from_file_descriptor_set(bytes: &[u8]) -> Result<Self, TranscodeError>
Build from an encoded FileDescriptorSet.
Sourcepub fn has_http_rules(&self) -> bool
pub fn has_http_rules(&self) -> bool
Whether any google.api.http REST bindings were found.
Sourcepub fn transcode_http_request(
&self,
method: &str,
path: &str,
query: Option<&str>,
body: &[u8],
) -> Result<Option<HttpCall>, TranscodeError>
pub fn transcode_http_request( &self, method: &str, path: &str, query: Option<&str>, body: &[u8], ) -> Result<Option<HttpCall>, TranscodeError>
Map a REST request (method, path, query, body) onto a gRPC call, or
Ok(None) if no HTTP binding matches.
Sourcepub fn match_ws(&self, path: &str, query: Option<&str>) -> Option<WsBinding>
pub fn match_ws(&self, path: &str, query: Option<&str>) -> Option<WsBinding>
Resolve a WebSocket annotation route from its upgrade path, or None if the
path matches no binding.
Sourcepub fn is_annotated_method(&self, grpc_method: &str) -> bool
pub fn is_annotated_method(&self, grpc_method: &str) -> bool
Whether a gRPC method has any HTTP annotation (used to keep an annotated RPC’s main route off the plain-HTTP surface).
Sourcepub fn has_method(&self, path: &str) -> bool
pub fn has_method(&self, path: &str) -> bool
Whether path (/pkg.Service/Method) resolves to a known method — i.e. this
transcoder can handle it. Callers use it to distinguish “unknown method”
(UNIMPLEMENTED) from a genuine transcode/validation failure.
Sourcepub fn request_json_to_proto(
&self,
path: &str,
json: &[u8],
) -> Result<Vec<u8>, TranscodeError>
pub fn request_json_to_proto( &self, path: &str, json: &[u8], ) -> Result<Vec<u8>, TranscodeError>
JSON request message -> binary protobuf. Empty input is the default message.
Sourcepub fn response_proto_to_json(
&self,
path: &str,
proto: &[u8],
) -> Result<Vec<u8>, TranscodeError>
pub fn response_proto_to_json( &self, path: &str, proto: &[u8], ) -> Result<Vec<u8>, TranscodeError>
Binary protobuf response message -> JSON.
Trait Implementations§
Source§impl Clone for Transcoder
impl Clone for Transcoder
Source§fn clone(&self) -> Transcoder
fn clone(&self) -> Transcoder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Transcoder
impl RefUnwindSafe for Transcoder
impl Send for Transcoder
impl Sync for Transcoder
impl Unpin for Transcoder
impl UnsafeUnpin for Transcoder
impl UnwindSafe for Transcoder
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
T in a tonic::Request