pub enum CBORCase {
Unsigned(u64),
Negative(u64),
ByteString(ByteString),
Text(String),
Array(Vec<CBOR>),
Map(Map),
Tagged(Tag, CBOR),
Simple(Simple),
}Expand description
An enum representing all possible CBOR data types.
CBORCase is the core enum that represents all possible CBOR data types according to
RFC 8949 and the dCBOR specification.
Each variant corresponds to one of the eight major types in CBOR.
This enum is not typically used directly by users of the library. Instead, it’s wrapped
by the reference-counted CBOR type, which provides a more ergonomic API.
§Major Types
CBOR defines eight major types, numbered 0 through 7:
| Major Type | Name | Description |
|---|---|---|
| 0 | Unsigned integer | A non-negative integer |
| 1 | Negative integer | A negative integer |
| 2 | Byte string | A sequence of bytes |
| 3 | Text string | A UTF-8 string |
| 4 | Array | A sequence of data items |
| 5 | Map | A collection of key-value pairs |
| 6 | Tagged value | A data item with a semantic tag |
| 7 | Simple value | A simple value like true, false, null, or float |
§dCBOR Constraints
According to the dCBOR specification, deterministic encoding adds several constraints:
- Maps must have lexicographically ordered keys
- Numeric values must use the smallest possible encoding
- Floats with integer values are reduced to integers
- All NaN values are canonicalized to a single representation
- Strings must be in Unicode Normalization Form C (NFC)
§Example
use dcbor::prelude::*;
use dcbor::{CBORCase, Simple};
// Create a CBOR value using the CBORCase enum
let case = CBORCase::Array(vec![
CBORCase::Unsigned(1).into(),
CBORCase::Text("hello".to_string()).into(),
CBORCase::Simple(Simple::True).into()
]);
// Wrap in the CBOR type for easier handling
let cbor = CBOR::from(case);
assert_eq!(cbor.diagnostic(), "[1, \"hello\", true]");Variants§
Unsigned(u64)
Unsigned integer (major type 0).
Represents a non-negative integer from 0 to 2^64-1.
Negative(u64)
Negative integer (major type 1).
Actual value is -1 - n, allowing representation of negative integers from -1 to -2^64.
ByteString(ByteString)
Byte string (major type 2).
Represents a sequence of bytes. In dCBOR, byte strings must use the most compact representation possible.
Text(String)
UTF-8 string (major type 3).
Represents a UTF-8 encoded string. In dCBOR, text strings must be in Unicode Normalization Form C (NFC).
Array(Vec<CBOR>)
Array (major type 4).
Represents a sequence of CBOR data items. dCBOR does not support indefinite-length arrays.
Map(Map)
Map (major type 5).
Represents a collection of key-value pairs. In dCBOR, map keys must be in lexicographic order, and duplicate keys are not allowed.
Tagged(Tag, CBOR)
Tagged value (major type 6).
Represents a data item with a semantic tag. The tag provides additional information about how to interpret the data.
Simple(Simple)
Simple value (major type 7).
Represents simple values like true, false, null, and floating-point numbers. In dCBOR, only a limited set of simple values are allowed.