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
//! # `folk-protocol`
//!
//! Wire format for Folk: typed RPC messages and length-prefixed framing.
//!
//! ## What this crate provides
//!
//! - [`RpcMessage`]: the three message variants of `MessagePack`-RPC
//! (`Request`, `Response`, `Notify`), encoded as positional `MessagePack` arrays.
//! - [`FrameCodec`]: a Tokio codec that combines a 4-byte big-endian length prefix
//! with `rmp_serde` payload encoding/decoding.
//! - [`Error`]: a single error type for all fallible operations in this crate.
//!
//! ## Wire format
//!
//! Every message on the wire is:
//!
//! ```text
//! +----------------+---------------------------------+
//! | 4-byte length | MessagePack-encoded array |
//! | big-endian | (the RpcMessage payload) |
//! +----------------+---------------------------------+
//! ```
//!
//! Maximum frame size is [`MAX_FRAME_SIZE`] (16 MiB). See
//! `folk-spec/spec/02-protocol.md` for the full specification.
//!
//! ## Example
//!
//! ```rust
//! use bytes::BytesMut;
//! use folk_protocol::{FrameCodec, RpcMessage};
//! use rmpv::Value;
//! use tokio_util::codec::{Decoder, Encoder};
//!
//! let mut codec = FrameCodec::new();
//! let msg = RpcMessage::request(1, "echo", Value::String("hello".into()));
//!
//! let mut buf = BytesMut::new();
//! codec.encode(msg.clone(), &mut buf).unwrap();
//!
//! let decoded = codec.decode(&mut buf).unwrap().unwrap();
//! assert_eq!(msg, decoded);
//! ```
pub use FrameCodec;
pub use ;
pub use RpcMessage;