Struct cbor_data::CborOwned [−][src]
Wrapper around a vector of bytes, for parsing as CBOR.
For details on the format see RFC 7049.
When interpreting CBOR messages from the outside (e.g. from the network) it is
advisable to ingest those using the canonical
constructor.
In case the message was encoded for example using CborBuilder
it is sufficient to use the trusting
constructor.
Canonicalisation rqeuires an intermediary data buffer, which can be supplied (and reused) by the caller to save on allocations.
Implementations
impl CborOwned
[src]
pub fn trusting(bytes: impl Into<Vec<u8>>) -> Self
[src]
Copy the bytes and wrap for indexing.
No checks on the integrity are made, indexing methods may panic if encoded lengths are out of bound.
If you want to carefully treat data obtained from unreliable sources, prefer
canonical()
.
pub fn canonical(bytes: impl AsRef<[u8]>) -> Option<Self>
[src]
Copy the bytes while checking for integrity and replacing indefinite (byte) strings with definite ones.
This constructor will go through and decode the whole provided CBOR bytes and write them into a vector, thereby
- retaining only innermost tags
- writing arrays and dicts using indefinite size format
- writing numbers in their smallest form
For more configuration options like reusing a scratch space or preferring definite size encoding
see CborBuilder
.
pub fn borrow(&self) -> Cbor<'_>
[src]
Borrow the underlying bytes for Cbor interpretation.
pub fn as_slice(&self) -> &[u8]
[src]
A view onto the underlying bytes.
pub fn value(&self) -> Option<CborValue<'_>>
[src]
Extract the single value represented by this piece of CBOR.
pub fn index(&self, path: &str) -> Option<CborValue<'_>>
[src]
Extract a value by indexing into arrays and dicts, with path elements separated by dot.
Returns None if an index doesn’t exist or the indexed object is neither an array nor a dict. When the object under consideration is an array, the next path element must represent an integer number.
The empty string will yield the same as calling value()
. If path elements
may contain .
then use index_iter()
.
pub fn index_iter<'b>(
&self,
path: impl IntoIterator<Item = &'b str>
) -> Option<CborValue<'_>>
[src]
&self,
path: impl IntoIterator<Item = &'b str>
) -> Option<CborValue<'_>>
Extract a value by indexing into arrays and dicts, with path elements yielded by an iterator.
Returns None if an index doesn’t exist or the indexed object is neither an array nor a dict. When the object under consideration is an array, the next path element must represent an integer number.
The empty iterator will yield the same as calling value()
.
pub fn visit<'a, Err, V: Visitor<'a, Err>>(
&'a self,
visitor: &mut V
) -> Result<bool, Err>
[src]
&'a self,
visitor: &mut V
) -> Result<bool, Err>
Visit the interesting parts of this CBOR item as guided by the given
Visitor
.
Returns false
if the visit was not even begun due to invalid or non-canonical CBOR.
Trait Implementations
impl AsRef<[u8]> for CborOwned
[src]
impl Clone for CborOwned
[src]
impl Debug for CborOwned
[src]
impl Display for CborOwned
[src]
impl PartialEq<CborOwned> for CborOwned
[src]
impl StructuralPartialEq for CborOwned
[src]
Auto Trait Implementations
impl RefUnwindSafe for CborOwned
impl Send for CborOwned
impl Sync for CborOwned
impl Unpin for CborOwned
impl UnwindSafe for CborOwned
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,