template<class Base>
class senf::GenericTLVParserBase< Base >
Base class for generic TLV parsers.
This abstract base class can be used to define generic TLV parsers. The following class structure is assumed:
Your TLVParser base class has to define a type
and a length
field:
{
# include SENF_PARSER()
};
Your concrete TLV parsers will inherit from this base class and have to define a specific
value field and a \c typeId member:
struct MyConcreteTLVParser : public MyTLVParserBase
{
# include SENF_PARSER()
length_() = 4;
}
static const type_t::value_type typeId = 0x42;
};
With GenericTLVParserBase you can define a generic parser class which provides
members to access the value data and and to cast the parser to a concrete tlv
parser:
{
MyGenericTLVParser(data_iterator i, state_type s) : base(i,s) {}
};
If your generic TLV parser just inherits from GenericTLVParserBase and doesn't
add any additional functionality you can use a simple \c typedef as well:
This generic tlv parser can now be used for example in a list:
{
# include SENF_PARSER()
};
Now, you can access the TLV parsers in the list in a generic way or you
can cast the parsers to some concrete tlv parser:
MyTestPacket p (...
typedef MyTestPacket::Parser::tlv_list_t::container_type container_t;
container_t tlvContainer (p->tlv_list() );
listIter->type() = 0x42;
listIter->value(someRangeOfValueData);
if (listIter->is<MyConcreteTLVParser>()) {
MyConcreteTLVParser concreteTLVParser (listIter->as<MyConcreteTLVParser>());
concreteTLVParser.myValue() = 0xabababab;
}
MyConcreteTLVParser
tlv (tlvContainer.push_back_space().init<MyConcreteTLVParser>());
\see
IPv6GenericOptionParser, WLANGenericInfoElementParser, MIHGenericTLVParser \n
GenericTLVParserRegistry
Definition at line 124 of file GenericTLV.hh.