Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods returning just the deserializer #102

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion ciborium/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ impl<E: de::Error> Expected<E> for Header {
}
}

struct Deserializer<'b, R: Read> {
/// Deserializer
pub struct Deserializer<'b, R: Read> {
decoder: Decoder<R>,
scratch: &'b mut [u8],
recurse: usize,
Expand Down Expand Up @@ -873,3 +874,40 @@ where

T::deserialize(&mut reader)
}

/// Returns a deserializer with a specified scratch buffer
#[inline]
pub fn deserializer_from_reader_with_buffer<R: Read>(
reader: R,
scratch_buffer: &mut [u8],
) -> Deserializer<'_, R>
where
R::Error: core::fmt::Debug,
{
Deserializer {
decoder: reader.into(),
scratch: scratch_buffer,
recurse: 256,
}
}

/// Returns a deserializer with a specified scratch buffer
/// amd maximum recursion limit. Inputs that are nested beyond the specified limit
/// will result in [`Error::RecursionLimitExceeded`] .
///
/// Set a high recursion limit at your own risk (of stack exhaustion)!
#[inline]
pub fn deserializer_from_reader_with_buffer_and_recursion_limit<R: Read>(
reader: R,
scratch_buffer: &mut [u8],
recurse_limit: usize,
) -> Deserializer<'_, R>
where
R::Error: core::fmt::Debug,
{
Deserializer {
decoder: reader.into(),
scratch: scratch_buffer,
recurse: recurse_limit,
}
}
Loading