first small steps to MPEG/DVB support...
[senf.git] / Packets / PacketParser.hh
index a52c888..6c40b2f 100644 (file)
@@ -325,27 +325,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 <tt>DefaultBundle//EthernetPacket.hh</tt>)
-        \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 <tt>DefaultBundle/EthernetPacket.hh</tt>)
+    
+        \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 +447,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
+           {
+               SENF_PACKET_PARSER_NO_INIT(ExtendedParser);
         
+               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,7 +487,36 @@ 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
+           {
+               SENF_PACKET_PARSER_NO_INIT(ExtendedParser);
+
+               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)
 
     struct VoidPacketParser 
         : public PacketParserBase