Crates.io | tokio-serde-postcard |
lib.rs | tokio-serde-postcard |
version | 0.1.0 |
source | src |
created_at | 2023-12-01 10:51:01.616968 |
updated_at | 2023-12-01 10:51:01.616968 |
description | `tokio-serde` transport based on `postcard` format |
homepage | https://github.com/heilhead/tokio-serde-postcard.git |
repository | https://github.com/heilhead/tokio-serde-postcard.git |
max_upload_size | |
id | 1054949 |
size | 16,364 |
tokio-serde
transport based on postcard
format.
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())
}