1 unstable release
0.1.0 | Dec 1, 2023 |
---|
#1836 in Encoding
734 downloads per month
7KB
tokio-serde-postcard
tokio-serde
transport based on postcard
format.
Usage
Adding dependency:
[dependencies]
tokio-serde-postcard = "0.1"
Transport initialization is the same as the built-in tokio_serde
serializers:
fn framed_tcp_stream<Item, SinkItem>(
stream: TcpStream,
) -> tokio_serde::Framed<
tokio_util::codec::Framed<TcpStream, LengthDelimitedCodec>,
Item,
SinkItem,
tokio_serde_postcard::Postcard<Item, SinkItem>,
> {
// First wrap the stream with a basic length-delimited codec.
let transport =
tokio_util::codec::Framed::new(stream, tokio_util::codec::LengthDelimitedCodec::default());
// Then wrap the transport with `tokio_serde`.
tokio_serde::Framed::new(transport, tokio_serde_postcard::Postcard::default())
}
License
Dependencies
~0.8–1.5MB
~30K SLoC