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
//! wRPC transport stream framing

use std::sync::Arc;

use bytes::Bytes;

mod codec;
mod conn;

#[cfg(any(target_family = "wasm", feature = "net"))]
pub mod tcp;

#[cfg(all(unix, feature = "net"))]
pub mod unix;

pub use codec::*;
pub use conn::*;

/// Framing protocol version
pub const PROTOCOL: u8 = 0;

/// Owned wRPC frame
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Frame {
    /// Frame path
    pub path: Arc<[usize]>,
    /// Frame data
    pub data: Bytes,
}

/// wRPC frame reference
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FrameRef<'a> {
    /// Frame path
    pub path: &'a [usize],
    /// Frame data
    pub data: &'a [u8],
}

impl<'a> From<&'a Frame> for FrameRef<'a> {
    fn from(Frame { path, data }: &'a Frame) -> Self {
        Self {
            path: path.as_ref(),
            data: data.as_ref(),
        }
    }
}