senf::GenericTLVParserBase< Base > Class Template Reference

Base class for generic TLV parsers. More...

#include <senf/Packets/GenericTLV.hh>

Inheritance diagram for senf::GenericTLVParserBase< Base >:

Public Member Functions

 GenericTLVParserBase (PacketParserBase::data_iterator i, PacketParserBase::state_type s)
 
PacketParserBase::size_type bytes () const
 
void init () const
 
template<class Parser >
Parser init ()
 
template<class Parser >
Parser as () const
 
template<class Parser >
bool is () const
 
PacketInterpreterBase::range value () const
 
void dump (std::ostream &os) const
 
template<class ForwardReadableRange >
void value (ForwardReadableRange const &val)
 
template<class ForwardReadableRange >
void value (std::pair< typename Base::type_t::value_type, ForwardReadableRange > const &val)
 

Static Public Attributes

static PacketParserBase::size_type const init_bytes = senf::init_bytes<Base>::value
 

Detailed Description

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:

GenericTLV.png

Your TLVParser base class has to define a type and a length field:

struct MyTLVParserBase : public senf::PacketParserBase
{
# include SENF_PARSER()
SENF_PARSER_FINALIZE( MyTLVParserBase );
};
    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()
SENF_PARSER_INHERIT ( MyTLVParserBase );
SENF_PARSER_FINALIZE( MyConcreteTLVParser );
type() = typeId;
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:
struct MyGenericTLVParser : public senf::GenericTLVParserBase<MyTLVParserBase>
{
MyGenericTLVParser(data_iterator i, state_type s) : base(i,s) {}
// members for your generic TLV parser...
};
    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:
class MyTestPacketParser : public senf::PacketParserBase
{
# include SENF_PARSER()
SENF_PARSER_LIST ( tlv_list, list_length, MyGenericTLVParser );
SENF_PARSER_FINALIZE( MyTestPacketParser );
};
    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() );
optContainer_t::iterator listIter (tlvContainer.begin());
// listIter points to a MyGenericTLVParser, so you have generic access:
listIter->type() = 0x42;
listIter->value(someRangeOfValueData);
// cast to an instance of MyConcreteTLVParser:
if (listIter->is<MyConcreteTLVParser>()) {
MyConcreteTLVParser concreteTLVParser (listIter->as<MyConcreteTLVParser>());
concreteTLVParser.myValue() = 0xabababab;
}
// add a MyConcreteTLV to the list:
MyConcreteTLVParser tlv (tlvContainer.push_back_space().init<MyConcreteTLVParser>());
tlv.myValue() = 0xffff;
    \see
        IPv6GenericOptionParser, WLANGenericInfoElementParser, MIHGenericTLVParser \n
        GenericTLVParserRegistry

Definition at line 124 of file GenericTLV.hh.

Constructor & Destructor Documentation

◆ GenericTLVParserBase()

Definition at line 129 of file GenericTLV.hh.

Member Function Documentation

◆ as()

template<class Base>
template<class Parser >
Parser senf::GenericTLVParserBase< Base >::as ( ) const

◆ bytes()

template<class Base>
PacketParserBase::size_type senf::GenericTLVParserBase< Base >::bytes ( ) const

◆ dump()

template<class Base>
void senf::GenericTLVParserBase< Base >::dump ( std::ostream &  os) const

◆ init() [1/2]

template<class Base>
void senf::GenericTLVParserBase< Base >::init ( ) const

◆ init() [2/2]

template<class Base>
template<class Parser >
Parser senf::GenericTLVParserBase< Base >::init ( )

◆ is()

template<class Base>
template<class Parser >
bool senf::GenericTLVParserBase< Base >::is ( ) const

◆ value() [1/3]

template<class Base>
PacketInterpreterBase::range senf::GenericTLVParserBase< Base >::value ( ) const

◆ value() [2/3]

template<class Base>
template<class ForwardReadableRange >
void senf::GenericTLVParserBase< Base >::value ( ForwardReadableRange const &  val)

◆ value() [3/3]

template<class Base>
template<class ForwardReadableRange >
void senf::GenericTLVParserBase< Base >::value ( std::pair< typename Base::type_t::value_type, ForwardReadableRange > const &  val)

Member Data Documentation

◆ init_bytes

template<class Base>
PacketParserBase::size_type const senf::GenericTLVParserBase< Base >::init_bytes = senf::init_bytes<Base>::value
static

Definition at line 132 of file GenericTLV.hh.


The documentation for this class was generated from the following file: