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
mod code;
mod message;
pub use self::code::Code;
pub(crate) use self::message::Message;
use crate::{response::Response, serialization::serialize};
use serde::{de::DeserializeOwned, ser::Serialize};
pub const MAX_MSG_SIZE: usize = 2048;
pub(crate) trait Command: Serialize + DeserializeOwned + Sized {
type ResponseType: Response;
const COMMAND_CODE: Code = Self::ResponseType::COMMAND_CODE;
}
impl<C: Command> From<C> for Message {
fn from(command: C) -> Message {
Self::create(C::COMMAND_CODE, serialize(&command).unwrap()).unwrap()
}
}