tokio-serde-postcard

Crates.iotokio-serde-postcard
lib.rstokio-serde-postcard
version0.1.0
sourcesrc
created_at2023-12-01 10:51:01.616968
updated_at2023-12-01 10:51:01.616968
description`tokio-serde` transport based on `postcard` format
homepagehttps://github.com/heilhead/tokio-serde-postcard.git
repositoryhttps://github.com/heilhead/tokio-serde-postcard.git
max_upload_size
id1054949
size16,364
Ivan Reshetnikov (heilhead)

documentation

README

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

Apache 2.0

Commit count: 2

cargo fmt