pub struct ProtocolRegistry { /* private fields */ }Expand description
Registry of built-in protocol decoders.
Implementations§
Source§impl ProtocolRegistry
impl ProtocolRegistry
Sourcepub fn with_builtins() -> Self
pub fn with_builtins() -> Self
Built-in registry with http and grpc registered.
Sourcepub fn http(&self) -> &HttpProtocol
pub fn http(&self) -> &HttpProtocol
HTTP protocol implementation.
Sourcepub fn grpc(&self) -> &GrpcProtocol
pub fn grpc(&self) -> &GrpcProtocol
gRPC protocol implementation.
Sourcepub fn decode_attachment(
&self,
attachment: &ProtocolAttachment,
) -> Result<DecodedAttachment>
pub fn decode_attachment( &self, attachment: &ProtocolAttachment, ) -> Result<DecodedAttachment>
Decode a protocol attachment envelope.
Built-in ids "http" and "grpc" deserialize to DecodedAttachment::Http
or DecodedAttachment::Grpc; other ids return
DecodedAttachment::Opaque with bytes unchanged.
§Examples
use switchback_codec_pb::canardleteer::switchback::protocol::http::v1alpha1::HttpOperationMeta;
use switchback_protocols::{DecodedAttachment, HttpPayloadKind, ProtocolRegistry};
let registry = ProtocolRegistry::with_builtins();
let attachment = registry.http().attach_operation(&HttpOperationMeta {
method: "GET".into(),
path_template: "/pets".into(),
..Default::default()
});
match registry.decode_attachment(&attachment).unwrap() {
DecodedAttachment::Http(HttpPayloadKind::Operation(m)) => assert_eq!(m.method, "GET"),
_ => panic!("expected operation meta"),
}Sourcepub fn http_operation_from_attachments(
&self,
protocols: &[ProtocolAttachment],
) -> Option<HttpOperationMeta>
pub fn http_operation_from_attachments( &self, protocols: &[ProtocolAttachment], ) -> Option<HttpOperationMeta>
Find the first HTTP operation meta on an operation body’s attachments.
Sourcepub fn grpc_operation_from_attachments(
&self,
protocols: &[ProtocolAttachment],
) -> Option<GrpcOperationMeta>
pub fn grpc_operation_from_attachments( &self, protocols: &[ProtocolAttachment], ) -> Option<GrpcOperationMeta>
Find the first gRPC operation meta on an operation body’s attachments.
Trait Implementations§
Source§impl Clone for ProtocolRegistry
impl Clone for ProtocolRegistry
Source§fn clone(&self) -> ProtocolRegistry
fn clone(&self) -> ProtocolRegistry
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 ProtocolRegistry
impl Debug for ProtocolRegistry
Source§impl Default for ProtocolRegistry
impl Default for ProtocolRegistry
Source§fn default() -> ProtocolRegistry
fn default() -> ProtocolRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ProtocolRegistry
impl RefUnwindSafe for ProtocolRegistry
impl Send for ProtocolRegistry
impl Sync for ProtocolRegistry
impl Unpin for ProtocolRegistry
impl UnsafeUnpin for ProtocolRegistry
impl UnwindSafe for ProtocolRegistry
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