X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=blobdiff_plain;f=source%2Fnet%2Fprotocol.h;h=0a8110c9518182f91ada3cfe48f0f09ecd579b98;hp=f722a76c82a7cc73b83d4880b7ac8043f45bd889;hb=c2d202f9b482be7b439436970d6366c369837107;hpb=93fc08266f938c667df869ae4fee77a584004af1 diff --git a/source/net/protocol.h b/source/net/protocol.h index f722a76..0a8110c 100644 --- a/source/net/protocol.h +++ b/source/net/protocol.h @@ -105,6 +105,23 @@ private: const char *deserialize(A &, const char *, const char *) const; }; + template + class CompoundSerializer + { + public: + typedef C ValueType; + + private: + const CompoundTypeDef &def; + + public: + CompoundSerializer(const Protocol &); + + std::string describe() const { return def.describe(); } + char *serialize(const C &, char *, char *) const; + const char *deserialize(C &, const char *, const char *) const; + }; + template class Serializer: public Head { @@ -226,6 +243,9 @@ private: void add_packet(PacketDefBase *); protected: + template + PacketDefBuilder > add(unsigned); + template PacketDefBuilder > add(); @@ -251,13 +271,19 @@ private: template -Protocol::PacketDefBuilder > Protocol::add() +Protocol::PacketDefBuilder > Protocol::add(unsigned id) { - PacketTypeDef

*pdef = new PacketTypeDef

(next_packet_id++); + PacketTypeDef

*pdef = new PacketTypeDef

(id); add_packet(pdef); return PacketDefBuilder >(*this, *pdef, NullSerializer

()); } +template +Protocol::PacketDefBuilder > Protocol::add() +{ + return add

(next_packet_id++); +} + template const Protocol::PacketTypeDef

&Protocol::get_packet_by_class() const { @@ -294,6 +320,13 @@ struct Protocol::BasicTraits typedef BasicSerializer Serializer; }; +template +struct Protocol::Traits +{ + static const UInt16 signature = 'C'; + typedef CompoundSerializer Serializer; +}; + template<> struct Protocol::Traits: BasicTraits { }; template<> struct Protocol::Traits: BasicTraits { }; template<> struct Protocol::Traits: BasicTraits { }; @@ -383,6 +416,24 @@ const char *Protocol::ArraySerializer::deserialize(A &array, const char *buf, } +template +Protocol::CompoundSerializer::CompoundSerializer(const Protocol &proto): + def(proto.get_packet_by_class().get_compound()) +{ } + +template +char *Protocol::CompoundSerializer::serialize(const C &com, char *buf, char *end) const +{ + return def.serialize(com, buf, end); +} + +template +const char *Protocol::CompoundSerializer::deserialize(C &com, const char *buf, const char *end) const +{ + return def.deserialize(com, buf, end); +} + + template Protocol::Serializer::Serializer(const Head &h, Pointer p, const Protocol &proto): Head(h),