Crate tokio_serde [] [src]

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

Note, if you are an end user, you probably won't want to use this crate directly. Instead, use a tokio-serde-* crate that implements a specific serialization format. For example tokio-serde-json uses serde-json to serialize and deserialize frames.

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 FramedRead or FramedWrite along with the upsteram [Stream] or [Sink] that handles the byte encoded frames.

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

  • tokio_serde_json::JsonRead
  • tokio_serde::FramedRead
  • tokio_io::codec::length_delimited::FramedRead
  • tokio_core::net::TcpStream

The write half looks like:

  • tokio_serde_json::JsonWrite
  • tokio_serde::FramedWrite
  • tokio_io::codec::length_delimited::FramedWrite
  • tokio_core::net::TcpStream

Examples

For an example, see how tokio-serde-json is implemented:

Structs

FramedRead

Adapts a stream of buffers to a stream of values by deserializing them.

FramedWrite

Adapts a buffer sink to a value sink by serializing the values.

Traits

Deserializer

Deserializes a value from a source buffer

Serializer

Serializes a value into a destination buffer