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
pub mod json_codec;
pub mod standard_codec;
#[derive(Serialize, Deserialize, Debug)]
pub struct MethodCall<T> {
pub method: String,
pub args: T,
}
pub enum CodecTypes {
JsonMessageCodec,
StandardMessageCodec,
}
pub enum MethodCallResult<R> {
Ok(R),
Err { code: String, message: String, details: R }
}
pub trait MethodCodec {
type R;
fn decode_method_call(buf: &[u8]) -> Option<MethodCall<Self::R>>;
fn encode_success_envelope(v: &Self::R) -> Vec<u8>;
fn encode_error_envelope(code: &str, message: &str, details: &Self::R) -> Vec<u8>;
fn encode_method_call(v: &MethodCall<Self::R>) -> Vec<u8>;
fn decode_envelope(buf: &[u8]) -> Option<MethodCallResult<Self::R>>;
}