Crate bytecodec

Source
Expand description

A tiny framework for implementing encoders/decoders of byte-oriented protocols.

§Features

  • Suited for byte-oriented protocols
  • Incremental encoding/decoding:
    • Encode and Decode traits support incremental encoding and decoding
    • The number of bytes consumed in an execution of encode/decode methods can be completely controlled by the caller
    • This property makes it easy to implement, for example, multi-stream multiplexing, transmittin rate control and asynchronous I/O
  • Composable:
    • By combining multiple encoders (or decoders), it is easy to build a more complex encoder (or decoder)
    • See the examples of EncodeExt and DecodeExt traits
  • Reduced number of memory copies:
    • In design, only two memory copies are required
    • Considering in the decode process, one is the copy from the actual stream (e.g., TCP socket) to the decoding buffer, the other one is the copy to construct the item from the buffer.
  • Supports some serde implemention crates:
    • Currently serde_json and bincode are supported (as optional featuers)
    • See json_codec and bincode_codec modules
  • Easily adapt to synchronous I/O, asynchronous I/O, UDP, etc
  • Trackable errors:
    • By using trackable crate, the location where an error occurred can be easily specified
    • See EncodeExt::map_err and DecodeExt::map_err methods

Modules§

bincode_codec
#[cfg(feature = "bincode_codec")] Bincode encoder and decoder that use bincode internally.
bytes
Encoders and decoders for reading/writing byte sequences.
combinator
Encoders and decoders for combination.
fixnum
Encoders and decoders for numbers which have fixed length binary representation.
io
I/O (i.e., Read and Write traits) related module.
io_async
I/O (i.e., Read and Write traits) related module.
json_codec
#[cfg(feature = "json_codec")] JSON encoder and decoder that use serde_json internally.
marker
Marker types.
monolithic
Monolithic encoder and decoder.
null
Null decoder and encoder.
padding
Encoder and decoder for padding bytes.
slice
Slice like types.
tuple
Encoders and decoders for tuples.

Macros§

bytecodec_try_decode
Tries to decode an item from the given buffer.
bytecodec_try_encode
Tries to encode items to the given buffer.

Structs§

Eos
Eos contains information on the distance to the end of a stream.
Error
This crate specific Error type.

Enums§

ByteCount
Number of bytes of interest.
ErrorKind
Possible error kinds.

Traits§

Decode
This trait allows for decoding items from a byte sequence incrementally.
DecodeExt
An extension of Decode trait.
Encode
This trait allows for encoding items into a byte sequence incrementally.
EncodeExt
An extension of Encode trait.
SizedEncode
This trait indicates that the encoder always knows the exact bytes required to encode remaining items.
TaggedDecode
This trait allows for decoding tagged items from a byte sequence incrementally.
TryTaggedDecode
This trait allows for decoding known-tagged or unknown-tagged items from a byte sequence incrementally.

Type Aliases§

Result
This crate specific Result type.