]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/protocol.h
Add a base id parameter to Protocol's serialization functions
[libs/net.git] / source / net / protocol.h
index 8068d3275ca292eea2317e9847725f90a0be7524..0721ec5b5403adebb4013e54a07358700beebecc 100644 (file)
@@ -226,10 +226,10 @@ protected:
 
 public:
        template<typename P>
-       std::size_t serialize(const P &, char *, std::size_t) const;
+       std::size_t serialize(const P &, char *, std::size_t, unsigned = 0) const;
 
        std::size_t get_packet_size(const char *, std::size_t) const;
-       std::size_t dispatch(ReceiverBase &, const char *, std::size_t) const;
+       std::size_t dispatch(ReceiverBase &, const char *, std::size_t, unsigned = 0) const;
 
        std::uint64_t get_hash() const;
 };
@@ -265,14 +265,14 @@ const Protocol::PacketTypeDef<P> &Protocol::get_packet_by_class() const
 }
 
 template<typename P>
-std::size_t Protocol::serialize(const P &pkt, char *buf, std::size_t size) const
+std::size_t Protocol::serialize(const P &pkt, char *buf, std::size_t size, unsigned base_id) const
 {
        const PacketTypeDef<P> &pdef = get_packet_by_class<P>();
        if(!pdef.get_id())
                throw std::invalid_argument("no packet id");
        char *ptr = pdef.serialize(pkt, buf+4, buf+size);
        size = ptr-buf;
-       header_def.serialize(PacketHeader(pdef.get_id(), size), buf, buf+4);
+       header_def.serialize(PacketHeader(base_id+pdef.get_id(), size), buf, buf+4);
        return size;
 }