From: tho Date: Fri, 5 Oct 2007 11:34:56 +0000 (+0000) Subject: TLVPacket creating is working now; thanx to Stefan once again. Documentation will... X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=759f89cf0952cbc42207e5c4cf059d3906a37e59;p=senf.git TLVPacket creating is working now; thanx to Stefan once again. Documentation will follow... git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@455 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/MPEGDVBBundle/TLVPacket.cc b/Packets/MPEGDVBBundle/TLVPacket.cc index 270d81f..628bf55 100644 --- a/Packets/MPEGDVBBundle/TLVPacket.cc +++ b/Packets/MPEGDVBBundle/TLVPacket.cc @@ -33,7 +33,8 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -prefix_ senf::Parse_TLVPacketLength::value_type senf::Parse_TLVPacketLength::value() const { +prefix_ senf::Parse_TLVPacketLength::value_type senf::Parse_TLVPacketLength::value() const +{ switch (bytes() ) { case 1: return fixed_length_field().value(); @@ -50,79 +51,89 @@ prefix_ senf::Parse_TLVPacketLength::value_type senf::Parse_TLVPacketLength::val }; } -prefix_ void senf::Parse_TLVPacketLength::value(value_type const & v) { +prefix_ void senf::Parse_TLVPacketLength::value(value_type const & v) +{ if (v > 4294967295u) throw(UnsuportedTLVPacketException()); - + + SafePacketParser safeThis (*this); if (v < 128u) { - if (bytes() != 1) resize(1); - fixed_length_field() = v; + if (bytes() != 1) { + resize(1); + safeThis->extended_length_flag() = false; + } + safeThis->fixed_length_field() = v; return; } if (v < 256u) { - if (bytes() != 2) resize(2); - parse(1) = v; + if (bytes() != 2) { + resize(2); + safeThis->extended_length_flag() = true; + safeThis->fixed_length_field() = 1; + } + safeThis->parse(1) = v; return; } if (v < 65536u) { - if (bytes() != 3) resize(3); - parse(1) = v; + if (bytes() != 3) { + resize(3); + safeThis->extended_length_flag() = true; + safeThis->fixed_length_field() = 2; + } + safeThis->parse(1) = v; return; } if (v < 16777216u) { - if (bytes() != 4) resize(4); - parse(1) = v; + if (bytes() != 4) { + resize(4); + safeThis->extended_length_flag() = true; + safeThis->fixed_length_field() = 3; + } + safeThis->parse(1) = v; return; } if (v <= 4294967295u) { - if (bytes() != 5) resize(5); - parse(1) = v; + if (bytes() != 5) { + resize(5); + safeThis->extended_length_flag() = true; + safeThis->fixed_length_field() = 4; + } + safeThis->parse(1) = v; return; } } -prefix_ senf::Parse_TLVPacketLength const & senf::Parse_TLVPacketLength::operator= (value_type other) { +prefix_ senf::Parse_TLVPacketLength const & senf::Parse_TLVPacketLength::operator= (value_type other) +{ value(other); return *this; } -prefix_ senf::Parse_TLVPacketLength::size_type senf::Parse_TLVPacketLength::bytes() const { +prefix_ senf::Parse_TLVPacketLength::size_type senf::Parse_TLVPacketLength::bytes() const +{ if ( extended_length_flag() ) return 1 + fixed_length_field(); else return 1; } -prefix_ void senf::Parse_TLVPacketLength::init() const { +prefix_ void senf::Parse_TLVPacketLength::init() const +{ defaultInit(); extended_length_flag() = 0; } -prefix_ void senf::Parse_TLVPacketLength::resize(size_type size) { - std::cout << "senf::Parse_TLVPacketLength::resize: " << unsigned(size) << "\n"; -// hexdump(data().begin(), data().end(), std::cout); - +prefix_ void senf::Parse_TLVPacketLength::resize(size_type size) +{ size_type current_size (bytes()); safe_data_iterator si (data(), i()); if (current_size > size) data().erase( si, boost::next(si, current_size-size)); - else { + else data().insert( si, size-current_size, 0); - Parse_TLVPacketLength(si,state()).init(); - } - - if (size > 1) { - extended_length_flag() = 1; - fixed_length_field() = size-1; - } else { - extended_length_flag() = 0; - } - -// hexdump(data().begin(), data().end(), std::cout); } - prefix_ void senf::TLVPacketType::dump(packet p, std::ostream & os) { os << "TLVPacket:\n" diff --git a/Packets/MPEGDVBBundle/TLVPacket.hh b/Packets/MPEGDVBBundle/TLVPacket.hh index 2bbccb3..e0ff4e0 100644 --- a/Packets/MPEGDVBBundle/TLVPacket.hh +++ b/Packets/MPEGDVBBundle/TLVPacket.hh @@ -82,7 +82,6 @@ namespace senf { } void resize(size_type size); - }; /** \brief parse TLVPacket Packet diff --git a/Packets/MPEGDVBBundle/TLVPacket.test.cc b/Packets/MPEGDVBBundle/TLVPacket.test.cc index 63645a4..eee6c80 100644 --- a/Packets/MPEGDVBBundle/TLVPacket.test.cc +++ b/Packets/MPEGDVBBundle/TLVPacket.test.cc @@ -99,13 +99,13 @@ BOOST_AUTO_UNIT_TEST(tlvPacket_create_packet_with_simple_length) BOOST_CHECK( equal( tlvPacket_value.begin(), tlvPacket_value.end(), payload.begin() )); } -/* + BOOST_AUTO_UNIT_TEST(tlvPacket_create_packet_with_extended_length) { 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( payload.size() + 4 + 2)); + TLVPacket tlvPacket (TLVPacket::create()); tlvPacket->type() = 42u; DataPacket::createAfter( tlvPacket, payload ); tlvPacket.finalize(); @@ -114,10 +114,19 @@ BOOST_AUTO_UNIT_TEST(tlvPacket_create_packet_with_extended_length) BOOST_CHECK_EQUAL( tlvPacket->length(), payload.size() ); PacketData & tlvPacket_value (tlvPacket.next().data()); - BOOST_CHECK( equal( tlvPacket_value.begin(), tlvPacket_value.end(), payload.begin() )); + + payload = std::string("This is a short string with less than 127 characters. That's all."); + DataPacket::createAfter( tlvPacket, payload ); + tlvPacket.finalize(); + + BOOST_CHECK_EQUAL( tlvPacket->type(), 42u ); + BOOST_CHECK_EQUAL( tlvPacket->length(), payload.size() ); + + PacketData & tlvPacket_value2 (tlvPacket.next().data()); + BOOST_CHECK( equal( tlvPacket_value2.begin(), tlvPacket_value2.end(), payload.begin() )); } -*/ + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_