#include <map>
#include <stdexcept>
#include <vector>
+#include <msp/core/hash.h>
#include "receiver.h"
namespace Msp {
{
virtual ~CompoundTypeDef() = default;
- virtual std::string describe() const = 0;
+ virtual std::uint64_t get_hash() 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 &);
- std::string describe() const override;
+ std::uint64_t get_hash() const override;
char *serialize(const C &, char *, char *) const override;
const char *deserialize(C &, const char *, const char *) const override;
};
BasicSerializer(const Protocol &) { }
- std::string describe() const { return get_type_signature<T>(); }
+ std::uint64_t get_hash() const { return Traits<T>::signature; }
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>(); }
+ std::uint64_t get_hash() const;
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;
+ std::uint64_t get_hash() const;
char *serialize(const A &, char *, char *) const;
const char *deserialize(A &, const char *, const char *) const;
};
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;
};
public:
Serializer(const Head &, Pointer, const Protocol &);
- std::string describe() const;
+ std::uint64_t get_hash() 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(); }
+ std::uint64_t get_hash() const { return 0; }
char *serialize(const P &, char *b, char *) const { return b; }
const char *deserialize(P &, const char *b, const char *) const { return b; }
};
virtual unsigned get_class_id() const = 0;
unsigned get_id() const { return id; }
- virtual std::string describe() const = 0;
+ virtual std::uint64_t get_hash() const = 0;
virtual const char *dispatch(ReceiverBase &, const char *, const char *) const = 0;
};
const CompoundTypeDef<P> &get_compound() const { return *compound; }
- std::string describe() const override { return compound->describe(); }
+ std::uint64_t get_hash() const override { return compound->get_hash(); }
char *serialize(const P &, char *, char *) const;
const char *deserialize(P &, const char *, const char *) const;
const char *dispatch(ReceiverBase &, const char *, const char *) const override;
std::size_t dispatch(ReceiverBase &, const char *, std::size_t) const;
std::uint64_t 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 std::uint16_t sig = Traits<T>::signature;
- std::string result;
- result += sig&0xFF;
- if(sig>=0x100)
- result += '0'+(sig>>8);
- return result;
-}
-
template<typename T, std::uint8_t K>
struct Protocol::BasicTraits
{ }
template<typename C, typename S>
-std::string Protocol::CompoundDef<C, S>::describe() const
+std::uint64_t Protocol::CompoundDef<C, S>::get_hash() const
{
- return "{"+serializer.describe()+"}";
+ return hash_round<64>(serializer.get_hash(), 'C');
}
template<typename C, typename S>
}
+inline std::uint64_t Protocol::StringSerializer::get_hash() const
+{
+ return Traits<std::string>::signature;
+}
+
+
template<typename A>
Protocol::ArraySerializer<A>::ArraySerializer(const Protocol &proto):
length_serializer(proto),
{ }
template<typename A>
-std::string Protocol::ArraySerializer<A>::describe() const
+std::uint64_t Protocol::ArraySerializer<A>::get_hash() const
{
- return "["+element_serializer.describe()+"]";
+ return hash_round<64>(element_serializer.get_hash(), 'A');
}
template<typename A>
{ }
template<typename P, typename Head, typename S>
-std::string Protocol::Serializer<P, Head, S>::describe() const
+std::uint64_t Protocol::Serializer<P, Head, S>::get_hash() const
{
- return Head::describe()+ser.describe();
+ return hash_update<64>(Head::get_hash(), ser.get_hash());
}
template<typename P, typename Head, typename S>