From: tho Date: Mon, 13 Jul 2009 14:37:38 +0000 (+0000) Subject: Packets/80221Bundle: one more fix for DynamicTLVLengthParser X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=725143806766debe218a838352a2b3db3824a027;p=senf.git Packets/80221Bundle: one more fix for DynamicTLVLengthParser Packets/VectorParser: set length field before adding new values to the vector git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1271 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/80221Bundle/MIHPacket.cc b/Packets/80221Bundle/MIHPacket.cc index d4e2e61..a81d0fa 100644 --- a/Packets/80221Bundle/MIHPacket.cc +++ b/Packets/80221Bundle/MIHPacket.cc @@ -123,8 +123,8 @@ prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os) prefix_ void senf::MIHPacketType::finalize(packet p) { - p->src_mihfId().shrinkLength(); - p->dst_mihfId().shrinkLength(); + p->src_mihfId().finalizeLength(); + p->dst_mihfId().finalizeLength(); p->payloadLength_() << p.size() - 8; p->messageId() << key(p.next(nothrow)); } diff --git a/Packets/80221Bundle/TLVPacket.cc b/Packets/80221Bundle/TLVPacket.cc index 5a17ac7..3c28c5b 100644 --- a/Packets/80221Bundle/TLVPacket.cc +++ b/Packets/80221Bundle/TLVPacket.cc @@ -92,7 +92,27 @@ prefix_ void senf::DynamicTLVLengthParser::value(value_type const & v) default: throw( TLVLengthException()); }; - underflow_flag() = v < 128; + underflow_flag() = (v <= 128); +} + + +prefix_ senf::DynamicTLVLengthParser::value_type senf::DynamicTLVLengthParser::maxValue() + const +{ + switch (bytes() ) { + case 1: + return 128; + case 2: + return UInt8Parser::max_value + 128; + case 3: + return UInt16Parser::max_value + 128; + case 4: + return UInt24Parser::max_value + 128; + case 5: + return UInt32Parser::max_value; + default: + throw( TLVLengthException()); + }; } @@ -110,7 +130,7 @@ prefix_ void senf::DynamicTLVLengthParser::init() const } -prefix_ void senf::DynamicTLVLengthParser::shrink() +prefix_ void senf::DynamicTLVLengthParser::finalize() { value_type v = value(); size_type b = bytes(); @@ -199,7 +219,7 @@ prefix_ void senf::GenericTLVPacketType::dump(packet p, std::ostream & os) prefix_ void senf::GenericTLVPacketType::finalize(packet p) { - p->shrinkLength(); + p->finalizeLength(); } diff --git a/Packets/80221Bundle/TLVPacket.hh b/Packets/80221Bundle/TLVPacket.hh index ac2ece4..2151e7f 100644 --- a/Packets/80221Bundle/TLVPacket.hh +++ b/Packets/80221Bundle/TLVPacket.hh @@ -68,8 +68,9 @@ namespace senf { SENF_PARSER_PRIVATE_BITFIELD ( underflow_flag, 1, bool ); SENF_PARSER_PRIVATE_BITFIELD ( fixed_length_field, 6, unsigned ); - void shrink(); - void maxValue(DynamicTLVLengthParser::value_type v); + void finalize(); + void maxValue(value_type v); + value_type maxValue() const; private: void resize(size_type size); }; @@ -131,8 +132,8 @@ namespace senf { The size of the length field will be decreased to minimum necessary to hold the current length value. */ - void shrinkLength() { - length_().shrink(); + void finalizeLength() { + length_().finalize(); }; protected: diff --git a/Packets/VectorParser.ct b/Packets/VectorParser.ct index 2b519fe..e98d027 100644 --- a/Packets/VectorParser.ct +++ b/Packets/VectorParser.ct @@ -64,8 +64,8 @@ prefix_ typename senf::VectorParser_Container::iterator senf::VectorParser_Container::shift(iterator pos, size_type n) { size_type ix (std::distance(data().begin(),pos.raw())); - data().insert(pos.raw(),n*ElementParser::fixed_bytes,0); setSize(size()+n); + data().insert(pos.raw(),n*ElementParser::fixed_bytes,0); return iterator(boost::next(data().begin(),ix),state()); } diff --git a/Packets/VectorParser.cti b/Packets/VectorParser.cti index adcaec1..60a7924 100644 --- a/Packets/VectorParser.cti +++ b/Packets/VectorParser.cti @@ -247,8 +247,8 @@ prefix_ void senf::VectorParser_Container::insert(itera template prefix_ void senf::VectorParser_Container::erase(iterator pos, size_type n) { - data().erase(pos.raw(),boost::next(pos.raw(),n*ElementParser::fixed_bytes)); setSize(size()-n); + data().erase(pos.raw(),boost::next(pos.raw(),n*ElementParser::fixed_bytes)); } template