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
52
53
54
55
56
57
58
59
//! # Framous
//! This package is inspired by the `codec` module from [`tokio::util`] but, unlike tokio,
//! is designed to work with non-async code.
//!
//! The intended use case for this crate is when you need to send and receive frames of
//! data via some add-hoc byte-orientated protocol, usually but not necessarily, over TCP.
//!
//! - It supports the sending of user-defined message structures by encoding them to a
//! byte-orientated frame through a user-defined `Encoder`.
//!
//! - Conversely, it supports the receiving of a byte-oriented frames and decoding then through
//! a user-defined `Decoder` into messages as understood by the application.
//!
//! [`tokio::util`]: https://docs.rs/tokio-util/latest/tokio_util/
//!
//! Typical usage:
//! ```compile_fail,no_run
//!
//! enum MyMessage {
//! msg1,
//! msg2,
//! }
//!
//! struct MyCodec;
//!
//! impl Decoder for MyCodec {
//! type Item = MyMessage;
//! type Error = io::Error;
//!
//! fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
//! // decode code
//! // see codec::Decoder
//! }
//! }
//!
//! impl Encoder<MyMessage> for TestCodec {
//! type Error = io::Error;
//!
//! fn encode(&mut self, item: MyMessage, dst: &mut BytesMut) -> Result<(), Self::Error> {
//! // encode code
//! // see codec::Encoder
//! }
//! }
//!
//! let cx = TcpStream::connect("127.0.0.1:35642").unwrap();
//! let mut rx = FramedRead(cx.try_clone()?, MyCodec);
//! let mut tx = FramedWrite(cx, MyCodec);
//!
//! // Send a message
//! tx.framed_write(MyMessage::msg1).unwrap();
//!
//! // Block on waiting for a message
//! let msg = rx.framed_read().unwrap();
pub use ;
pub use ;