Derive Macro asn1_rs::BerSequence

source · []
#[derive(BerSequence)]
{
    // Attributes available to this derive:
    #[debug_derive]
    #[default]
    #[optional]
    #[tag_explicit]
    #[tag_implicit]
    #[error]
    #[map_err]
}
Expand description

BerSequence custom derive

BerSequence is a custom derive attribute, to derive a BER Sequence parser automatically from the structure definition. This attribute will automatically derive implementations for the following traits:

DerSequence implies BerSequence, and will conflict with this custom derive. Use BerSequence when you only want the above traits derived.

Parsers will be automatically derived from struct fields. Every field type must implement the FromBer trait.

See derive documentation for more examples and documentation.

Examples

To parse the following ASN.1 structure:

S ::= SEQUENCE {
    a INTEGER(0..2^32),
    b INTEGER(0..2^16),
    c INTEGER(0..2^16),
}

Define a structure and add the BerSequence derive:

use asn1_rs::*;

#[derive(BerSequence)]
struct S {
  a: u32,
  b: u16,
  c: u16
}

Debugging

To help debugging the generated code, the #[debug_derive] attribute has been added.

When this attribute is specified, the generated code will be printed to stderr during compilation.

Example:

use asn1_rs::*;

#[derive(BerSequence)]
#[debug_derive]
struct S {
  a: u32,
}