Framed transport
FramedTransport is a generic transport wrapper for AsyncRead + AsyncWrite streams that uses a framing codec to divide a continuous byte stream into discrete messages.
This transport requires a codec implementing dnet::io::framed::Framing.
What it does
- Wraps a lower-level transport that implements
AsyncReadandAsyncWrite. - Encodes outgoing messages into frames using the provided codec.
- Reads incoming bytes into an internal buffer and decodes complete frames as they arrive.
Constructors
FramedTransport::new(transport, codec)creates a raw framed transport.FramedTransport::buffered(transport, codec)wraps the transport in buffered I/O for better throughput with many small writes or reads.
When to use it
- Use
FramedTransportwhen you need a generic framed protocol over any async byte stream. - Use
TcpFramedTransportorQuicFramedTransportwhen you want a transport-specific wrapper that already exposes the same framed behavior. - Use
length_delimited::Codecfor the common case of messages prefixed with their length.
Notes
- A framing codec can implement custom delimiting strategies beyond length-prefix framing.
- The codec must preserve partial input until a full frame can be decoded.
FramedTransport::bufferedis often a good default for network streams.