pub struct Decoder<'a> { /* private fields */ }Expand description
Deserializes CBOR items from a fixed input slice.
Implementations§
Source§impl<'a> Decoder<'a>
impl<'a> Decoder<'a>
Sourcepub fn peek_major(&self) -> Option<Major>
pub fn peek_major(&self) -> Option<Major>
Major type of the next item without consuming it.
Sourcepub fn u8(&mut self) -> Result<u8, Error>
pub fn u8(&mut self) -> Result<u8, Error>
Decodes an unsigned integer that fits in u8.
§Errors
Error::TYPE_MISMATCH for non-integers; Error::INTEGER_OUT_OF_RANGE
when the value exceeds u8::MAX.
Sourcepub fn u64(&mut self) -> Result<u64, Error>
pub fn u64(&mut self) -> Result<u64, Error>
Decodes any CBOR unsigned integer into u64.
§Errors
Returns Error::TYPE_MISMATCH for other major types.
Sourcepub fn i8(&mut self) -> Result<i8, Error>
pub fn i8(&mut self) -> Result<i8, Error>
Decodes a negative or non-negative integer into i8.
§Errors
Error::TYPE_MISMATCH for non-integers;
Error::INTEGER_OUT_OF_RANGE outside the i8 range.
Sourcepub fn i64(&mut self) -> Result<i64, Error>
pub fn i64(&mut self) -> Result<i64, Error>
Decodes any CBOR integer (major types 0 and 1) into i64.
§Errors
Error::TYPE_MISMATCH for non-integers;
Error::INTEGER_OUT_OF_RANGE below i64::MIN.
Sourcepub fn bytes(&mut self) -> Result<&'a [u8], Error>
pub fn bytes(&mut self) -> Result<&'a [u8], Error>
Borrows a byte string’s contents from the input.
§Errors
Error::TYPE_MISMATCH if not a byte string; Error::TRUNCATED
if the declared length exceeds the input.
Sourcepub fn str(&mut self) -> Result<&'a str, Error>
pub fn str(&mut self) -> Result<&'a str, Error>
Borrows a text string from the input after validating UTF-8.
§Errors
Error::TYPE_MISMATCH if not a text string; Error::INVALID_UTF8
if the payload violates RFC 3629; Error::TRUNCATED on short input.
Sourcepub fn is_null(&mut self) -> Result<bool, Error>
pub fn is_null(&mut self) -> Result<bool, Error>
Decodes null; returns whether the value was null without consuming
anything else. Use Decoder::peek_major for generic lookahead.
§Errors
Propagates decode errors from malformed heads only.
Sourcepub fn simple(&mut self) -> Result<Simple, Error>
pub fn simple(&mut self) -> Result<Simple, Error>
Decodes any simple value (including booleans and null).
§Errors
Error::TYPE_MISMATCH for floats and non-major-7 items;
Error::INVALID_SIMPLE for two-byte encodings of values below 32.
Sourcepub fn tag(&mut self) -> Result<u64, Error>
pub fn tag(&mut self) -> Result<u64, Error>
Reads a tag number; the tagged item follows immediately.
Tag semantics are application concerns (RFC 8949 §3.4); this returns only the number.
§Errors
Returns Error::TYPE_MISMATCH if the item is not a tag.
Sourcepub fn array_len(&mut self) -> Result<usize, Error>
pub fn array_len(&mut self) -> Result<usize, Error>
Reads an array header, returning the number of following items.
§Errors
Returns Error::TYPE_MISMATCH if the item is not an array.
Sourcepub fn map_len(&mut self) -> Result<usize, Error>
pub fn map_len(&mut self) -> Result<usize, Error>
Reads a map header, returning the number of following key/value pairs.
§Errors
Returns Error::TYPE_MISMATCH if the item is not a map.
Sourcepub fn skip(&mut self) -> Result<(), Error>
pub fn skip(&mut self) -> Result<(), Error>
Consumes exactly one complete data item, whatever its type.
Nested containers are traversed iteratively up to SKIP_LIMIT
levels deep; deeper input yields Error::DEPTH_EXCEEDED.
§Errors
Any structural error (Error::TRUNCATED,
Error::INVALID_ADDITIONAL_INFO, Error::INVALID_SIMPLE,
Error::DEPTH_EXCEEDED).