pub struct DecoderImpl<R, C: Config, Context, const UNTRUSTED: bool = false> { /* private fields */ }Expand description
A Decoder that reads bytes from a given reader R.
This struct should rarely be used.
In most cases, prefer any of the decode functions.
Use Self::new_untrusted to construct a decoder accepted by the explicit
untrusted traits. Allocation behavior belongs to the trait being called:
Decode retains ordinary behavior even on this decoder; call
super::DecodeUntrusted::decode_untrusted for collection safeguards.
The ByteOrder that is chosen will impact the endianness that is used to read integers out of the reader.
use bincode::de::{DecoderImpl, Decode};
let mut context = ();
let mut decoder = DecoderImpl::new(some_reader, bincode::config::standard(), &mut context);
// this u32 can be any Decode
let value = u32::decode(&mut decoder).unwrap();Implementations§
Source§impl<R: Reader, C: Config, Context> DecoderImpl<R, C, Context>
impl<R: Reader, C: Config, Context> DecoderImpl<R, C, Context>
Sourcepub fn new(reader: R, config: C, context: Context) -> DecoderImpl<R, C, Context>
pub fn new(reader: R, config: C, context: Context) -> DecoderImpl<R, C, Context>
Construct a new Decoder
Sourcepub fn new_untrusted(
reader: R,
config: C,
context: Context,
) -> DecoderImpl<R, C, Context, true>
pub fn new_untrusted( reader: R, config: C, context: Context, ) -> DecoderImpl<R, C, Context, true>
Construct a decoder accepted by super::DecodeUntrusted.
Call the untrusted traits to use their collection safeguards.
The capability is preserved by Decoder::with_context and mutable references.
Trait Implementations§
Source§impl<'de, R: BorrowReader<'de>, C: Config, Context, const UNTRUSTED: bool> BorrowDecoder<'de> for DecoderImpl<R, C, Context, UNTRUSTED>
impl<'de, R: BorrowReader<'de>, C: Config, Context, const UNTRUSTED: bool> BorrowDecoder<'de> for DecoderImpl<R, C, Context, UNTRUSTED>
Source§type BR = R
type BR = R
The concrete BorrowReader type
Source§fn borrow_reader(&mut self) -> &mut Self::BR
fn borrow_reader(&mut self) -> &mut Self::BR
Rerturns a mutable reference to the borrow reader
Source§impl<R: Reader, C: Config, Context, const UNTRUSTED: bool> Decoder for DecoderImpl<R, C, Context, UNTRUSTED>
impl<R: Reader, C: Config, Context, const UNTRUSTED: bool> Decoder for DecoderImpl<R, C, Context, UNTRUSTED>
Source§fn claim_bytes_read(&mut self, n: usize) -> Result<(), DecodeError>
fn claim_bytes_read(&mut self, n: usize) -> Result<(), DecodeError>
Claim that
n bytes are going to be read from the decoder.
This can be used to validate Configuration::Limit<N>().Source§fn unclaim_bytes_read(&mut self, n: usize)
fn unclaim_bytes_read(&mut self, n: usize)
Notify the decoder that
n bytes are being reclaimed. Read moreSource§fn with_context<C>(&mut self, context: C) -> WithContext<'_, Self, C>
fn with_context<C>(&mut self, context: C) -> WithContext<'_, Self, C>
Wraps decoder with a context
Source§fn claim_container_read<T>(&mut self, len: usize) -> Result<(), DecodeError>
fn claim_container_read<T>(&mut self, len: usize) -> Result<(), DecodeError>
Claim that we’re going to read a container which contains
len entries of T.
This will correctly handle overflowing if len * size_of::<T>() > usize::max_valueimpl<R: Reader, C: Config, Context> UntrustedDecoder for DecoderImpl<R, C, Context, true>
Auto Trait Implementations§
impl<R, C, Context, const UNTRUSTED: bool> Freeze for DecoderImpl<R, C, Context, UNTRUSTED>
impl<R, C, Context, const UNTRUSTED: bool> RefUnwindSafe for DecoderImpl<R, C, Context, UNTRUSTED>
impl<R, C, Context, const UNTRUSTED: bool> Send for DecoderImpl<R, C, Context, UNTRUSTED>
impl<R, C, Context, const UNTRUSTED: bool> Sync for DecoderImpl<R, C, Context, UNTRUSTED>
impl<R, C, Context, const UNTRUSTED: bool> Unpin for DecoderImpl<R, C, Context, UNTRUSTED>
impl<R, C, Context, const UNTRUSTED: bool> UnsafeUnpin for DecoderImpl<R, C, Context, UNTRUSTED>
impl<R, C, Context, const UNTRUSTED: bool> UnwindSafe for DecoderImpl<R, C, Context, UNTRUSTED>
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