wire_framed/lib.rs
1//! wire-framed is a library for encoding and decoding frames using a custom binary protocol.
2//! It prioritizes ease-of-use.
3//!
4//! It reolves around two traits [`FromFrame`] and [`IntoFrame`]. These traits can be manually implemented relatively easily using
5//! the utilities provided in the [`utils`] module or automatically using the [`Encoding`] and [`Decoding`] macros.
6//!
7//! [`FromFrame`]: trait.FromFrame.html
8//! [`IntoFrame`]: trait.IntoFrame.html
9//! [`utils`]: utils/index.html
10//! [`Encoding`]: macro.Encoding.html
11//! [`Decoding`]: macro.Decoding.html
12//!
13//! # Usage
14//! ```
15//! use wire_framed::prelude::*;
16//!
17//! #[derive(Debug, Encoding, Decoding, PartialEq, Eq)]
18//! pub struct Foo {
19//! pub id: u32,
20//! pub name: String,
21//! pub description: String,
22//! pub created_at: u64,
23//! }
24//!
25//! # fn send_to_socket(_frame: Bytes) -> Result<(), std::io::Error> { Ok(()) }
26//!
27//! fn send() -> Result<(), std::io::Error> {
28//! let foo = Foo {
29//! id: 1,
30//! name: "John".to_string(),
31//! description: "John is a legend".to_string(),
32//! created_at: 1234567890,
33//! };
34//!
35//! let frame = foo.into_frame();
36//! send_to_socket(frame)
37//! }
38//!
39//! # fn recv_from_socket() -> Bytes {
40//! # Bytes::from_static(&[
41//! # 0x00, 0x00, 0x00, 0x01, // id
42//! # 0x00, 0x00, 0x00, 0x04, // name length
43//! # 0x4a, 0x6f, 0x68, 0x6e, // name
44//! # 0x00, 0x00, 0x00, 0x10, // description length
45//! # 0x4a, 0x6f, 0x68, 0x6e, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x6c, 0x65, 0x67, 0x65, 0x6e, 0x64, // description
46//! # 0x00, 0x00, 0x00, 0x00, 0x49, 0x96, 0x02, 0xd2, // created_at
47//! # ])
48//! # }
49//!
50//! fn recv() -> Result<(), std::io::Error> {
51//! let bytes = recv_from_socket();
52//! let foo = Foo::from_frame(bytes)?;
53//!
54//! // process foo
55//! # Ok(())
56//! }
57//!
58//! # fn main() -> Result<(), std::io::Error> {
59//! # send()?;
60//! # recv()?;
61//! #
62//! # Ok(())
63//! # }
64//! ```
65
66
67pub use wire_framed_core::{
68 self, FromFrame, IntoFrame, FrameCodec, Framed, FramedRead, FramedWrite, bytes::{self, Bytes, BytesMut, Buf, BufMut}, codec, common_impls::*, utils
69};
70pub use wire_framed_derive::{Decoding, Encoding};
71
72pub mod prelude {
73 pub use super::*;
74}