X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnet%2Fprotocol.h;h=e078caff57ac8569d36a1fd24b3e5e1f2686f8fe;hb=c0b73c437d75a6fbf111969ea67c1d24586dbde7;hp=05ea60e2f13232305a0ca18c9b50850db25e013c;hpb=8248f2912454229f4ded72b8fb4db3e76ea3ad15;p=libs%2Fnet.git diff --git a/source/net/protocol.h b/source/net/protocol.h index 05ea60e..e078caf 100644 --- a/source/net/protocol.h +++ b/source/net/protocol.h @@ -256,10 +256,10 @@ protected: public: template - unsigned serialize(const P &, char *, unsigned) const; + std::size_t serialize(const P &, char *, std::size_t) const; - unsigned get_packet_size(const char *, unsigned) const; - unsigned dispatch(ReceiverBase &, const char *, unsigned) const; + std::size_t get_packet_size(const char *, std::size_t) const; + std::size_t dispatch(ReceiverBase &, const char *, std::size_t) const; UInt64 get_hash() const; @@ -291,9 +291,11 @@ const Protocol::PacketTypeDef

&Protocol::get_packet_by_class() const } template -unsigned Protocol::serialize(const P &pkt, char *buf, unsigned size) const +std::size_t Protocol::serialize(const P &pkt, char *buf, std::size_t size) const { const PacketTypeDef

&pdef = get_packet_by_class

(); + 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); @@ -326,6 +328,7 @@ struct Protocol::Traits typedef CompoundSerializer Serializer; }; +template<> struct Protocol::Traits: BasicTraits { }; template<> struct Protocol::Traits: BasicTraits { }; template<> struct Protocol::Traits: BasicTraits { }; template<> struct Protocol::Traits: BasicTraits { };