{
virtual ~CompoundTypeDef() { }
+ virtual std::string describe() const = 0;
virtual char *serialize(const C &, char *, char *) const = 0;
virtual const char *deserialize(C &, const char *, const char *) const = 0;
};
CompoundDef(const S &);
virtual ~CompoundDef();
+ virtual std::string describe() const;
virtual char *serialize(const C &, char *, char *) const;
virtual const char *deserialize(C &, const char *, const char *) const;
};
BasicSerializer(const Protocol &) { }
+ std::string describe() const { return get_type_signature<T>(); }
char *serialize(const T &, char *, char *) const;
const char *deserialize(T &, const char *, const char *) const;
};
public:
StringSerializer(const Protocol &);
+ std::string describe() const { return get_type_signature<std::string>(); }
char *serialize(const std::string &, char *, char *) const;
const char *deserialize(std::string &, const char *, const char *) const;
};
public:
ArraySerializer(const Protocol &);
+ std::string describe() const;
char *serialize(const A &, char *, char *) const;
const char *deserialize(A &, const char *, const char *) const;
};
public:
Serializer(const Head &, Pointer, const Protocol &);
+ std::string describe() const;
char *serialize(const P &, char *, char *) const;
const char *deserialize(P &, const char *, const char *) const;
};
typedef Serializer<P, NullSerializer, typename Traits<N>::Serializer> Type;
};
+ std::string describe() const { return std::string(); }
char *serialize(const P &, char *b, char *) const { return b; }
const char *deserialize(P &, const char *b, const char *) const { return b; }
};
virtual ~PacketDefBase() { }
virtual unsigned get_class_id() const = 0;
unsigned get_id() const { return id; }
+ virtual std::string describe() const = 0;
virtual const char *dispatch(ReceiverBase &, const char *, const char *) const = 0;
};
const CompoundTypeDef<P> &get_compound() const { return *compound; }
+ virtual std::string describe() const;
char *serialize(const P &, char *, char *) const;
const char *deserialize(P &, const char *, const char *) const;
virtual const char *dispatch(ReceiverBase &, const char *, const char *) const;
unsigned get_packet_size(const char *, unsigned) const;
unsigned dispatch(ReceiverBase &, const char *, unsigned) const;
- unsigned get_hash() const;
+ UInt64 get_hash() const;
+
+private:
+ template<typename T>
+ static std::string get_type_signature();
};
return size;
}
+template<typename T>
+std::string Protocol::get_type_signature()
+{
+ const UInt16 sig = Traits<T>::signature;
+ std::string result;
+ result += sig&0xFF;
+ if(sig>=0x100)
+ result += '0'+(sig>>8);
+ return result;
+}
+
template<typename T, UInt8 K>
struct Protocol::BasicTraits
{
+ static const UInt16 signature = K | (sizeof(T)<<8);
typedef BasicSerializer<T> Serializer;
};
-template<> struct Protocol::Traits<Int8>: BasicTraits<Int8> { };
-template<> struct Protocol::Traits<UInt8>: BasicTraits<UInt8> { };
-template<> struct Protocol::Traits<Int16>: BasicTraits<Int16> { };
-template<> struct Protocol::Traits<UInt16>: BasicTraits<UInt16> { };
-template<> struct Protocol::Traits<Int32>: BasicTraits<Int32> { };
-template<> struct Protocol::Traits<UInt32>: BasicTraits<UInt32> { };
-template<> struct Protocol::Traits<Int64>: BasicTraits<Int64> { };
-template<> struct Protocol::Traits<UInt64>: BasicTraits<UInt64> { };
-template<> struct Protocol::Traits<float>: BasicTraits<float> { };
-template<> struct Protocol::Traits<double>: BasicTraits<double> { };
+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<> struct Protocol::Traits<UInt16>: BasicTraits<UInt16, 'U'> { };
+template<> struct Protocol::Traits<Int32>: BasicTraits<Int32, 'I'> { };
+template<> struct Protocol::Traits<UInt32>: BasicTraits<UInt32, 'U'> { };
+template<> struct Protocol::Traits<Int64>: BasicTraits<Int64, 'I'> { };
+template<> struct Protocol::Traits<UInt64>: BasicTraits<UInt64, 'U'> { };
+template<> struct Protocol::Traits<float>: BasicTraits<float, 'F'> { };
+template<> struct Protocol::Traits<double>: BasicTraits<double, 'F'> { };
template<> struct Protocol::Traits<std::string>
{
+ static const UInt16 signature = 'S';
typedef StringSerializer Serializer;
};
template<typename T>
struct Protocol::Traits<std::vector<T> >
{
+ static const UInt16 signature = 'A';
typedef ArraySerializer<std::vector<T> > Serializer;
};
delete serializer;
}
+template<typename C, typename S>
+std::string Protocol::CompoundDef<C, S>::describe() const
+{
+ return "{"+serializer->describe()+"}";
+}
+
template<typename C, typename S>
char *Protocol::CompoundDef<C, S>::serialize(const C &com, char *buf, char *end) const
{
element_serializer(proto)
{ }
+template<typename A>
+std::string Protocol::ArraySerializer<A>::describe() const
+{
+ return "["+element_serializer.describe()+"]";
+}
+
template<typename A>
char *Protocol::ArraySerializer<A>::serialize(const A &array, char *buf, char *end) const
{
ser(proto)
{ }
+template<typename P, typename Head, typename S>
+std::string Protocol::Serializer<P, Head, S>::describe() const
+{
+ return Head::describe()+ser.describe();
+}
+
template<typename P, typename Head, typename S>
char * Protocol::Serializer<P, Head, S>::serialize(const P &pkt, char *buf, char *end) const
{
compound = new CompoundDef<P, S>(ser);
}
+template<typename P>
+std::string Protocol::PacketTypeDef<P>::describe() const
+{
+ return compound->describe();
+}
+
template<typename P>
char *Protocol::PacketTypeDef<P>::serialize(const P &pkt, char *buf, char *end) const
{