X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketParser.hh;h=21858ba8a4cbfebd6fbe316acc68752f8e9c92c7;hb=2c10a733c69cd95e10a312a471c84d07d52b7755;hp=a52c888a63ddfc917d535c399f908ff2484fa195;hpb=ef0a3583fc76292d631de6a4a5cad4a432351ac8;p=senf.git diff --git a/Packets/PacketParser.hh b/Packets/PacketParser.hh index a52c888..21858ba 100644 --- a/Packets/PacketParser.hh +++ b/Packets/PacketParser.hh @@ -463,8 +463,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 +503,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