pub struct DecodeOptions { /* private fields */ }Expand description
Options for configuring message decoding behavior.
Use this to set custom recursion depth limits or maximum message sizes when decoding from untrusted input.
§Examples
use buffa::DecodeOptions;
// Restrict recursion depth to 50 and message size to 1 MiB:
let msg: Person = DecodeOptions::new()
.with_recursion_limit(50)
.with_max_message_size(1024 * 1024)
.decode_from_slice(bytes)?;Implementations§
Source§impl DecodeOptions
impl DecodeOptions
Sourcepub fn new() -> Self
pub fn new() -> Self
Create new decode options with defaults.
Defaults:
recursion_limit: 100 (same asRECURSION_LIMIT)max_message_size: 2 GiB - 1
Sourcepub fn with_recursion_limit(self, limit: u32) -> Self
pub fn with_recursion_limit(self, limit: u32) -> Self
Set the maximum recursion depth for nested messages.
Each nested sub-message consumes one level of depth budget. When
the budget reaches zero, decoding returns
DecodeError::RecursionLimitExceeded.
Default: 100.
Sourcepub fn with_max_message_size(self, max_bytes: usize) -> Self
pub fn with_max_message_size(self, max_bytes: usize) -> Self
Set the maximum total message size in bytes.
If the input buffer or length-delimited payload exceeds this size,
decoding returns DecodeError::MessageTooLarge.
This is checked at the top-level decode entry point. Individual sub-messages are still bounded by the internal 2 GiB limit regardless of this setting.
Default: 2 GiB - 1 (0x7FFF_FFFF).
Sourcepub fn recursion_limit(&self) -> u32
pub fn recursion_limit(&self) -> u32
Returns the configured recursion depth limit.
Sourcepub fn max_message_size(&self) -> usize
pub fn max_message_size(&self) -> usize
Returns the configured maximum message size in bytes.
Sourcepub fn decode<M: Message>(&self, buf: &mut impl Buf) -> Result<M, DecodeError>
pub fn decode<M: Message>(&self, buf: &mut impl Buf) -> Result<M, DecodeError>
Decode a message from a buffer.
Sourcepub fn decode_from_slice<M: Message>(
&self,
data: &[u8],
) -> Result<M, DecodeError>
pub fn decode_from_slice<M: Message>( &self, data: &[u8], ) -> Result<M, DecodeError>
Decode a message from a byte slice.
Sourcepub fn decode_length_delimited<M: Message>(
&self,
buf: &mut impl Buf,
) -> Result<M, DecodeError>
pub fn decode_length_delimited<M: Message>( &self, buf: &mut impl Buf, ) -> Result<M, DecodeError>
Decode a length-delimited message from a buffer.
Sourcepub fn merge<M: Message>(
&self,
msg: &mut M,
buf: &mut impl Buf,
) -> Result<(), DecodeError>
pub fn merge<M: Message>( &self, msg: &mut M, buf: &mut impl Buf, ) -> Result<(), DecodeError>
Merge fields from a buffer into an existing message.
Sourcepub fn merge_from_slice<M: Message>(
&self,
msg: &mut M,
data: &[u8],
) -> Result<(), DecodeError>
pub fn merge_from_slice<M: Message>( &self, msg: &mut M, data: &[u8], ) -> Result<(), DecodeError>
Merge fields from a byte slice into an existing message.
Sourcepub fn decode_view<'a, V: MessageView<'a>>(
&self,
buf: &'a [u8],
) -> Result<V, DecodeError>
pub fn decode_view<'a, V: MessageView<'a>>( &self, buf: &'a [u8], ) -> Result<V, DecodeError>
Decode a zero-copy view from a byte slice.
Sourcepub fn decode_reader<M: Message>(
&self,
reader: &mut impl Read,
) -> Result<M, Error>
Available on crate feature std only.
pub fn decode_reader<M: Message>( &self, reader: &mut impl Read, ) -> Result<M, Error>
std only.Decode a message by reading all bytes from a std::io::Read source.
Reads until EOF, enforces max_message_size, then decodes the
buffered bytes. Returns std::io::Error to be compatible with
Read-based error handling.
Sourcepub fn decode_length_delimited_reader<M: Message>(
&self,
reader: &mut impl Read,
) -> Result<M, Error>
Available on crate feature std only.
pub fn decode_length_delimited_reader<M: Message>( &self, reader: &mut impl Read, ) -> Result<M, Error>
std only.Decode a length-delimited message from a std::io::Read source.
Reads a varint length prefix, enforces max_message_size, reads
exactly that many bytes, then decodes. Useful for reading sequential
length-delimited messages from a file or stream.
Trait Implementations§
Source§impl Clone for DecodeOptions
impl Clone for DecodeOptions
Source§fn clone(&self) -> DecodeOptions
fn clone(&self) -> DecodeOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more