added scheduler watchdog members to sys/scheduler console dir
[senf.git] / senf / Packets / 80221Bundle / TLVParser.cc
index 5f35f25..729b1ec 100644 (file)
@@ -29,7 +29,6 @@
 // Custom includes
 #include <senf/Utils/hexdump.hh>
 #include <senf/Utils/Format.hh>
-#include <senf/Utils/String.hh>
 
 #define prefix_
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -42,15 +41,21 @@ SENF_PACKET_TLV_REGISTRY_REGISTER( senf::MIHValidTimeIntervalTLVParser );
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
 // MIHBaseTLVParser
 
-prefix_ void senf::MIHBaseTLVParser::validateTL(boost::uint8_t expectedType, MIHTLVLengthParser::value_type expectedLength)
+prefix_ void senf::MIHBaseTLVParser::validateType(boost::uint8_t expectedType)
     const
 {
     if (! check( 1 + senf::bytes(length_()) + length()) )
-        throw InvalidMIHPacketException("truncated TLV.") << " Type: " << senf::str(type());
+        throw InvalidMIHPacketException("truncated TLV.") << " Type: " << unsigned(type());
     if (type() != expectedType)
-        throw InvalidMIHPacketException("invalid TLV type") << " Type: " << senf::str(type());
+        throw InvalidMIHPacketException("wrong TLV type. expected ") << unsigned(expectedType) << " got " << unsigned(type());
+}
+
+prefix_ void senf::MIHBaseTLVParser::validateTypeLength(boost::uint8_t expectedType, MIHTLVLengthParser::value_type expectedLength)
+    const
+{
+    validateType( expectedType);
     if (length() != expectedLength)
-        throw InvalidMIHPacketException("invalid length in TLV.") << " Type: " << senf::str(type());
+        throw InvalidMIHPacketException("invalid length in TLV.") << " Type: " << unsigned(type());
 }
 
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -63,7 +68,6 @@ prefix_ void senf::MIHBaseListTLVParser::maxListSize(MIHTLVLengthParser::value_t
     maxLength( maxl + senf::bytes(listSize_()));
 }
 
-
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
 // senf::MIHFIdTLVParser
 
@@ -185,10 +189,7 @@ prefix_ void senf::MIHFSrcIdTLVParser::dump(std::ostream & os)
 prefix_ void senf::MIHFSrcIdTLVParser::validate()
     const
 {
-    if (! check( 1 + senf::bytes(length_()) + length()) )
-        throw InvalidMIHPacketException("truncated TLV.") << " Type: " << senf::str(type());
-    if (type() != typeId)
-        throw InvalidMIHPacketException("invalid TLV type: ") << senf::str(type());
+    validateType( typeId);
 }
 
 
@@ -206,10 +207,7 @@ prefix_ void senf::MIHFDstIdTLVParser::dump(std::ostream & os)
 prefix_ void senf::MIHFDstIdTLVParser::validate()
     const
 {
-    if (! check( 1 + senf::bytes(length_()) + length()) )
-        throw InvalidMIHPacketException("truncated TLV.") << " Type: " << senf::str(type());
-    if (type() != typeId)
-        throw InvalidMIHPacketException("invalid TLV type: ") << senf::str(type());
+    validateType( typeId);
 }
 
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -247,9 +245,9 @@ prefix_ void senf::MIHStatusTLVParser::dump(std::ostream & os)
 prefix_ void senf::MIHStatusTLVParser::validate()
     const
 {
-    validateTL( typeId, 1);
+    validateTypeLength( typeId, 1);
     if (value() >= 4)
-        throw InvalidMIHPacketException("invalid value in MIHStatusTLV ") << senf::str(value());
+        throw InvalidMIHPacketException("invalid value in MIHStatusTLV ") << unsigned( value());
 }
 
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -278,9 +276,9 @@ prefix_ void senf::MIHRegisterReqCodeTLVParser::dump(std::ostream & os)
 prefix_ void senf::MIHRegisterReqCodeTLVParser::validate()
     const
 {
-    validateTL( typeId, 1);
+    validateTypeLength( typeId, 1);
     if (value() >= 2)
-        throw InvalidMIHPacketException("invalid value in MIHRegisterReqCodeTLV ") << senf::str(value());
+        throw InvalidMIHPacketException("invalid value in MIHRegisterReqCodeTLV ") << unsigned( value());
 }
 
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -301,7 +299,7 @@ prefix_ void senf::MIHValidTimeIntervalTLVParser::dump(std::ostream & os)
 prefix_ void senf::MIHValidTimeIntervalTLVParser::validate()
     const
 {
-    validateTL( typeId, 4);
+    validateTypeLength( typeId, 4);
 }
 
 //-/////////////////////////////////////////////////////////////////////////////////////////////////