X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketParser.hh;h=631bf10f915736700f0796cabcbba485d9f8b80b;hb=d084c02e4914da4fa1a4098a33d704f69e8bdedd;hp=a52c888a63ddfc917d535c399f908ff2484fa195;hpb=ef0a3583fc76292d631de6a4a5cad4a432351ac8;p=senf.git diff --git a/Packets/PacketParser.hh b/Packets/PacketParser.hh index a52c888..631bf10 100644 --- a/Packets/PacketParser.hh +++ b/Packets/PacketParser.hh @@ -74,9 +74,7 @@ #include #include "Utils/SafeBool.hh" #include "PacketTypes.hh" -#define HH_PacketData_DeclOnly #include "PacketData.hh" -#undef HH_PacketData_DeclOnly #include "PacketParser.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -325,27 +323,11 @@ namespace senf { These macros simplify providing the above defined interface. A typical packet declaration using these macros has the following form (This is a concrete example from the definition of - the ethernet packet in DefaultBundle//EthernetPacket.hh) - \code - struct Parse_EthVLan : public senf::PacketParserBase - { - SENF_PACKET_PARSER_INIT(Parse_EthVLan); - - // //////////////////////////////////////////////////////////////////////// - - typedef senf::Parse_UIntField < 0, 3 > Parse_Priority; - typedef senf::Parse_Flag < 3 > Parse_CFI; - typedef senf::Parse_UIntField < 4, 16 > Parse_VLanId; - typedef senf::Parse_UInt16 Parse_Type; - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((OverlayField)( priority, Parse_Priority )) - ((OverlayField)( cfi, Parse_CFI )) - ((Field )( vlanId, Parse_VLanId )) - ((Field )( type, Parse_Type )) - ); - }; - \endcode + the ethernet packet in DefaultBundle/EthernetPacket.hh) + + \dontinclude EthernetPacket.hh + \skipline struct Parse_EthVLan : public PacketParserBase + \until }; The macros take care of the following: \li They define the accessor functions returning parsers of the given type. @@ -463,8 +445,37 @@ namespace senf { \hideinitializer */ # define SENF_PACKET_PARSER_DEFINE_FIELDS(fields) \ - SENF_PACKET_PARSER_I_DEFINE_FIELDS(fields) + SENF_PACKET_PARSER_I_DEFINE_FIELDS(0,fields) + /** \brief Define fields for a dynamically sized parser (with offset) + + Define the fields as specified in \a fields. This macro supports dynamically sized + subfields, the resulting parser will be dynamically sized. + + The \a offset argument gives the byte offset at which to start parsing the fields. This + helps defining extended parser deriving from a base parser: + \code + struct ExtendedParser : public BaseParser + { + ExtendedParser(data_iterator i, state_type s) : BaseParser(i,s) {} + + SENF_PACKET_PARSER_DEFINE_FIELDS_OFFSET(senf::bytes(BaseParser(*this)), + ( ... fields ... ) ); + + void init() { + BaseParser::init(); + defaultInit(); + // other init code + } + } + \endcode + + \ingroup packetparsermacros + \hideinitializer + */ +# define SENF_PACKET_PARSER_DEFINE_FIELDS_OFFSET(offset,fields) \ + SENF_PACKET_PARSER_I_DEFINE_FIELDS(offset,fields) + /** \brief Define fields for a fixed size parser Define the fields as specified in \a fields. This macro only supports fixed size @@ -474,8 +485,39 @@ namespace senf { \hideinitializer */ # define SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(fields) \ - SENF_PACKET_PARSER_I_DEFINE_FIXED_FIELDS(fields) + SENF_PACKET_PARSER_I_DEFINE_FIXED_FIELDS(0,fields) + /** \brief Define fields for a fixed size parser + + Define the fields as specified in \a fields. This macro only supports fixed size + subfields, the resulting parser will also be a fixed size parser. + + The \a offset argument gives the byte offset at which to start parsing the fields. This + helps defining extended parser deriving from a base parser: + \code + struct ExtendedParser : public BaseParser + { + ExtendedParser(data_iterator i, state_type s) : BaseParser(i,s) {} + + SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS_OFFSET(BaseParser::fixed_bytes, + ( ... fields ... ) ); + + void init() { + BaseParser::init(); + defaultInit(); + // other init code + } + } + \endcode + + \ingroup packetparsermacros + \hideinitializer + */ +# define SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS_OFFSET(offset,fields) \ + SENF_PACKET_PARSER_I_DEFINE_FIXED_FIELDS(offset,fields) + + /** \brief Default parser parsing nothing + */ struct VoidPacketParser : public PacketParserBase { @@ -540,6 +582,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketParser_i_) +#define HH_PacketParser_i_ #include "PacketParser.cci" #include "PacketParser.ct" #include "PacketParser.cti" @@ -556,13 +601,3 @@ namespace senf { // comment-column: 40 // End: -// LocalWords: templated PacketParser defgroup packetparser PacketParsers li -// LocalWords: EthernetParser ethertype UInt senf PacketParserBase tt -// LocalWords: struct FooParser const init endcode ingroup param SomeParser -// LocalWords: ethernet DefaultBundle EthernetPacket hh EthVLan UIntField CFI -// LocalWords: VLanId OverlayField cfi vlanId accessor defaultInit bitfield -// LocalWords: SomePacket SimpleVectorSizer packetparsermacros Fraunhofer std -// LocalWords: hideinitializer Institut fuer offene Kommunikationssysteme STL -// LocalWords: FOKUS Kompetenzzentrum Satelitenkommunikation SatCom Bund cerr -// LocalWords: berlios dil Structors someField someVector someOtherField -// LocalWords: TruncatedPacketException