pub struct Codec { /* private fields */ }Expand description
gRPC length-prefixed framing codec.
Handles the 5-byte gRPC frame header (1 byte compression flag + 4 byte big-endian length) and protobuf encode/decode with optional compression.
Implementations§
Source§impl Codec
impl Codec
pub fn new() -> Codec
pub fn from_headers(headers: &HeaderMap) -> Codec
Sourcepub fn set_limit(&mut self, limit: usize)
pub fn set_limit(&mut self, limit: usize)
Set the maximum allowed size in bytes for a single gRPC message frame.
Set to 0 for unlimited.
pub const fn limit(&self) -> usize
Sourcepub fn decode<T>(&self, src: &mut BytesMut) -> Result<Option<T>, ProtocolError>
pub fn decode<T>(&self, src: &mut BytesMut) -> Result<Option<T>, ProtocolError>
Try to decode a complete gRPC message from src.
Consumes the frame bytes from src on success.
Returns:
Ok(Some(message))when a complete frame is availableOk(None)when more data is neededErron protocol violations (size limit, decode error)
Sourcepub fn encode<T>(
&self,
msg: &T,
dst: &mut BytesMut,
) -> Result<(), ProtocolError>where
T: Message,
pub fn encode<T>(
&self,
msg: &T,
dst: &mut BytesMut,
) -> Result<(), ProtocolError>where
T: Message,
Encode a protobuf message into gRPC length-prefixed framing.
Writes to dst: 1 byte compression flag + 4 byte big-endian length + payload.
When compression is enabled and the compress feature is active, the payload
is compressed and the flag byte is set to 1.
Auto Trait Implementations§
impl Freeze for Codec
impl RefUnwindSafe for Codec
impl Send for Codec
impl Sync for Codec
impl Unpin for Codec
impl UnsafeUnpin for Codec
impl UnwindSafe for Codec
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