Macro eagre_asn1::der_choice
[−]
[src]
macro_rules! der_choice { ($choice_name:ident : $($variant_name:ident : $tagtype:ident $(TAG $tagclass:ident $tagval:expr ;)* TYPE $variant_type:ty),+) => { ... }; ($choice_name:ident : $($variant_name:ident : $tagtype:ident $(TAG $tagclass:ident $tagval:expr ;)* TYPE $variant_type:ty),+,) => { ... }; }
Macro to create choice implementation for enum
Used like der_sequence!
except that every variant has to have it's unique tag
Example
enum Command { Forward(i32), Rotate(i32), Start(Null), Stop(Null), } der_choice!{ Command: // Don't forget to make every variant have it's own tag Forward: IMPLICIT TAG CONTEXT 1; TYPE i32, Rotate: IMPLICIT TAG CONTEXT 2; TYPE i32, Start: IMPLICIT TAG CONTEXT 3; TYPE Null, Stop: IMPLICIT TAG CONTEXT 4; TYPE Null, } for cmd in vec!(Command::Start(Null), Command::Forward(12), Command::Rotate(2), Command::Stop(Null)) { let encoded = cmd.der_bytes().unwrap(); // Send to far away planet let decoded = Command::der_from_bytes(encoded).unwrap(); assert_eq!(cmd, decoded); }