sansio-codec
Protocol codecs for the sansio ecosystem, providing reusable frame decoders, string codecs, and transport abstractions.
Features
- Frame Decoders: Line-based frame decoders for parsing delimited streams
- String Codecs: UTF-8 string encoding/decoding
- Transport Abstractions: Tagged message types with transport metadata (IP addresses, ports, protocol type, ECN)
- Sans-IO Design: Pure protocol logic without I/O dependencies
Quick Start
[]
= "0.0.8"
Usage
Building a Pipeline with Codecs
use Pipeline;
use ;
use Rc;
let pipeline = new;
// Add line-based frame decoder (splits on \n or \r\n)
let frame_decoder = new;
pipeline.add_back;
// Add string codec (converts bytes to UTF-8 strings)
pipeline.add_back;
// Add your business logic handler
// pipeline.add_back(your_handler);
pipeline.update;
Transport Context
All messages are wrapped with transport metadata:
use ;
use Instant;
use BytesMut;
let msg = TaggedBytesMut ;
Modules
byte_to_message_decoder
Frame decoders for parsing byte streams:
LineBasedFrameDecoder: Splits frames on line terminators (\n,\r\n, or both)TaggedByteToMessageCodec: Handler wrapper for anyMessageDecoderTerminatorType: Configure line terminator type (BOTH, NEWLINE, CarriageNewline)
string_codec
String encoding/decoding:
TaggedStringCodec: Converts betweenTaggedBytesMutandTaggedString
transport
Transport abstractions:
TransportContext: Local/peer addresses, transport protocol type, ECN bitsTaggedBytesMut: BytesMut message with transport contextTaggedString: String message with transport contextTransportProtocol: TCP or UDPFourTuple: Local and peer addressesFiveTuple: Local address, peer address, and transport protocol
Example
See the examples directory for complete working examples using these codecs, including:
- TCP chat server with line-based framing
- UDP chat server with message broadcasting
Documentation
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.