pub struct CBOR(/* private fields */);Expand description
A symbolic representation of CBOR data.
Implementations§
source§impl CBOR
impl CBOR
Affordances for decoding CBOR from binary representation.
sourcepub fn try_from_data(data: impl AsRef<[u8]>) -> Result<CBOR, Error>
pub fn try_from_data(data: impl AsRef<[u8]>) -> Result<CBOR, Error>
Decodes the given date into CBOR symbolic representation.
sourcepub fn try_from_hex(hex: &str) -> Result<CBOR, Error>
pub fn try_from_hex(hex: &str) -> Result<CBOR, Error>
Decodes the given data into CBOR symbolic representation given as a hexadecimal string.
Panics if the string is not well-formed hexadecimal with no spaces or other characters.
pub fn to_cbor_data(&self) -> Vec<u8> ⓘ
source§impl CBOR
impl CBOR
sourcepub fn to_byte_string(data: impl AsRef<[u8]>) -> CBOR
pub fn to_byte_string(data: impl AsRef<[u8]>) -> CBOR
Create a new CBOR value representing a byte string.
sourcepub fn to_byte_string_from_hex(hex: impl AsRef<str>) -> CBOR
pub fn to_byte_string_from_hex(hex: impl AsRef<str>) -> CBOR
Create a new CBOR value representing a byte string given as a hexadecimal string.
Panics if the string is not well-formed hexadecimal.
source§impl CBOR
impl CBOR
sourcepub fn try_into_byte_string(self) -> Result<Bytes, Error>
pub fn try_into_byte_string(self) -> Result<Bytes, Error>
Extract the CBOR value as a byte string.
Returns Ok if the value is a byte string, Err otherwise.
pub fn into_byte_string(self) -> Option<Bytes>
sourcepub fn try_into_text(self) -> Result<String, Error>
pub fn try_into_text(self) -> Result<String, Error>
Extract the CBOR value as a text string.
Returns Ok if the value is a text string, Err otherwise.
sourcepub fn try_into_array(self) -> Result<Vec<CBOR>, Error>
pub fn try_into_array(self) -> Result<Vec<CBOR>, Error>
Extract the CBOR value as an array.
Returns Ok if the value is an array, Err otherwise.
sourcepub fn try_into_map(self) -> Result<Map, Error>
pub fn try_into_map(self) -> Result<Map, Error>
Extract the CBOR value as a map.
Returns Ok if the value is a map, Err otherwise.
sourcepub fn try_into_tagged_value(self) -> Result<(Tag, CBOR), Error>
pub fn try_into_tagged_value(self) -> Result<(Tag, CBOR), Error>
Extract the CBOR value as a tagged value.
Returns Ok if the value is a tagged value, Err otherwise.
sourcepub fn try_into_expected_tagged_value(
self,
expected_tag: impl Into<Tag>,
) -> Result<CBOR, Error>
pub fn try_into_expected_tagged_value( self, expected_tag: impl Into<Tag>, ) -> Result<CBOR, Error>
Extract the CBOR value as an expected tagged value.
Returns Ok if the value is a tagged value with the expected tag, Err
otherwise.
sourcepub fn try_into_simple_value(self) -> Result<Simple, Error>
pub fn try_into_simple_value(self) -> Result<Simple, Error>
Extract the CBOR value as a simple value.
Returns Ok if the value is a simple value, Err otherwise.
source§impl CBOR
impl CBOR
Affordances for viewing CBOR in diagnostic notation.
sourcepub fn diagnostic_opt(
&self,
annotate: bool,
tags: Option<&dyn TagsStoreTrait>,
) -> String
pub fn diagnostic_opt( &self, annotate: bool, tags: Option<&dyn TagsStoreTrait>, ) -> String
Returns a representation of this CBOR in diagnostic notation.
Optionally annotates the output, e.g. formatting dates and adding names of known tags.
sourcepub fn diagnostic(&self) -> String
pub fn diagnostic(&self) -> String
Returns a representation of this CBOR in diagnostic notation.