From e5aff9bd715cfd9b95bf42f928bb18485f7d4dbf Mon Sep 17 00:00:00 2001 From: g0dil <g0dil@wiback.org> Date: Wed, 17 Oct 2007 07:58:43 +0000 Subject: [PATCH] Packets: Some more porting of old parsers to the new parse helpers --- Packets/MPEGDVBBundle/SNDUPacket.cc | 9 ----- Packets/MPEGDVBBundle/SNDUPacket.hh | 46 ++++++++++-------------- Packets/MPEGDVBBundle/TransportPacket.hh | 16 ++++----- Utils/Exception.hh | 1 + doclib/Doxyfile.global | 23 ++++++------ 5 files changed, 41 insertions(+), 54 deletions(-) diff --git a/Packets/MPEGDVBBundle/SNDUPacket.cc b/Packets/MPEGDVBBundle/SNDUPacket.cc index abf97834..8b5d0486 100644 --- a/Packets/MPEGDVBBundle/SNDUPacket.cc +++ b/Packets/MPEGDVBBundle/SNDUPacket.cc @@ -41,15 +41,6 @@ //} -prefix_ senf::PacketParserBase::size_type senf::Parse_SNDUPacket::bytes() - const -{ - if ( d_bit() ) - return 2 + 2 + 4; // D-Bit + 15 bits length + 16 bits type field + 32 bits crc - else - return 2 + 2 + 4 + 6; // + 6 Byte NPA destination address -} - prefix_ boost::uint32_t senf::Parse_SNDUPacket::calcCrc() const { diff --git a/Packets/MPEGDVBBundle/SNDUPacket.hh b/Packets/MPEGDVBBundle/SNDUPacket.hh index 872a39e4..19d9b8da 100644 --- a/Packets/MPEGDVBBundle/SNDUPacket.hh +++ b/Packets/MPEGDVBBundle/SNDUPacket.hh @@ -45,37 +45,29 @@ namespace senf { */ struct Parse_SNDUPacket : public PacketParserBase { - Parse_SNDUPacket(data_iterator i, state_type s) : PacketParserBase(i,s) {} - - typedef Parse_Flag < 0 > Parse_daaf; // Destination Address Absent Field - typedef Parse_UIntField < 1, 16 > Parse_length; - - Parse_daaf d_bit() const { - return parse<Parse_daaf>( 0 ); - } - Parse_length length() const { - return parse<Parse_length>( 0 ); - } - Parse_UInt16 type() const { - return parse<Parse_UInt16>( 2 ); - } - Parse_MAC destination() const { +# include SENF_PARSER() + + SENF_PARSER_BITFIELD ( d_bit , 1 , bool ); + SENF_PARSER_BITFIELD ( length , 15 , unsigned ); + + SENF_PARSER_FIELD ( type , Parse_UInt16 ); + + // This field only exists, if d_bit() is *not* set. New SNDUPackets are created with d_bit() + // set to 0, they have destination. We set the size of this field depending on the value of + // d_bit(), the init_bytes value is set to 6 bytes (the size of a MAC address) + SENF_PARSER_CUSTOM_FIELD ( destination , Parse_MAC , d_bit() ? 0 : 6 , 6 ) { BOOST_ASSERT( ! d_bit() ); - return parse<Parse_MAC>( 4 ); + return parse<destination_t>( destination_offset() ); } - Parse_UInt32 crc() const { - return parse<Parse_UInt32>( data().size()-4 ); - } - - void init() const { - defaultInit(); - d_bit() = false; + + // This field is placed at the end of the parser. It is therefore only considered for + // calculating init_bytes but not for calculating bytes() + SENF_PARSER_CUSTOM_FIELD ( crc , Parse_UInt32 , 0 , 4 ) { + return parse<crc_t>( data().size() - 4 ); } - - PacketParserBase::size_type bytes() const; - - static const size_type init_bytes = 2+2+4; // D-Bit + 15 bits length + 16 bits type field + 32 bits crc + SENF_PARSER_FINALIZE( Parse_SNDUPacket ); + boost::uint32_t calcCrc() const; }; diff --git a/Packets/MPEGDVBBundle/TransportPacket.hh b/Packets/MPEGDVBBundle/TransportPacket.hh index 7f214156..d8d6ff64 100644 --- a/Packets/MPEGDVBBundle/TransportPacket.hh +++ b/Packets/MPEGDVBBundle/TransportPacket.hh @@ -45,15 +45,15 @@ namespace senf { { # include SENF_FIXED_PARSER() - SENF_PARSER_FIELD( sync_byte, Parse_UInt8 ); + SENF_PARSER_FIELD ( sync_byte , Parse_UInt8 ); - SENF_PARSER_BITFIELD( transport_error_indicator, 1, bool ); - SENF_PARSER_BITFIELD( pusi, 1, bool ); - SENF_PARSER_BITFIELD( transport_priority, 1, bool ); - SENF_PARSER_BITFIELD( pid, 13, unsigned ); - SENF_PARSER_BITFIELD( transport_scrmbl_ctrl, 2, unsigned ); - SENF_PARSER_BITFIELD( adaptation_field_ctrl, 2, unsigned ); - SENF_PARSER_BITFIELD( continuity_counter, 4, unsigned ); + SENF_PARSER_BITFIELD ( transport_error_indicator , 1 , bool ); + SENF_PARSER_BITFIELD ( pusi , 1 , bool ); + SENF_PARSER_BITFIELD ( transport_priority , 1 , bool ); + SENF_PARSER_BITFIELD ( pid , 13 , unsigned ); + SENF_PARSER_BITFIELD ( transport_scrmbl_ctrl , 2 , unsigned ); + SENF_PARSER_BITFIELD ( adaptation_field_ctrl , 2 , unsigned ); + SENF_PARSER_BITFIELD ( continuity_counter , 4 , unsigned ); SENF_PARSER_FINALIZE( Parse_TransportPacket ); diff --git a/Utils/Exception.hh b/Utils/Exception.hh index 37f18d3d..a3c66a9b 100644 --- a/Utils/Exception.hh +++ b/Utils/Exception.hh @@ -66,6 +66,7 @@ namespace senf { int err; ///< Error number virtual ~SystemException() throw(); + private: void init(); std::string buffer_; diff --git a/doclib/Doxyfile.global b/doclib/Doxyfile.global index c91d4a17..a9a4c4bb 100644 --- a/doclib/Doxyfile.global +++ b/doclib/Doxyfile.global @@ -29,23 +29,26 @@ MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES PREDEFINED = DOXYGEN \ "SENF_PPI_MODULE(x)=" \ + "SENF_PARSER_INHERIT(name)=" \ "SENF_PARSER_FIELD(name,type)=type name() const" \ "SENF_PARSER_FIELD_RO(name,type)=type::value_type name() const" \ - "SENF_PARSER_FIELD_AFTER(name,type,prev)=type name() const" \ - "SENF_PARSER_FIELD_AFTER_RO(name,type,prev)=type::value_type name() const" \ - "SENF_PARSER_BITFIELD(name, bits, type)=senf::ParseField_ ## type name() const" \ - "SENF_PARSER_BITFIELD_RO(name, bits, type)=type ## _ ## bits name() const" \ - "SENF_PARSER_INHERIT(name)=" \ - "SENF_PARSER_FINALIZE(name)=" \ - "SENF_PARSER_INIT()=void init()" \ + "SENF_PARSER_BITFIELD(name, bits, type)=senf::ParseField_ ## type(bits) name() const" \ + "SENF_PARSER_BITFIELD_RO(name, bits, type)=senf::ParseField_ ## type(bits)::value_type name() const" \ + "SENF_PARSER_CUSTOM_FIELD(name, type, size, isize)=type name() const" \ + "SENF_PARSER_PRIVATE_FIELD(name,type)=private: type name() const; public:" \ + "SENF_PARSER_PRIVATE_FIELD_RO(name, type)=private: type::value_type name() const; public:" \ + "SENF_PARSER_PRIVATE_BITFIELD(name, bits, type)=private: senf::ParseField_ ## type(bits) name() const; public:" \ + "SENF_PARSER_PRIVATE_BITFIELD_RO(name, bits, type)=private: senf::ParseField_ ## type(bits)::value_type name() const; public:" \ "SENF_PARSER_SKIP(x)=" \ "SENF_PARSER_SKIP_BITS(x)=" \ "SENF_PARSER_GOTO(x)=" \ "SENF_PARSER_GOTO_OFFSET(x)=" \ "SENF_PARSER_LABEL(x)=" \ - "ParseField_unsigned=Parse_UIntField" \ - "ParseField_signed=Parse_IntField" \ - "ParseField_bool=Parse_Flag" + "SENF_PARSER_INIT()=void init()" \ + "SENF_PARSER_FINALIZE(name)=" \ + "ParseField_unsigned(b)=Parse_UIntField<?,?+b>" \ + "ParseField_signed(b)=Parse_IntField<?,?+b>" \ + "ParseField_bool(b)=Parse_Flag<?>" EXPAND_AS_DEFINED = prefix_ HTML_HEADER = "$(TOPDIR)/doclib/doxy-header.html" -- GitLab