Skip to main content

Crate openmls_serialization_helpers

Crate openmls_serialization_helpers 

Source
Expand description

Serialization helpers for enums.

These helpers provide custom implementations of [serde::Serialize] and [serde::Deserialize] for the provided enums.

These affect non-self-describing serializations, ensuring that the storage tag specified on each enum variant is used as the numeric tag for that variant (instead of its position in the ordering of variants).

NOTE: These storage tags are always written as u32 values in the serde non-self-describing serializations.

§Usage

Annotate an enum with the Serialize and Deserialize macros to derive [serde::Serialize] and [serde::Deserialize] traits automatically for these enums.

#[derive(
    openmls_serialization_helpers::Serialize,
    openmls_serialization_helpers::Deserialize,
)]
pub enum TestEnum {
  #[storage_tag = 0]
  Unit,
  #[storage_tag = 2]
  Data(Vec<u8>),
  #[storage_tag = 4]
  Tuple(usize, Vec<u8>),
}

Other enum variant formats (such as Data { field: .. }) are not supported by these macros.

These helper macros can also be used with enums that include feature-flagged variants.

Derive Macros§

Deserialize
Serialize