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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
pub mod no_key {
use serde::{de::DeserializeOwned, ser::Serialize};
use bytes::Bytes;
use crate::{
messages::submessages::submessage_elements::serialized_payload::RepresentationIdentifier,
serialization::error::Result,
};
pub trait DeserializerAdapter<D>
where
D: DeserializeOwned,
{
fn supported_encodings() -> &'static [RepresentationIdentifier];
fn from_bytes(input_bytes: &[u8], encoding: RepresentationIdentifier) -> Result<D>;
fn from_vec_bytes(input_vec_bytes: &[Bytes], encoding: RepresentationIdentifier) -> Result<D> {
let total_len = input_vec_bytes.iter().map(Bytes::len).sum();
let mut total_payload = Vec::with_capacity(total_len);
for iv in input_vec_bytes {
total_payload.extend(iv);
}
Self::from_bytes(&total_payload, encoding)
}
}
pub trait SerializerAdapter<D>
where
D: Serialize,
{
fn output_encoding() -> RepresentationIdentifier;
fn to_bytes(value: &D) -> Result<Bytes>;
}
}
pub mod with_key {
use serde::{de::DeserializeOwned, Serialize};
use bytes::Bytes;
use crate::{
dds::traits::key::Keyed,
messages::submessages::submessage_elements::serialized_payload::RepresentationIdentifier,
serialization::error::Result,
};
use super::no_key;
pub trait DeserializerAdapter<D>: no_key::DeserializerAdapter<D>
where
D: Keyed + DeserializeOwned,
{
fn key_from_bytes(input_bytes: &[u8], encoding: RepresentationIdentifier) -> Result<D::K>;
}
pub trait SerializerAdapter<D>: no_key::SerializerAdapter<D>
where
D: Keyed + Serialize,
{
fn key_to_bytes(value: &D::K) -> Result<Bytes>;
}
}