pub struct Codec {
prefix: String,
content_types: Vec<Box<str>>,
default_ct: String,
max_encoded_len: usize,
max_decoded_body: usize,
max_payload_bytes: usize,
}Expand description
Validated parcel codec; construct with Codec::new and reuse across calls.
Fields§
§prefix: String§content_types: Vec<Box<str>>§default_ct: String§max_encoded_len: usize§max_decoded_body: usize§max_payload_bytes: usizeImplementations§
Source§impl Codec
impl Codec
Sourcepub fn new(config: CodecConfig) -> Result<Self, CodecBuildError>
pub fn new(config: CodecConfig) -> Result<Self, CodecBuildError>
Validate config and produce a ready-to-use Codec.
§Errors
Returns CodecBuildError when the prefix or content-type configuration is invalid.
Sourcepub fn default_content_type(&self) -> &str
pub fn default_content_type(&self) -> &str
The default content type used when Codec::encode is called without an override.
Sourcepub fn encode(
&self,
payload: &[u8],
content_type: Option<&str>,
) -> Result<String, ParcelError>
pub fn encode( &self, payload: &[u8], content_type: Option<&str>, ) -> Result<String, ParcelError>
Encode payload into a parcel envelope (None content type uses the default).
§Errors
Returns ParcelError for invalid input, compression failure, or an oversized envelope.
Sourcepub fn decode(&self, encoded: &str) -> Result<DecodedParcel, ParcelError>
pub fn decode(&self, encoded: &str) -> Result<DecodedParcel, ParcelError>
Decode a parcel envelope into the recovered payload bytes plus metadata.
§Errors
Returns ParcelError for an invalid envelope, checksum, body, or configured limit.
Sourcepub fn inspect(&self, encoded: &str) -> String
pub fn inspect(&self, encoded: &str) -> String
Decode encoded and render a multi-line human-readable summary (not a transport format).
fn parse<'a>( &self, encoded: &'a str, ) -> Result<(&'a str, &'a str, &'a str), ParcelError>
Trait Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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>
Converts
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>
Converts
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