Crate framed_aio

Crate framed_aio 

Source
Expand description

A crate for framed async io.

This crate allows performing io operations in a framed manner, which means that instead of sending and receiving bytes from a stream of bytes, you can send and receive frames of bytes.

The reading of frames is implemented in a cancel safe way, which means that you can use it in one of the branches of tokio::select!.

The implementation is also tuned for high performance and low overhead.

§Goals

  • Provide cancel safety
  • High performance
  • Low overhead

§Usage

To read from some type which implements AsyncRead in a framed manner, you can wrap it in a FramedReader and call FramedReader::read_frame.

To write to some type which implements AsyncWrite in a framed manner, you can wrap it in a FramedWriter and call FramedWriter::write_frame or FramedWriter::write_frame_cancel_safe for writing a frame in a cancel safe way.

§Typed Frames

If you wish to send typed frames, which is frames that contains serialized objects, you need to opt in the typed feature flag.

You can then use the [FramedReader::read_frame_typed] and [FramedWriter::write_frame_typed] functions to read and write typed frames.

Structs§

FramedReader
A reader which reads from a readable source in a framed manner. This reader can only read frames generated by a FramedWriter.
FramedWriter
A writer which writes to a writeable sink in a framed manner. Frames written by this writer can be read using a FramedReader.

Enums§

ReadFrameError
An error which occured while trying to read a frame from a FramedReader.
WriteFrameError
An error which occured while trying to write a frame to a FramedWriter.