Expand description
§folk-protocol
Wire format for Folk: typed RPC messages and length-prefixed framing.
§What this crate provides
RpcMessage: the three message variants ofMessagePack-RPC (Request,Response,Notify), encoded as positionalMessagePackarrays.FrameCodec: a Tokio codec that combines a 4-byte big-endian length prefix withrmp_serdepayload encoding/decoding.Error: a single error type for all fallible operations in this crate.
§Wire format
Every message on the wire is:
+----------------+---------------------------------+
| 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
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);Re-exports§
pub use codec::FrameCodec;pub use error::Error;pub use error::MAX_FRAME_SIZE;pub use error::Result;pub use message::RpcMessage;