thalassa-derive
Description
Derives for thalassa
Note: A lot of this is similar to tls_codec's derives, in an effort to ease migration between the derives/attrs
Attributes
On Enums
#[tlspl(untagged)]- Marks that this enum contents should not be de/serialized preceded by their discriminant. This is especially useful when using the#[tlspl(select)]attribute#[tlspl(extensible)]- This marks an enum as "extensible", meaning that the contents of the variants (eg. its fields) will be serialized as a variable-length bytes container, to ensure that it can be extended, serialized and deserialized even in the case of future evolutions or downstream-defined extensions. This is inspired by how MLS (RFC9420) Extensions are done.
On Enum Variants
#[tlspl(discrmininant = "path::to::constant"|1337)]- Allows to point to a discriminant tag for cases where it's not supported by the Rust language (eg complex data types/structs where explicit discriminant isn't allowed).- This also supports the following forms
- integer literals:
#[tlspl(discriminant = 69)] - constants:
#[tlspl(discriminant = "MY_CONST")]- note: wrapped in a string - enum variants that have an explicit discriminant:
#[tlspl(discriminant = "MyEnum::CaseN")]- note: wrapped in a string
- integer literals:
- This also supports the following forms
#[tlspl(other)]- Marks a "catch-all" or "unknown" variant that needs to be a tuple having 1 field equal to the #[repr] of the enum (for naked enums), or 2 fields equal to(repr, Cow<[u8]>)(for enums that have data)- Example
On Fields
#[tlspl(skip)]- Skips this field during both serialization and deserialization. RequiresDefaultto be implemented on the field since this data format has a fixed data layout.#[tlspl(with = path::to::module)]- Allows to override the ser/deser implementation of the underlying type with a custom implementation. The module should export any of those functions, depending on which trait your're deriving:tlspl_serialized_len(&T) -> usizetlspl_serialize_to(&T, writer) -> TlsplWriteResult<usize>tlspl_deserialize_from(reader) -> TlsplReadResult<T>
#[tlspl(select = field.member.thing)]- mirrors theselectkeyword in TLSPL prose found in specifications.- Restrictions
- The targeted field must be declared BEFORE this field. The order of declaration matters in TLSPL.
- The type of the field with this attribute must be an enum that has
#[tlspl(untagged)]
- Example
- Restrictions
- Enum Variants