Struct aws_smithy_cbor::decode::Decoder
source · pub struct Decoder<'b> { /* private fields */ }
Expand description
Provides functions for decoding a CBOR object with a known schema.
Although CBOR is a self-describing format, this decoder is tailored for cases where the schema
is known in advance. Therefore, the caller can determine which object key exists at the current
position by calling str
method, and call the relevant function based on the predetermined schema
for that key. If an unexpected key is encountered, the caller can use the skip
method to skip
over the element.
Implementations§
source§impl<'b> Decoder<'b>
impl<'b> Decoder<'b>
pub fn new(bytes: &'b [u8]) -> Self
pub fn datatype(&self) -> Result<Type, DeserializeError>
pub fn skip(&mut self) -> Result<(), DeserializeError>
pub fn boolean(&mut self) -> Result<bool, DeserializeError>
pub fn byte(&mut self) -> Result<i8, DeserializeError>
pub fn short(&mut self) -> Result<i16, DeserializeError>
pub fn integer(&mut self) -> Result<i32, DeserializeError>
pub fn long(&mut self) -> Result<i64, DeserializeError>
pub fn float(&mut self) -> Result<f32, DeserializeError>
pub fn double(&mut self) -> Result<f64, DeserializeError>
pub fn null(&mut self) -> Result<(), DeserializeError>
pub fn list(&mut self) -> Result<Option<u64>, DeserializeError>
pub fn map(&mut self) -> Result<Option<u64>, DeserializeError>
sourcepub fn position(&self) -> usize
pub fn position(&self) -> usize
Returns the current position of the buffer, which will be decoded when any of the methods is called.
sourcepub fn str(&mut self) -> Result<Cow<'b, str>, DeserializeError>
pub fn str(&mut self) -> Result<Cow<'b, str>, DeserializeError>
Returns a Cow::Borrowed(&str)
if the element at the current position in the buffer is a definite
length string. Otherwise, it returns a Cow::Owned(String)
if the element at the current position is an
indefinite-length string. An error is returned if the element is neither a definite length nor an
indefinite-length string.
sourcepub fn string(&mut self) -> Result<String, DeserializeError>
pub fn string(&mut self) -> Result<String, DeserializeError>
Allocates and returns a String
if the element at the current position in the buffer is either a
definite-length or an indefinite-length string. Otherwise, an error is returned if the element is not a string type.
sourcepub fn blob(&mut self) -> Result<Blob, DeserializeError>
pub fn blob(&mut self) -> Result<Blob, DeserializeError>
Returns a blob
if the element at the current position in the buffer is a byte string. Otherwise,
a DeserializeError
error is returned.
sourcepub fn timestamp(&mut self) -> Result<DateTime, DeserializeError>
pub fn timestamp(&mut self) -> Result<DateTime, DeserializeError>
Returns a DateTime
if the element at the current position in the buffer is a timestamp
. Otherwise,
a DeserializeError
error is returned.
Trait Implementations§
Auto Trait Implementations§
impl<'b> Freeze for Decoder<'b>
impl<'b> RefUnwindSafe for Decoder<'b>
impl<'b> Send for Decoder<'b>
impl<'b> Sync for Decoder<'b>
impl<'b> Unpin for Decoder<'b>
impl<'b> UnwindSafe for Decoder<'b>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more