Expand description
tobytcp
is a library used when sending messages over a buffer, typically an async TcpStream
.
It uses length-prefixing to allow the receiver to differentiate different messages
§Examples
Here is a tiny example of what it looks like to use TobyTcp
’s built-in send
and receive
fns. Also look at the /examples
directory
and unit tests in the source code for concrete uses of this library.
#![feature(async_await)]
let mut buf = vec![1, 2, 3];
send(&mut buf, &mut stream).await?;
// Pretend we're connected to an echo server..
let received = receive(&mut stream).await?;
assert_eq!(buf, received);
Modules§
- protocol
- Includes methods for generating the
tobytcp
prefix, or attempting to decode the length of the encoded data i.e. payload, from a buffer.
Functions§
- receive
- Wait for data, which was encoded as
tobytcp
, to be received from thisRead
. Returns the data or any error. See theexamples/
dir in the source code, or the tests of this fn in the source code for some examples of this being used. - send
- Writes the data, encoded as
tobytcp
, to theWrite
. Returns the total number of bytes written, equal todata.len() + 8
. See theexamples/
dir in the source code, or the tests of this fn in the source code for some examples of this being used.