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
//! # Components
//!
//! - [`transport`] Defines data transport layer.
//! - [`rpc`] Defines RPC layer
//!
pub(crate) mod raw;

mod ext;
pub use ext::*; // As all internal modules are prefixed with `ext_`, this is safe.

pub mod rpc;
pub mod transport;

pub use raw::{ReplyCode, MAX_ROUTE_LEN};
pub use rpc::driver::{InitInfo, Notify, PooledBuffer, Reply, ReplyError, Request, VecPool};
pub use rpc::{Handle, Inbound, ReplyWait, WeakHandle};
pub use traits::{RetrievePayload, RetrieveRoute};
pub use transport::{AsyncFrameRead, AsyncFrameWrite};

pub mod consts {
    pub const SMALL_PAYLOAD_SLICE_COUNT: usize = 16;

    pub const BUFSIZE_SMALL: usize = 128;
    pub const BUFSIZE_LARGE: usize = 4096;
}

pub mod alias {
    use lockfree_object_pool::{LinearObjectPool, LinearOwnedReusable, LinearReusable};

    pub type PoolPtr<T> = LinearOwnedReusable<T>;
    pub type PoolRef<'a, T> = LinearReusable<'a, T>;
    pub type Pool<T> = LinearObjectPool<T>;

    pub(crate) type AsyncMutex<T> = async_mutex::Mutex<T>;

    pub(crate) fn default<T: Default>() -> T {
        Default::default()
    }
}

pub mod traits {
    use std::ffi::CStr;

    pub trait RetrievePayload {
        fn payload(&self) -> &[u8];
    }

    pub trait RetrieveRoute {
        fn route(&self) -> &[u8];
        fn route_str(&self) -> Option<&str> {
            std::str::from_utf8(self.route()).ok()
        }
        unsafe fn route_cstr(&self) -> Option<&CStr> {
            let route = self.route();
            if route.is_empty() {
                return None;
            }

            let cs = CStr::from_ptr(route.as_ptr() as *const _);
            (cs.to_bytes().len() <= route.len()).then(|| cs)
        }
    }
}