]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/protocol.cpp
Support compound types in network packets
[libs/net.git] / source / net / protocol.cpp
index d862ed82f72a37d7416160307dac7b7069d749bf..b24cef1f5e3f03ef067711271480c2eb1ab378cb 100644 (file)
@@ -1,12 +1,13 @@
 #include <cstring>
 #include <string>
+#include <msp/core/hash.h>
 #include <msp/core/maputils.h>
+#include <msp/strings/format.h>
 #include <msp/strings/lexicalcast.h>
 #include "protocol.h"
 
 using namespace std;
 
-
 namespace Msp {
 namespace Net {
 
@@ -28,9 +29,13 @@ void Protocol::add_packet(PacketDefBase *pdef)
 {
        PacketDefBase *&ptr = packet_class_defs[pdef->get_class_id()];
        if(ptr)
+       {
+               packet_id_defs.erase(ptr->get_id());
                delete ptr;
+       }
        ptr = pdef;
-       packet_id_defs[pdef->get_id()] = pdef;
+       if(unsigned id = pdef->get_id())
+               packet_id_defs[id] = pdef;
 }
 
 const Protocol::PacketDefBase &Protocol::get_packet_by_class_id(unsigned id) const
@@ -63,10 +68,12 @@ unsigned Protocol::get_packet_size(const char *buf, unsigned size) const
        return header.length;
 }
 
-unsigned Protocol::get_hash() const
+UInt64 Protocol::get_hash() const
 {
-       // TODO
-       return 123;
+       string description;
+       for(PacketMap::const_iterator i=packet_id_defs.begin(); i!=packet_id_defs.end(); ++i)
+               description += format("%d:%s\n", i->first, i->second->describe());
+       return hash64(description);
 }