From: g0dil Date: Wed, 17 Oct 2007 07:58:43 +0000 (+0000) Subject: Packets: Some more porting of old parsers to the new parse helpers X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=f87667d7d3b3edafba7e67d6fc33168c4e1af620;p=senf.git Packets: Some more porting of old parsers to the new parse helpers git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@466 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/MPEGDVBBundle/SNDUPacket.cc b/Packets/MPEGDVBBundle/SNDUPacket.cc index abf9783..8b5d048 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 872a39e..19d9b8d 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( 0 ); - } - Parse_length length() const { - return parse( 0 ); - } - Parse_UInt16 type() const { - return parse( 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( 4 ); + return parse( destination_offset() ); } - Parse_UInt32 crc() const { - return parse( 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( 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 7f21415..d8d6ff6 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 37f18d3..a3c66a9 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 c91d4a1..a9a4c4b 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" \ + "ParseField_signed(b)=Parse_IntField" \ + "ParseField_bool(b)=Parse_Flag" EXPAND_AS_DEFINED = prefix_ HTML_HEADER = "$(TOPDIR)/doclib/doxy-header.html"