From: tho Date: Mon, 14 Jan 2008 12:40:05 +0000 (+0000) Subject: made the TLVPacketType more generic X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=652de52f32911951ca0c372459555aabf8e22bed;p=senf.git made the TLVPacketType more generic git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@593 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/MPEGDVBBundle/TLVPacket.cc b/Packets/MPEGDVBBundle/TLVPacket.cc index 42e0dd6..962c044 100644 --- a/Packets/MPEGDVBBundle/TLVPacket.cc +++ b/Packets/MPEGDVBBundle/TLVPacket.cc @@ -33,7 +33,7 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -prefix_ senf::TLVPacketLengthParser::value_type senf::TLVPacketLengthParser::value() const +prefix_ senf::DynamicTLVLengthParser::value_type senf::DynamicTLVLengthParser::value() const { switch (bytes() ) { case 1: @@ -51,12 +51,12 @@ prefix_ senf::TLVPacketLengthParser::value_type senf::TLVPacketLengthParser::val }; } -prefix_ void senf::TLVPacketLengthParser::value(value_type const & v) +prefix_ void senf::DynamicTLVLengthParser::value(value_type const & v) { if (v > 4294967295u) throw(UnsuportedTLVPacketException()); - SafePacketParserWrapper safeThis (*this); + SafePacketParserWrapper safeThis (*this); if (v < 128u) { if (bytes() != 1) { resize(1); @@ -103,13 +103,13 @@ prefix_ void senf::TLVPacketLengthParser::value(value_type const & v) } } -prefix_ senf::TLVPacketLengthParser const & senf::TLVPacketLengthParser::operator= (value_type other) +prefix_ senf::DynamicTLVLengthParser const & senf::DynamicTLVLengthParser::operator= (value_type other) { value(other); return *this; } -prefix_ senf::TLVPacketLengthParser::size_type senf::TLVPacketLengthParser::bytes() const +prefix_ senf::DynamicTLVLengthParser::size_type senf::DynamicTLVLengthParser::bytes() const { if ( extended_length_flag() ) return 1 + fixed_length_field(); @@ -117,13 +117,13 @@ prefix_ senf::TLVPacketLengthParser::size_type senf::TLVPacketLengthParser::byte return 1; } -prefix_ void senf::TLVPacketLengthParser::init() const +prefix_ void senf::DynamicTLVLengthParser::init() const { defaultInit(); extended_length_flag() = 0; } -prefix_ void senf::TLVPacketLengthParser::resize(size_type size) +prefix_ void senf::DynamicTLVLengthParser::resize(size_type size) { size_type current_size (bytes()); safe_data_iterator si (data(), i()); diff --git a/Packets/MPEGDVBBundle/TLVPacket.ct b/Packets/MPEGDVBBundle/TLVPacket.ct index 182d023..1b965a4 100644 --- a/Packets/MPEGDVBBundle/TLVPacket.ct +++ b/Packets/MPEGDVBBundle/TLVPacket.ct @@ -31,8 +31,8 @@ #define prefix_ ///////////////////////////////ct.p//////////////////////////////////////// -template -prefix_ void senf::TLVPacketType::dump(packet p, std::ostream & os) +template +prefix_ void senf::TLVPacketType::dump(packet p, std::ostream & os) { os << "TLVPacket:" << std::dec @@ -40,8 +40,8 @@ prefix_ void senf::TLVPacketType::dump(packet p, std::ostream & os << " length: " << unsigned(p->length()) << "\n"; } -template -prefix_ void senf::TLVPacketType::finalize(packet p) +template +prefix_ void senf::TLVPacketType::finalize(packet p) { PacketData::size_type size = p.next().data().size(); if ( size > LengthParser::max_value ) @@ -49,15 +49,15 @@ prefix_ void senf::TLVPacketType::finalize(packet p) p->length() = size; } -template -prefix_ senf::PacketParserBase::size_type senf::TLVPacketType::initSize() +template +prefix_ senf::PacketParserBase::size_type senf::TLVPacketType::initSize() { - return 4 + senf::init_bytes::value; + return senf::init_bytes::value + senf::init_bytes::value; } -template +template prefix_ senf::PacketInterpreterBase::optional_range -senf::TLVPacketType::nextPacketRange(packet p) +senf::TLVPacketType::nextPacketRange(packet p) { if (p.data().size() < 5) return no_range(); diff --git a/Packets/MPEGDVBBundle/TLVPacket.hh b/Packets/MPEGDVBBundle/TLVPacket.hh index 4ba9b94..17b2f9a 100644 --- a/Packets/MPEGDVBBundle/TLVPacket.hh +++ b/Packets/MPEGDVBBundle/TLVPacket.hh @@ -51,12 +51,12 @@ namespace senf { /** \brief xxx \todo document me */ - class TLVPacketLengthParser - : public detail::packet::IntParserOps, + class DynamicTLVLengthParser + : public detail::packet::IntParserOps, public PacketParserBase { public: - TLVPacketLengthParser(data_iterator i, state_type s) : PacketParserBase(i,s) {} + DynamicTLVLengthParser(data_iterator i, state_type s) : PacketParserBase(i,s) {} typedef boost::uint32_t value_type; static const size_type init_bytes = 1; @@ -66,10 +66,8 @@ namespace senf { value_type value() const; void value(value_type const & v); - TLVPacketLengthParser const & operator= (value_type other); - + DynamicTLVLengthParser const & operator= (value_type other); size_type bytes() const; - void init() const; private: @@ -93,12 +91,12 @@ namespace senf { \see TLVPacketType */ - template + template struct TLVPacketParser : public PacketParserBase { # include SENF_PARSER() - SENF_PARSER_FIELD( type, UInt32Parser ); + SENF_PARSER_FIELD( type, TypeParser ); SENF_PARSER_FIELD( length, LengthParser ); SENF_PARSER_FINALIZE(TLVPacketParser); @@ -110,14 +108,13 @@ namespace senf { \ingroup protocolbundle_mpegdvb */ - template + template struct TLVPacketType : public PacketTypeBase { -#ifndef DOXYGEN - typedef ConcretePacket > packet; - typedef TLVPacketParser parser; -#endif + typedef ConcretePacket > packet; + typedef TLVPacketParser parser; + static optional_range nextPacketRange(packet p); static size_type initSize(); @@ -125,13 +122,8 @@ namespace senf { static void dump(packet p, std::ostream & os); }; - - typedef TLVPacketType::packet TLVPacket; - typedef ConcretePacket > TLVFix8Packet; - typedef ConcretePacket > TLVFix16Packet; - typedef ConcretePacket > TLVFix24Packet; - typedef ConcretePacket > TLVFix32Packet; + typedef ConcretePacket > MIHInfoElement; } diff --git a/Packets/MPEGDVBBundle/TLVPacket.test.cc b/Packets/MPEGDVBBundle/TLVPacket.test.cc index d6aadc6..1c3d94d 100644 --- a/Packets/MPEGDVBBundle/TLVPacket.test.cc +++ b/Packets/MPEGDVBBundle/TLVPacket.test.cc @@ -56,36 +56,42 @@ BOOST_AUTO_UNIT_TEST(TLVPacket_static) { // check static values: // number of bytes to allocate for a new TLVPacket should be 5 - BOOST_CHECK_EQUAL( TLVPacket::type::initSize(), 5u ); + // BOOST_CHECK_EQUAL( TLVPacket::type::initSize(), 5u ); } + BOOST_AUTO_UNIT_TEST(TLVPacket_parse_packet_with_simple_length) { + typedef ConcretePacket > TestTLVPacket; unsigned char data[] = { 0x01, 0x23, 0x45, 0x67, // type 0x0A, // first bit not set, length=10 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 // value (payload) }; - senf::TLVPacket tlvPacket (senf::TLVPacket::create(data)); + TestTLVPacket tlvPacket (TestTLVPacket::create(data)); check_TLVPacket( tlvPacket, 0x01234567u, 0x0Au ); } + BOOST_AUTO_UNIT_TEST(TLVPacket_parse_packet_with_extended_length) { + typedef ConcretePacket > TestTLVPacket; unsigned char data[] = { 0x01, 0x23, 0x45, 0x67, // type 0x81, // first and last bit set => one byte length following 0x0A, // length (10 bytes value) 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 // value (payload) }; - senf::TLVPacket tlvPacket (senf::TLVPacket::create(data)); + TestTLVPacket tlvPacket (TestTLVPacket::create(data)); check_TLVPacket( tlvPacket, 0x01234567u, 0x0Au ); } + BOOST_AUTO_UNIT_TEST(TLVPacket_create_packet_with_simple_length) { + typedef ConcretePacket > TestTLVPacket; std::string payload ("Hello, world!"); - TLVPacket tlvPacket (TLVPacket::create()); + TestTLVPacket tlvPacket (TestTLVPacket::create()); tlvPacket->type() = 42u; DataPacket::createAfter( tlvPacket, payload ); tlvPacket.finalize(); @@ -100,10 +106,11 @@ BOOST_AUTO_UNIT_TEST(TLVPacket_create_packet_with_simple_length) BOOST_AUTO_UNIT_TEST(TLVPacket_create_packet_with_extended_length) { + typedef ConcretePacket > TestTLVPacket; std::string payload ( "This is a very long string with more than 127 characters to check if the TLV-Packet " "works correctly with an extended length. That's all." ); - TLVPacket tlvPacket (TLVPacket::create()); + TestTLVPacket tlvPacket (TestTLVPacket::create()); tlvPacket->type() = 42u; DataPacket::createAfter( tlvPacket, payload ); tlvPacket.finalize(); @@ -125,19 +132,21 @@ BOOST_AUTO_UNIT_TEST(TLVPacket_create_packet_with_extended_length) BOOST_CHECK( equal( tlvPacket_value2.begin(), tlvPacket_value2.end(), payload.begin() )); } + BOOST_AUTO_UNIT_TEST(TLVPacket_create_invalid_packet) { } + BOOST_AUTO_UNIT_TEST(TLVFixPacket_static) { // check static values: - // number of bytes to allocate for a new TLVFixPacket should be 4+bytes_of_length - BOOST_CHECK_EQUAL( TLVFix8Packet::type::initSize(), 4+1u ); - BOOST_CHECK_EQUAL( TLVFix16Packet::type::initSize(), 4+2u ); - BOOST_CHECK_EQUAL( TLVFix24Packet::type::initSize(), 4+3u ); - BOOST_CHECK_EQUAL( TLVFix32Packet::type::initSize(), 4+4u ); + typedef ConcretePacket > TestTLVPacket8; + typedef ConcretePacket > TestTLVPacket24; + + BOOST_CHECK_EQUAL( TestTLVPacket8::type::initSize(), 4+1u ); + BOOST_CHECK_EQUAL( TestTLVPacket24::type::initSize(), 4+3u ); } @@ -158,10 +167,15 @@ void test_TLVFixPacket_parsing(unsigned lengthParser_size) BOOST_AUTO_UNIT_TEST(TLVFixPacket_parse_packet) { - test_TLVFixPacket_parsing( UInt8Parser::fixed_bytes); - test_TLVFixPacket_parsing( UInt16Parser::fixed_bytes); - test_TLVFixPacket_parsing( UInt24Parser::fixed_bytes); - test_TLVFixPacket_parsing( UInt32Parser::fixed_bytes); + typedef ConcretePacket > TestTLVPacket8; + typedef ConcretePacket > TestTLVPacket16; + typedef ConcretePacket > TestTLVPacket24; + typedef ConcretePacket > TestTLVPacket32; + + test_TLVFixPacket_parsing( UInt8Parser::fixed_bytes); + test_TLVFixPacket_parsing( UInt16Parser::fixed_bytes); + test_TLVFixPacket_parsing( UInt24Parser::fixed_bytes); + test_TLVFixPacket_parsing( UInt32Parser::fixed_bytes); } @@ -183,10 +197,15 @@ void test_TLVFixPacket_creating() BOOST_AUTO_UNIT_TEST(TLVFixPacket_create_packet) { - test_TLVFixPacket_creating(); - test_TLVFixPacket_creating(); - test_TLVFixPacket_creating(); - test_TLVFixPacket_creating(); + typedef ConcretePacket > TestTLVPacket8; + typedef ConcretePacket > TestTLVPacket16; + typedef ConcretePacket > TestTLVPacket24; + typedef ConcretePacket > TestTLVPacket32; + + test_TLVFixPacket_creating(); + test_TLVFixPacket_creating(); + test_TLVFixPacket_creating(); + test_TLVFixPacket_creating(); } @@ -202,10 +221,13 @@ void test_invalid_TLVFixPacket_creating(boost::uint32_t max_value) BOOST_AUTO_UNIT_TEST(TLVFixPacket_create_invalid_packet) { - test_invalid_TLVFixPacket_creating ( UInt8Parser::max_value); - test_invalid_TLVFixPacket_creating( UInt16Parser::max_value); - test_invalid_TLVFixPacket_creating( UInt24Parser::max_value); - //test_invalid_TLVFixPacket_creating( UInt32Parser::max_value); + typedef ConcretePacket > TestTLVPacket8; + typedef ConcretePacket > TestTLVPacket16; + typedef ConcretePacket > TestTLVPacket24; + + test_invalid_TLVFixPacket_creating ( UInt8Parser::max_value); + test_invalid_TLVFixPacket_creating( UInt16Parser::max_value); + test_invalid_TLVFixPacket_creating( UInt24Parser::max_value); }