pub struct GrpcTranscoder { /* private fields */ }Expand description
The gRPC-Web + JSON transcoding engine. Loaded at config publish from .proto descriptor files; holds a method map keyed by the fully- qualified gRPC method path.
The transcoding uses prost for protobuf encoding/decoding. Because the descriptors are supplied at runtime (not compiled in), the transcoder works with the dynamic protobuf descriptor model: it reads the FileDescriptorSet, resolves message types by name, and encodes/decodes fields by walking the descriptor’s field list. This avoids any build-time code generation.
Implementations§
Source§impl GrpcTranscoder
impl GrpcTranscoder
Sourcepub fn from_descriptors(
descriptors: Vec<LoadedDescriptor>,
) -> Result<Self, GrpcWebError>
pub fn from_descriptors( descriptors: Vec<LoadedDescriptor>, ) -> Result<Self, GrpcWebError>
Build a transcoder from loaded descriptors. Parses each FileDescriptorSet, resolves the service’s methods, and builds the method map.
Sourcepub fn method(&self, full_path: &str) -> Option<&MethodInfo>
pub fn method(&self, full_path: &str) -> Option<&MethodInfo>
Look up a method by its fully-qualified path
(/{package}.{service}/{method}).
Sourcepub fn method_count(&self) -> usize
pub fn method_count(&self) -> usize
The number of resolved methods.
Sourcepub fn json_to_grpc(
&self,
method: &str,
json: &Value,
) -> Result<Vec<u8>, GrpcWebError>
pub fn json_to_grpc( &self, method: &str, json: &Value, ) -> Result<Vec<u8>, GrpcWebError>
Translate a JSON request body to protobuf wire bytes for the given gRPC method. The returned bytes are the raw protobuf message (without the 5-byte gRPC length prefix — the caller adds that when framing the native gRPC request).
Sourcepub fn grpc_to_json(
&self,
method: &str,
proto_bytes: &[u8],
) -> Result<Value, GrpcWebError>
pub fn grpc_to_json( &self, method: &str, proto_bytes: &[u8], ) -> Result<Value, GrpcWebError>
Translate a protobuf response body to JSON for the given gRPC
method. The input proto_bytes are the raw protobuf message
bytes (without the 5-byte gRPC length prefix).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GrpcTranscoder
impl RefUnwindSafe for GrpcTranscoder
impl Send for GrpcTranscoder
impl Sync for GrpcTranscoder
impl Unpin for GrpcTranscoder
impl UnwindSafe for GrpcTranscoder
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
T behind Box pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Self to T,
useful only in generic context as a workaround for specializationSource§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<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more