]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/protocol.cpp
Add a base id parameter to Protocol's serialization functions
[libs/net.git] / source / net / protocol.cpp
index 402b84a0633cdeb4dbe45c463e2f9676af911709..c6112923c9692db7f4b646f11d68e0a8e6e753a0 100644 (file)
@@ -1,9 +1,9 @@
+#include "protocol.h"
 #include <cstring>
 #include <string>
 #include <msp/core/maputils.h>
 #include <msp/strings/format.h>
 #include <msp/strings/lexicalcast.h>
-#include "protocol.h"
 
 using namespace std;
 
@@ -44,13 +44,13 @@ const Protocol::PacketDefBase &Protocol::get_packet_by_id(unsigned id) const
        return *get_item(packet_id_defs, id);
 }
 
-size_t Protocol::dispatch(ReceiverBase &rcv, const char *buf, size_t size) const
+size_t Protocol::dispatch(ReceiverBase &rcv, const char *buf, size_t size, unsigned base_id) const
 {
        PacketHeader header;
        const char *ptr = header_def.deserialize(header, buf, buf+size);
        if(header.length>size)
                throw bad_packet("truncated");
-       const PacketDefBase &pdef = get_packet_by_id(header.type);
+       const PacketDefBase &pdef = get_packet_by_id(header.type-base_id);
        ptr = pdef.dispatch(rcv, ptr, ptr+header.length);
        return ptr-buf;
 }