#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();
};
}
-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<Parse_TLVPacketLength> 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<Parse_UInt8>(1) = v;
+ if (bytes() != 2) {
+ resize(2);
+ safeThis->extended_length_flag() = true;
+ safeThis->fixed_length_field() = 1;
+ }
+ safeThis->parse<Parse_UInt8>(1) = v;
return;
}
if (v < 65536u) {
- if (bytes() != 3) resize(3);
- parse<Parse_UInt16>(1) = v;
+ if (bytes() != 3) {
+ resize(3);
+ safeThis->extended_length_flag() = true;
+ safeThis->fixed_length_field() = 2;
+ }
+ safeThis->parse<Parse_UInt16>(1) = v;
return;
}
if (v < 16777216u) {
- if (bytes() != 4) resize(4);
- parse<Parse_UInt24>(1) = v;
+ if (bytes() != 4) {
+ resize(4);
+ safeThis->extended_length_flag() = true;
+ safeThis->fixed_length_field() = 3;
+ }
+ safeThis->parse<Parse_UInt24>(1) = v;
return;
}
if (v <= 4294967295u) {
- if (bytes() != 5) resize(5);
- parse<Parse_UInt32>(1) = v;
+ if (bytes() != 5) {
+ resize(5);
+ safeThis->extended_length_flag() = true;
+ safeThis->fixed_length_field() = 4;
+ }
+ safeThis->parse<Parse_UInt32>(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"
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();
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_