pub struct ConnId(/* private fields */);Expand description
Value of C_R or C_I, as chosen by ourself or the peer.
Semantically, this is a byte string of some length.
Its legal values are constrained to only contain a single CBOR item that is either a byte string or a number in -24..=23, all in preferred encoding.
Implementations§
Source§impl ConnId
impl ConnId
Sourcepub const fn from_int_raw(raw: u8) -> Self
👎Deprecated: This API is only capable of generating a limited sub-set of the supported identifiers.
pub const fn from_int_raw(raw: u8) -> Self
Construct a ConnId from the result of [cbor_decoder::int_raw], which is a
byte that represents a single positive or negative CBOR integer encoded in the 5 bits minor
type.
Evolving from u8-only values, this could later interact with the decoder directly.
Sourcepub fn from_decoder(decoder: &mut CBORDecoder<'_>) -> Result<Self, CBORError>
pub fn from_decoder(decoder: &mut CBORDecoder<'_>) -> Result<Self, CBORError>
Read a connection identifier from a given decoder.
It is an error for the decoder to read anything but a small integer or a byte string, to exceed the maximum allowed ConnId length, or to contain a byte string that should have been encoded as a small integer.
Sourcepub fn as_cbor(&self) -> &[u8]
pub fn as_cbor(&self) -> &[u8]
The CBOR encoding of the identifier.
For the 48 compact connection identifiers -24..=23, this is identical to the slice representation:
let c_i = ConnId::from_slice(&[0x04]).unwrap();
assert_eq!(c_i.as_cbor(), &[0x04]);For other IDs, this contains an extra byte header:
let c_i = ConnId::from_slice(&[0xff]).unwrap();
assert_eq!(c_i.as_cbor(), &[0x41, 0xff]);Sourcepub fn from_slice(input: &[u8]) -> Option<Self>
pub fn from_slice(input: &[u8]) -> Option<Self>
Try to construct a ConnId from a slice that represents its string value.
This is the inverse of Self::as_slice, and returns None if the identifier is too long (or, if only the compact 48 values are supported, outside of that range).
let c_i = &[0x04];
let c_i = ConnId::from_slice(c_i).unwrap();
assert!(c_i.as_slice() == &[0x04]);
let c_i = ConnId::from_slice(&[0x12, 0x34]).unwrap();
assert!(c_i.as_slice() == &[0x12, 0x34]);