added MIHPacketType::finalize
tho [Fri, 9 Jan 2009 14:57:23 +0000 (14:57 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1054 270642c3-0616-0410-b53a-bc976706d245

Packets/80221Bundle/MIHPacket.cc
Packets/80221Bundle/MIHPacket.hh
Packets/80221Bundle/TLVPacket.cc
Packets/80221Bundle/TLVPacket.hh
Packets/80221Bundle/TLVPacket.test.cc

index 9b2d899..ce0e086 100644 (file)
@@ -53,6 +53,13 @@ prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os)
 }
 
 
+prefix_ void senf::MIHPacketType::finalize(packet p)
+{
+    p->source_length() << senf::bytes( p->source_mihf_id());
+    p->destination_length() << senf::bytes( p->destination_mihf_id());
+    p->payloadLength_() << p.size() - 8;
+}
+
 
 #undef prefix_
 
index b84bbe9..2c1da37 100644 (file)
@@ -80,6 +80,8 @@ namespace senf {
             source_type() = 1;
             destination_type() = 2;
         }
+        
+        friend class MIHPacketType;
     };
     
     
@@ -96,7 +98,7 @@ namespace senf {
         using mixin::initSize;
 
         static void dump(packet p, std::ostream &os);
-//        static void finalize(packet p);
+        static void finalize(packet p);
     };
 
     typedef ConcretePacket<MIHPacketType> MIHPacket;
index 5c7c0da..f79d84b 100644 (file)
@@ -127,25 +127,24 @@ prefix_ void senf::DynamicTLVLengthParser::shrink()
 }
 
 
-prefix_ void senf::BaseTLVPacketParser:: maxLengthValue(DynamicTLVLengthParser::value_type v)
-    const
+prefix_ void senf::DynamicTLVLengthParser:: maxValue(DynamicTLVLengthParser::value_type v)
 {
     if (v <= 127)
         return;
-    size_type b = senf::bytes( length_());
+    size_type b = bytes();
     if (v <= UInt8Parser::max_value) {
-        if (b < 2) length_().resize(2);
+        if (b < 2) resize(2);
         return;
     }
     if (v <= UInt16Parser::max_value) {
-        if (b < 3) length_().resize(3);
+        if (b < 3) resize(3);
         return;
     }
     if (v <= UInt24Parser::max_value) {
-        if (b < 4) length_().resize(4);
+        if (b < 4) resize(4);
         return;
     }
-    if (b < 5) length_().resize(5);
+    if (b < 5) resize(5);
 }
 
 
index f2fdc36..057f06f 100644 (file)
@@ -64,8 +64,10 @@ namespace senf {
         SENF_PARSER_PRIVATE_BITFIELD ( extended_length_flag, 1,  bool     );
         SENF_PARSER_PRIVATE_BITFIELD ( fixed_length_field,   7,  unsigned );
 
-        void resize(size_type size);
         void shrink();
+        void maxValue(DynamicTLVLengthParser::value_type v);
+    private:
+        void resize(size_type size);
     };  
         
 
@@ -76,8 +78,12 @@ namespace senf {
         SENF_PARSER_FIELD_RO ( length, DynamicTLVLengthParser );
         SENF_PARSER_FINALIZE ( BaseTLVPacketParser            );
         
-        void maxLengthValue(DynamicTLVLengthParser::value_type v) const;
-        void shrinkLength() { length_().shrink(); };
+        void maxLengthValue(DynamicTLVLengthParser::value_type v) const {
+            length_().maxValue(v);
+        }
+        void shrinkLength() { 
+            length_().shrink(); 
+        };
         
     protected:
         size_type length_bytes() const { return length_().bytes(); };
index 043a93d..0e46beb 100644 (file)
@@ -149,8 +149,8 @@ namespace {
     struct TestMacAddressTLVPacketParser : public BaseTLVPacketParser
     {
     #   include SENF_PARSER()        
-        SENF_PARSER_INHERIT ( BaseTLVPacketParser )
-        SENF_PARSER_VECTOR  ( value, bytes(length), senf::MACAddressParser )
+        SENF_PARSER_INHERIT ( BaseTLVPacketParser );
+        SENF_PARSER_VECTOR  ( value, bytes(length), senf::MACAddressParser );
         SENF_PARSER_FINALIZE( TestMacAddressTLVPacketParser );
     };