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;
}
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;
};
}
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;
}