#postcard #transport #tokio #stream #tokio-serde

tokio-serde-postcard

tokio-serde基于postcard格式的传输

1个不稳定版本

0.1.0 2023年12月1日

#1759编码

Download history 284/week @ 2024-03-13 51/week @ 2024-03-20 300/week @ 2024-03-27 55/week @ 2024-04-03 337/week @ 2024-04-10 122/week @ 2024-04-17 72/week @ 2024-04-24 20/week @ 2024-05-01 74/week @ 2024-05-08 64/week @ 2024-05-15 205/week @ 2024-05-22 125/week @ 2024-05-29 105/week @ 2024-06-05 47/week @ 2024-06-12 102/week @ 2024-06-19 25/week @ 2024-06-26

每月301次下载

Apache-2.0

7KB

tokio-serde-postcard

tokio-serde基于postcard格式的传输。

用法

添加依赖

[dependencies]
tokio-serde-postcard = "0.1"

传输初始化与内置的tokio_serde序列化器相同

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())
}

许可证

Apache 2.0

依赖

~0.8–1.5MB
~30K SLoC