senf::GenericTLVParserBase< Base > Class Template Reference

Base class for generic TLV parsers. More...

#include <senf/Packets/GenericTLV.hh>

List of all members.


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_FIELD    ( type,   senf::UInt8Parser );
    SENF_PARSER_FIELD_RO ( length, senf::UInt8Parser );
    SENF_PARSER_FINALIZE ( MyTLVParserBase           );
};

Your concrete TLV parsers will inherit from this base class and have to define a specific value field and a typeId member:

struct MyConcreteTLVParser : public MyTLVParserBase
{
#   include SENF_PARSER()
    SENF_PARSER_INHERIT  ( MyTLVParserBase             );
    SENF_PARSER_FIELD    ( myValue, senf::UInt32Parser );
    SENF_PARSER_FINALIZE ( MyConcreteTLVParser         );

    SENF_PARSER_INIT() {
        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>
{
    typedef senf::GenericTLVParserBase<MyTLVParserBase> base;
    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 typedef as well:

typedef senf::GenericTLVParserBase<MyTLVParserBase> MyGenericTLVParser;

This generic tlv parser can now be used for example in a list:

class MyTestPacketParser : public senf::PacketParserBase
{
#   include SENF_PARSER()
    SENF_PARSER_FIELD_RO ( list_length, senf::UInt8Parser );
    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 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 also:
IPv6GenericOptionParser, WLANGenericInfoElementParser, MIHGenericTLVParser
GenericTLVParserRegistry

Definition at line 133 of file GenericTLV.hh.


Public Member Functions

  GenericTLVParserBase (senf::PacketParserBase::data_iterator i, senf::PacketParserBase::state_type s)
senf::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
senf::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)

Constructor & Destructor Documentation

template<class Base>
senf::GenericTLVParserBase< Base >::
GenericTLVParserBase ( senf::PacketParserBase::data_iterator  i,
senf::PacketParserBase::state_type  s )

Definition at line 136 of file GenericTLV.hh.


Member Function Documentation

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

Definition at line 55 of file GenericTLV.cti.

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

Reimplemented in senf::NDPGenericOptionParser.

Definition at line 37 of file GenericTLV.cti.

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

Definition at line 55 of file GenericTLV.ct.

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

Definition at line 42 of file GenericTLV.ct.

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

Reimplemented in senf::MIHGenericTLVParser.

Definition at line 47 of file GenericTLV.cti.

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

Definition at line 63 of file GenericTLV.cti.

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

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

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

Definition at line 71 of file GenericTLV.ct.


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