1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use bytes::Bytes;

use crate::{CBOR, CBORCase};

impl From<Bytes> for CBOR {
    fn from(value: Bytes) -> Self {
        CBORCase::ByteString(value).into()
    }
}

impl TryFrom<CBOR> for Bytes {
    type Error = anyhow::Error;

    fn try_from(value: CBOR) -> Result<Self, Self::Error> {
        match value.case() {
            CBORCase::ByteString(b) => Ok(b.clone()),
            _ => Err(anyhow::anyhow!("Cannot convert {:?} to Bytes", value))
        }
    }
}