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
pub mod decode;
pub mod encode;
mod shared_reader;
mod shared_writer;

pub use shared_reader::{RequestDispatch, ResponseReceiver, RpcIncomingMessage, RpcIteration};
pub use shared_writer::SharedRpcSink;

use crate::decode::ValueFuture;
use crate::encode::EfficientInt;
use shared_reader::RpcResultFuture;

pub type ResponseResult<R> =
    Result<ValueFuture<RpcResultFuture<R>>, ValueFuture<RpcResultFuture<R>>>;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MsgId(u32);

impl From<MsgId> for EfficientInt {
    fn from(msgid: MsgId) -> EfficientInt {
        msgid.0.into()
    }
}

// Allow getting, but not modifying, the raw id
impl From<MsgId> for u32 {
    fn from(msgid: MsgId) -> u32 {
        msgid.0
    }
}

impl From<u32> for MsgId {
    fn from(id: u32) -> Self {
        MsgId(id)
    }
}

#[repr(u8)]
#[derive(Debug, Eq, PartialEq, Primitive)]
pub(crate) enum MsgType {
    Request = 0,
    Response = 1,
    Notification = 2,
}

impl From<MsgType> for EfficientInt {
    fn from(ty: MsgType) -> EfficientInt {
        (ty as u8).into()
    }
}