Crate senax_encoder

Source
Expand description

§senax-encoder

A fast, compact, and schema-evolution-friendly binary serialization library for Rust.

  • Supports struct/enum encoding with field/variant IDs for forward/backward compatibility
  • Efficient encoding for primitives, collections, Option, String, bytes, and popular crates (chrono, uuid, ulid, rust_decimal, indexmap, fxhash, ahash, smol_str)
  • Custom derive macros for ergonomic usage
  • Feature-gated support for optional dependencies

§Attribute Macros

You can control encoding/decoding behavior using the following attributes:

  • #[senax(id = N)] — Assigns a custom field or variant ID (u64). Ensures stable wire format across versions.
  • #[senax(default)] — If a field is missing during decoding, its value is set to Default::default() instead of causing an error. For Option<T>, this means None.
  • #[senax(skip_encode)] — This field is not written during encoding. On decode, it is set to Default::default().
  • #[senax(skip_decode)] — This field is ignored during decoding and always set to Default::default(). It is still encoded if present.
  • #[senax(skip_default)] — This field is not written during encoding if its value equals the default value. On decode, missing fields are set to Default::default().
  • #[senax(rename = "name")] — Use the given string as the logical field/variant name for ID calculation. Useful for renaming fields/variants while keeping the same wire format.

§Feature Flags

The following optional features enable support for popular crates and types:

§Core Features

  • encode — Enables the encode()/decode() functions and methods with schema evolution support (field IDs, type tags). Default enabled.
  • pack — Enables the pack()/unpack() functions and methods for compact encoding without schema evolution support.
  • vec_u8 — Optimizes Vec<u8> encoding to use the same binary tag as Bytes for better compatibility and smaller size. When enabled, Vec<u8> and Bytes are interchangeable in the binary format. Default enabled.

§External Crate Support

  • chrono — Enables encoding/decoding of chrono::DateTime, NaiveDate, and NaiveTime types.
  • uuid — Enables encoding/decoding of uuid::Uuid.
  • ulid — Enables encoding/decoding of ulid::Ulid (shares the same tag as UUID for binary compatibility).
  • rust_decimal — Enables encoding/decoding of rust_decimal::Decimal.
  • indexmap — Enables encoding/decoding of IndexMap and IndexSet collections.
  • fxhash — Enables encoding/decoding of fxhash::FxHashMap and fxhash::FxHashSet (fast hash collections).
  • ahash — Enables encoding/decoding of ahash::AHashMap and ahash::AHashSet (high-performance hash collections).
  • smol_str — Enables encoding/decoding of smol_str::SmolStr (small string optimization).
  • serde_json — Enables encoding/decoding of serde_json::Value (JSON values as dynamic type).

Modules§

core

Enums§

EncoderError
Error type for all encoding and decoding operations in this crate.

Traits§

Decoder
Trait for types that can be decoded from the senax binary format.
Encoder
Trait for types that can be encoded into the senax binary format.

Functions§

decode
Convenience function to decode a value from bytes.
encode
Convenience function to encode a value to bytes.

Type Aliases§

Result
The result type used throughout this crate for encode/decode operations.

Derive Macros§

Decode
Derive macro for implementing the Decode trait
Encode
Derive macro for implementing the Encode trait