Packets/80221Bundle: one more fix for DynamicTLVLengthParser
tho [Mon, 13 Jul 2009 14:37:38 +0000 (14:37 +0000)]
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

Packets/80221Bundle/MIHPacket.cc
Packets/80221Bundle/TLVPacket.cc
Packets/80221Bundle/TLVPacket.hh
Packets/VectorParser.ct
Packets/VectorParser.cti

index d4e2e61..a81d0fa 100644 (file)
@@ -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));
 }
index 5a17ac7..3c28c5b 100644 (file)
@@ -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();
 }
 
 
index ac2ece4..2151e7f 100644 (file)
@@ -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:
index 2b519fe..e98d027 100644 (file)
@@ -64,8 +64,8 @@ prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::iterator
 senf::VectorParser_Container<ElementParser,AuxPolicy>::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());
 }
 
index adcaec1..60a7924 100644 (file)
@@ -247,8 +247,8 @@ prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::insert(itera
 template <class ElementParser, class AuxPolicy>
 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::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 <class ElementParser, class AuxPolicy>