Skip to content

Commit c19bf22

Browse files
elrafoonrjzak
authored andcommitted
feat: add methods returning just the deserializer
- fn deserializer_from_reader_with_buffer() - fn deserializer_from_reader_with_buffer_and_recursion_limit() Signed-off-by: Stanislav Ravas <[email protected]>
1 parent 422face commit c19bf22

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

ciborium/src/de/mod.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ impl<E: de::Error> Expected<E> for Header {
4545
}
4646
}
4747

48-
struct Deserializer<'b, R: Read> {
48+
/// Deserializer
49+
pub struct Deserializer<'b, R: Read> {
4950
decoder: Decoder<R>,
5051
scratch: &'b mut [u8],
5152
recurse: usize,
@@ -873,3 +874,40 @@ where
873874

874875
T::deserialize(&mut reader)
875876
}
877+
878+
/// Returns a deserializer with a specified scratch buffer
879+
#[inline]
880+
pub fn deserializer_from_reader_with_buffer<R: Read>(
881+
reader: R,
882+
scratch_buffer: &mut [u8],
883+
) -> Deserializer<'_, R>
884+
where
885+
R::Error: core::fmt::Debug,
886+
{
887+
Deserializer {
888+
decoder: reader.into(),
889+
scratch: scratch_buffer,
890+
recurse: 256,
891+
}
892+
}
893+
894+
/// Returns a deserializer with a specified scratch buffer
895+
/// amd maximum recursion limit. Inputs that are nested beyond the specified limit
896+
/// will result in [`Error::RecursionLimitExceeded`] .
897+
///
898+
/// Set a high recursion limit at your own risk (of stack exhaustion)!
899+
#[inline]
900+
pub fn deserializer_from_reader_with_buffer_and_recursion_limit<R: Read>(
901+
reader: R,
902+
scratch_buffer: &mut [u8],
903+
recurse_limit: usize,
904+
) -> Deserializer<'_, R>
905+
where
906+
R::Error: core::fmt::Debug,
907+
{
908+
Deserializer {
909+
decoder: reader.into(),
910+
scratch: scratch_buffer,
911+
recurse: recurse_limit,
912+
}
913+
}

0 commit comments

Comments
 (0)