Module serde_bincode_compat

Module serde_bincode_compat 

Expand description

Bincode-compatible serde implementations for common abstracted types in Reth.

bincode crate doesn’t work with optionally serializable serde fields, but some of the Reth types require optional serialization for RPC compatibility. This module makes so that all fields are serialized.

Read more: https://github.com/bincode-org/bincode/issues/326 Bincode compatibility support for reth primitive types.

This module provides traits and implementations to work around bincode’s limitations with optional serde fields. The bincode crate requires all fields to be present during serialization, which conflicts with types that have #[serde(skip_serializing_if)] attributes for RPC compatibility.

§Overview

The main trait is SerdeBincodeCompat, which provides a conversion mechanism between types and their bincode-compatible representations. There are two main ways to implement this trait:

  1. Using RLP encoding - Implement RlpBincode for types that already support RLP
  2. Custom implementation - Define a custom representation type

§Examples

§Using with serde_with

#[serde_as]
#[derive(Serialize, Deserialize)]
struct MyStruct {
    #[serde_as(as = "serde_bincode_compat::BincodeReprFor<'_, Header>")]
    data: Header,
}

Structs§

Block
Bincode-compatible [alloy_consensus::Block] serde implementation.
BlockBody
Bincode-compatible [alloy_consensus::BlockBody] serde implementation.
RecoveredBlock
Bincode-compatible super::RecoveredBlock serde implementation.
SealedBlock
Bincode-compatible super::SealedBlock serde implementation.
SealedHeader
Bincode-compatible super::SealedHeader serde implementation.

Traits§

RlpBincode
A helper trait for using RLP-encoding for providing bincode-compatible serialization.
SerdeBincodeCompat
Trait for types that can be serialized and deserialized using bincode.

Type Aliases§

BincodeReprFor
Type alias for the SerdeBincodeCompat::BincodeRepr associated type.