1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use super::Format;
use serde::{de::DeserializeSeed, Serialize};
use crate::kind::Fallible;
pub struct Cbor;
impl Format for Cbor {
type Representation = Vec<u8>;
type Error = serde_cbor::Error;
fn serialize<T: Serialize>(item: T) -> Self::Representation {
serde_cbor::to_vec(&item).unwrap()
}
fn deserialize<'de, T: DeserializeSeed<'de>>(
item: Self::Representation,
context: T,
) -> Fallible<T::Value, (Self::Error, Self::Representation)>
where
T: Sync + Send + 'static,
{
Box::pin(async move {
let mut deserializer = serde_cbor::Deserializer::from_reader(item.as_slice());
context
.deserialize(&mut deserializer)
.map_err(|e| (e, item))
})
}
}