Crate encdec

source ·
Expand description

Common traits and helper macros for binary encoding and decoding.

This crate provides common Encode and Decode traits for describing binary encode/decode-able objects, as well as #[derive(Encode)] and #[derive(Decode)] macros to reduce boilerplate when propagating these and little-endian implementations for primitive types. For more implementation see the module-level documentation.

This is intended to provide a reusable base for implementing binary encodable objects to match a particular protocol or specification (and mitigate embedded pub trait (Encode|Decode) {..} bankruptcy)

If you don’t need to control the encoded layout directly you might like to look at serde, with postcard for efficient binary encoding between rust components. If you’re creating a new protocol for cross-language use you may wish to consider creating a specification using protocol buffers and prost.

Modules

  • Decode traits and helper macros
  • Macros for deriving primitive Decode and Encode implementations on types containing decodable/encodable fields.
  • Encode traits and helper macros
  • Helpers for testing encode/decode objects as well as specialised encode/decode impls

Enums

  • Basic encode/decode error type

Traits

  • Decode trait implemented for binary decodable objects
  • Extensions to Decode trait for decodable objects
  • Decode trait implemented for owned types
  • Composite trait requiring an object is reversibly encodable and decodable into borrowed types, useful for simplifying type bounds / generics.
  • Composite trait requiring an object is reversibly encodable and decodable into owned types, useful for simplifying type bounds / generics.
  • Encode trait implemented for binary encodable objects
  • Extensions to Encode trait for encodable types

Derive Macros