![]() |
Home | Libraries | People | FAQ | More |
The ASN1 specification defines the SEQUENCE, SEQUENCE OF, SET and SET OF keywords to denote sequences and sets of data. Sequences mean ordered lists and sets are unordered. In essance, a SEQUENCE is a structure of data, and a SEQUENCE OF is an list of data. The SET and SET OF keywords are the unordered counterparts to the SEQUENCE keywords.
Boost.ASN1 has a set of templates used for dealing with PDU
objects. The base templates are called, pdu_base_t
and pdu_base_of_t. From these
two base objects are derived the templates that deal with SEQUENCE
and SET keywords. These templates are named
sequence<>, sequence_of<>,
set<> and set_of<>.
These templates are fairly easy to use; you create a structure with the variables
you require in the PDU and then use that
structure as the type parameter for one of the templates. For instance:
| ASN1 | Boost.ASN1 |
|---|---|
Authenticate := SEQUENCE { MessageID INTEGER, UserName IA5STRING, Password OCTET STRING } |
struct authenticate { integer_t MessageID; ia5string_t UserName; octectstring_t Password; }; sequence<authenticate> Authenticate; |
The sequence<> template allows for the user to directly access the structure that is contained as the typename, for example:
Authenticate.MessageID = rng();
The sequence_of template is simply a vector of ASN1 objects, so, you would use it like an array:
sequence_of<ia5string_t> string_list; string_list[0] = "First"; string_list[1] = "Second"; string_list[3] = "Third";
This type conversion funcionality is only the first step to encoding or decoding
your data. You must give these functions an asn_base_ptr
to either convert from or to.
asn_base_ptr pduPtr; string_list.to(pduPtr);
This now gives you a PDU pointer that the
asn_encode and asn_decode can use to encode/decode the
actual ASN1 packet.
| Copyright © 2007 Andreas Haberstroh |