Skip to main content

wrpc_transport/frame/
mod.rs

1//! wRPC transport stream framing
2
3use std::sync::Arc;
4
5use bytes::Bytes;
6
7mod codec;
8mod conn;
9mod oneshot;
10
11#[cfg(any(all(target_family = "wasm", feature = "wasi"), feature = "net"))]
12pub mod tcp;
13
14#[cfg(all(unix, feature = "net"))]
15pub mod unix;
16
17pub use codec::*;
18pub use conn::*;
19pub use oneshot::*;
20
21/// Framing protocol version
22pub const PROTOCOL: u8 = 0;
23
24const MAX_INITIAL_PATH_CAPACITY: usize = 32;
25
26/// Owned wRPC frame
27#[derive(Clone, Debug, Eq, PartialEq)]
28pub struct Frame {
29    /// Frame path
30    pub path: Arc<[usize]>,
31    /// Frame data
32    pub data: Bytes,
33}
34
35/// wRPC frame reference
36#[derive(Clone, Debug, Eq, PartialEq)]
37pub struct FrameRef<'a> {
38    /// Frame path
39    pub path: &'a [usize],
40    /// Frame data
41    pub data: &'a [u8],
42}
43
44impl<'a> From<&'a Frame> for FrameRef<'a> {
45    fn from(Frame { path, data }: &'a Frame) -> Self {
46        Self {
47            path: path.as_ref(),
48            data: data.as_ref(),
49        }
50    }
51}