[−][src]Crate tokio_serde
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
FramedRead
or FramedWrite
along with the upstream 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::FramedRead
tokio::codec::FramedRead
tokio::net::TcpStream
The write half looks like:
tokio_serde::FramedWrite
tokio_io::codec::FramedWrite
tokio::net::TcpStream
Examples
For an example, see how JSON support 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 |