pub struct Limits {
pub max_message_bytes: u32,
pub max_payload_bytes: u32,
pub max_records: u32,
pub max_allocation_bytes: u32,
}Expand description
Bounded decoder policy applied before a protocol allocates or creates records.
Fields§
§max_message_bytes: u32Maximum complete encoded message size.
max_payload_bytes: u32Maximum opaque payload size after the common envelope.
max_records: u32Maximum variable records a protocol decoder may construct.
max_allocation_bytes: u32Maximum aggregate allocation a protocol decoder may perform.
Implementations§
Source§impl Limits
impl Limits
Sourcepub const fn new(
max_message_bytes: u32,
max_payload_bytes: u32,
max_records: u32,
max_allocation_bytes: u32,
) -> Self
pub const fn new( max_message_bytes: u32, max_payload_bytes: u32, max_records: u32, max_allocation_bytes: u32, ) -> Self
Creates an explicit decoder policy.
Examples found in repository?
examples/bounded_codec.rs (line 42)
38fn main() -> Result<(), Box<dyn std::error::Error>> {
39 let mut wire = [0_u8; 128];
40 let written = encode_message::<CounterProtocol>(Envelope::new(1, 0, 7, 1), &42, &mut wire)?;
41
42 let limits = Limits::new(128, 16, 1, 16);
43 let decoded = decode_message::<CounterProtocol>(&wire[..written], &limits)?;
44
45 assert_eq!(decoded.message, 42);
46 assert_eq!(decoded.envelope.generation, 7);
47 println!(
48 "decoded counter {} from {} bounded bytes",
49 decoded.message, written
50 );
51 Ok(())
52}Trait Implementations§
impl Copy for Limits
impl Eq for Limits
impl StructuralPartialEq for Limits
Auto Trait Implementations§
impl Freeze for Limits
impl RefUnwindSafe for Limits
impl Send for Limits
impl Sync for Limits
impl Unpin for Limits
impl UnsafeUnpin for Limits
impl UnwindSafe for Limits
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