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.
source§impl CBOR
impl CBOR
sourcepub fn byte_string<T>(data: T) -> CBORwhere
T: AsRef<[u8]>,
pub fn byte_string<T>(data: T) -> CBORwhere T: AsRef<[u8]>,
Create a new CBOR value representing a byte string.
sourcepub fn byte_string_hex(hex: &str) -> CBOR
pub fn byte_string_hex(hex: &str) -> CBOR
Create a new CBOR value representing a byte string given as a hexadecimal string.
sourcepub fn as_byte_string(&self) -> Option<Bytes>
pub fn as_byte_string(&self) -> Option<Bytes>
Extract the CBOR value as a byte string.
Returns Some if the value is a byte string, None otherwise.
sourcepub fn expect_byte_string(&self) -> Result<Bytes, CBORError>
pub fn expect_byte_string(&self) -> Result<Bytes, CBORError>
Extract the CBOR value as a byte string.
Returns Ok if the value is a byte string, Err otherwise.
sourcepub fn as_text(&self) -> Option<&str>
pub fn as_text(&self) -> Option<&str>
Extract the CBOR value as a text string.
Returns Some if the value is a text string, None otherwise.
sourcepub fn expect_text(&self) -> Result<&str, CBORError>
pub fn expect_text(&self) -> Result<&str, CBORError>
Extract the CBOR value as a text string.
Returns Ok if the value is a text string, Err otherwise.
sourcepub fn as_array(&self) -> Option<&Vec<CBOR>>
pub fn as_array(&self) -> Option<&Vec<CBOR>>
Extract the CBOR value as an array.
Returns Some if the value is an array, None otherwise.
sourcepub fn expect_array(&self) -> Result<&Vec<CBOR>, CBORError>
pub fn expect_array(&self) -> Result<&Vec<CBOR>, CBORError>
Extract the CBOR value as an array.
Returns Ok if the value is an array, Err otherwise.
sourcepub fn as_map(&self) -> Option<&Map>
pub fn as_map(&self) -> Option<&Map>
Extract the CBOR value as a map.
Returns Some if the value is a map, None otherwise.
sourcepub fn expect_map(&self) -> Result<&Map, CBORError>
pub fn expect_map(&self) -> Result<&Map, CBORError>
Extract the CBOR value as a map.
Returns Ok if the value is a map, Err otherwise.
sourcepub fn tagged_value(tag: impl Into<Tag>, item: impl CBOREncodable) -> CBOR
pub fn tagged_value(tag: impl Into<Tag>, item: impl CBOREncodable) -> CBOR
Create a new CBOR value representing a tagged value.
sourcepub fn as_tagged_value(&self) -> Option<(&Tag, &CBOR)>
pub fn as_tagged_value(&self) -> Option<(&Tag, &CBOR)>
Extract the CBOR value as a tagged value.
Returns Some if the value is a tagged value, None otherwise.
sourcepub fn expect_tagged_value(
&self,
expected_tag: impl Into<Tag>
) -> Result<&CBOR, CBORError>
pub fn expect_tagged_value( &self, expected_tag: impl Into<Tag> ) -> Result<&CBOR, CBORError>
Extract the CBOR value as a tagged value.
Returns Ok if the value is a tagged value with the expected tag, Err
otherwise.
sourcepub fn as_simple_value(&self) -> Option<&Simple>
pub fn as_simple_value(&self) -> Option<&Simple>
Extract the CBOR value as a simple value.
Returns Some if the value is a simple value, None otherwise.
sourcepub fn expect_simple_value(&self) -> Result<&Simple, CBORError>
pub fn expect_simple_value(&self) -> Result<&Simple, CBORError>
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.