#serialization #serde #async #networking #send-receive #codec #serializer-deserializer

tokio-serde

Send and receive Serde encodable types over the network using Tokio. This library is used as a building block for serialization format specific libraries

13 releases (breaking)

0.9.0 Feb 4, 2024
0.8.0 Dec 24, 2020
0.7.1 Oct 31, 2020
0.6.1 Mar 23, 2020
0.0.0 Mar 14, 2017

#42 in Encoding

Download history 27911/week @ 2023-12-23 42867/week @ 2023-12-30 78694/week @ 2024-01-06 77607/week @ 2024-01-13 63271/week @ 2024-01-20 70271/week @ 2024-01-27 70743/week @ 2024-02-03 64216/week @ 2024-02-10 79077/week @ 2024-02-17 74216/week @ 2024-02-24 94378/week @ 2024-03-02 60581/week @ 2024-03-09 72364/week @ 2024-03-16 67588/week @ 2024-03-23 58143/week @ 2024-03-30 49214/week @ 2024-04-06

255,372 downloads per month
Used in 275 crates (53 directly)

MIT/Apache

26KB
336 lines

Tokio Serialize / Deserialize

Utilities needed to easily implement a Tokio transport using serde for serialization and deserialization of frame values.

Documentation

Usage

To use tokio-serde, first add this to your Cargo.toml:

[dependencies]
tokio-serde = "0.9"

Next, add this to your crate:

use tokio_serde::{Serializer, Deserializer, Framed};

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in iovec by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

This crate provides the utilities needed to easily implement a Tokio transport using serde for serialization and deserialization of frame values.

Introduction

This crate provides transport combinators that transform a stream of frames encoded as bytes into a stream of frame values. It is expected that the framing happens at another layer. One option is to use a length delimited framing transport.

The crate provides two traits that must be implemented: Serializer and Deserializer. Implementations of these traits are then passed to Framed along with the upstream Stream or Sink that handles the byte encoded frames.

By doing this, a transformation pipeline is built. For reading, it looks something like this:

  • tokio_serde::Framed
  • tokio_util::codec::FramedRead
  • tokio::net::TcpStream

The write half looks like:

  • tokio_serde::Framed
  • tokio_util::codec::FramedWrite
  • tokio::net::TcpStream

Examples

For an example, see how JSON support is implemented:

Dependencies

~0.5–1.4MB
~30K SLoC