1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! 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.
//! ```rust
//! #[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.
use TokenStream;