const char *deserialize(A &, const char *, const char *) const;
};
+ template<typename C>
+ class CompoundSerializer
+ {
+ public:
+ typedef C ValueType;
+
+ private:
+ const CompoundTypeDef<C> &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<typename P, typename Head, typename S>
class Serializer: public Head
{
void add_packet(PacketDefBase *);
protected:
+ template<typename P>
+ PacketDefBuilder<P, NullSerializer<P> > add(unsigned);
+
template<typename P>
PacketDefBuilder<P, NullSerializer<P> > add();
template<typename P>
-Protocol::PacketDefBuilder<P, Protocol::NullSerializer<P> > Protocol::add()
+Protocol::PacketDefBuilder<P, Protocol::NullSerializer<P> > Protocol::add(unsigned id)
{
- PacketTypeDef<P> *pdef = new PacketTypeDef<P>(next_packet_id++);
+ PacketTypeDef<P> *pdef = new PacketTypeDef<P>(id);
add_packet(pdef);
return PacketDefBuilder<P, NullSerializer<P> >(*this, *pdef, NullSerializer<P>());
}
+template<typename P>
+Protocol::PacketDefBuilder<P, Protocol::NullSerializer<P> > Protocol::add()
+{
+ return add<P>(next_packet_id++);
+}
+
template<typename P>
const Protocol::PacketTypeDef<P> &Protocol::get_packet_by_class() const
{
typedef BasicSerializer<T> Serializer;
};
+template<typename T>
+struct Protocol::Traits
+{
+ static const UInt16 signature = 'C';
+ typedef CompoundSerializer<T> Serializer;
+};
+
template<> struct Protocol::Traits<Int8>: BasicTraits<Int8, 'I'> { };
template<> struct Protocol::Traits<UInt8>: BasicTraits<UInt8, 'U'> { };
template<> struct Protocol::Traits<Int16>: BasicTraits<Int16, 'I'> { };
}
+template<typename C>
+Protocol::CompoundSerializer<C>::CompoundSerializer(const Protocol &proto):
+ def(proto.get_packet_by_class<C>().get_compound())
+{ }
+
+template<typename C>
+char *Protocol::CompoundSerializer<C>::serialize(const C &com, char *buf, char *end) const
+{
+ return def.serialize(com, buf, end);
+}
+
+template<typename C>
+const char *Protocol::CompoundSerializer<C>::deserialize(C &com, const char *buf, const char *end) const
+{
+ return def.deserialize(com, buf, end);
+}
+
+
template<typename P, typename Head, typename S>
Protocol::Serializer<P, Head, S>::Serializer(const Head &h, Pointer p, const Protocol &proto):
Head(h),