pub enum CBOR {
Unsigned(u64),
Negative(i64),
ByteString(Vec<u8, Global>),
Text(String),
Array(Vec<CBOR, Global>),
Map(Map),
Tagged(Tag, Box<CBOR, Global>),
Simple(Simple),
}Expand description
A symbolic representation of CBOR data.
Variants§
Unsigned(u64)
Unsigned integer (major type 0).
Negative(i64)
Negative integer (major type 1).
ByteString(Vec<u8, Global>)
Byte string (major type 2).
Text(String)
UTF-8 string (major type 3).
Array(Vec<CBOR, Global>)
Array (major type 4).
Map(Map)
Map (major type 5).
Tagged(Tag, Box<CBOR, Global>)
Tagged value (major type 6).
Simple(Simple)
Simple value (major type 7).
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<&[u8]>
pub fn as_byte_string(&self) -> Option<&[u8]>
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<&[u8], CBORError>
pub fn expect_byte_string(&self) -> Result<&[u8], 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, Global>>
pub fn as_array(&self) -> Option<&Vec<CBOR, Global>>
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, Global>, CBORError>
pub fn expect_array(&self) -> Result<&Vec<CBOR, Global>, 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<T, I>(tag: T, item: I) -> CBORwhere
T: Into<Tag>,
I: CBOREncodable,
pub fn tagged_value<T, I>(tag: T, item: I) -> CBORwhere T: Into<Tag>, I: CBOREncodable,
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<T>(
&self,
expected_tag: T
) -> Result<&CBOR, CBORError>where
T: Into<Tag>,
pub fn expect_tagged_value<T>( &self, expected_tag: T ) -> Result<&CBOR, CBORError>where T: Into<Tag>,
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.