class BasicSerializer
{
public:
- typedef T ValueType;
-
BasicSerializer(const Protocol &) { }
std::uint64_t get_hash() const { return Traits<T>::signature; }
class StringSerializer
{
- public:
- typedef std::string ValueType;
-
private:
BasicSerializer<std::uint16_t> length_serializer;
template<typename A>
class ArraySerializer
{
- public:
- typedef A ValueType;
-
private:
BasicSerializer<std::uint16_t> length_serializer;
typename Traits<typename A::value_type>::Serializer element_serializer;
template<typename C>
class CompoundSerializer
{
- public:
- typedef C ValueType;
-
private:
const Serializer<C> &serializer;
const char *deserialize(C &, const char *, const char *) const;
};
- template<typename C, typename Head, typename S>
+ template<typename C, typename Head, typename T>
class FieldSerializer: public Head
{
public:
template<typename N>
- struct Next
- {
- typedef FieldSerializer<C, FieldSerializer<C, Head, S>, typename Traits<N>::Serializer> Type;
- };
+ using Next = FieldSerializer<C, FieldSerializer<C, Head, T>, N>;
private:
- typedef typename S::ValueType C::*Pointer;
-
- Pointer ptr;
- S ser;
+ T C::*ptr;
+ typename Traits<T>::Serializer ser;
public:
- FieldSerializer(const Head &, Pointer, const Protocol &);
+ FieldSerializer(const Head &, T C::*, const Protocol &);
std::uint64_t get_hash() const;
char *serialize(const C &, char *, char *) const;
{
public:
template<typename N>
- struct Next
- {
- typedef FieldSerializer<C, Serializer<C>, typename Traits<N>::Serializer> Type;
- };
+ using Next = FieldSerializer<C, Serializer<C>, N>;
virtual ~Serializer() = default;
PacketDefBuilder(const Protocol &, PacketTypeDef<P> &, const S &);
template<typename T>
- PacketDefBuilder<P, typename S::template Next<T>::Type> operator()(T P::*);
+ PacketDefBuilder<P, typename S::template Next<T>> operator()(T P::*);
};
struct PacketHeader
}
-template<typename P, typename Head, typename S>
-Protocol::FieldSerializer<P, Head, S>::FieldSerializer(const Head &h, Pointer p, const Protocol &proto):
+template<typename C, typename Head, typename T>
+Protocol::FieldSerializer<C, Head, T>::FieldSerializer(const Head &h, T C::*p, const Protocol &proto):
Head(h),
ptr(p),
ser(proto)
{ }
-template<typename P, typename Head, typename S>
-std::uint64_t Protocol::FieldSerializer<P, Head, S>::get_hash() const
+template<typename C, typename Head, typename T>
+std::uint64_t Protocol::FieldSerializer<C, Head, T>::get_hash() const
{
return hash_update<64>(Head::get_hash(), ser.get_hash());
}
-template<typename P, typename Head, typename S>
-char *Protocol::FieldSerializer<P, Head, S>::serialize(const P &pkt, char *buf, char *end) const
+template<typename C, typename Head, typename T>
+char *Protocol::FieldSerializer<C, Head, T>::serialize(const C &com, char *buf, char *end) const
{
- buf = Head::serialize(pkt, buf, end);
- return ser.serialize(pkt.*ptr, buf, end);
+ buf = Head::serialize(com, buf, end);
+ return ser.serialize(com.*ptr, buf, end);
}
-template<typename P, typename Head, typename S>
-const char *Protocol::FieldSerializer<P, Head, S>::deserialize(P &pkt, const char *buf, const char *end) const
+template<typename C, typename Head, typename T>
+const char *Protocol::FieldSerializer<C, Head, T>::deserialize(C &com, const char *buf, const char *end) const
{
- buf = Head::deserialize(pkt, buf, end);
- return ser.deserialize(pkt.*ptr, buf, end);
+ buf = Head::deserialize(com, buf, end);
+ return ser.deserialize(com.*ptr, buf, end);
}
template<typename P, typename S>
template<typename T>
-Protocol::PacketDefBuilder<P, typename S::template Next<T>::Type> Protocol::PacketDefBuilder<P, S>::operator()(T P::*ptr)
+Protocol::PacketDefBuilder<P, typename S::template Next<T>> Protocol::PacketDefBuilder<P, S>::operator()(T P::*ptr)
{
- typename S::template Next<T>::Type next_ser(serializer, ptr, protocol);
+ typename S::template Next<T> next_ser(serializer, ptr, protocol);
pktdef.set_serializer(next_ser);
- return PacketDefBuilder<P, typename S::template Next<T>::Type>(protocol, pktdef, next_ser);
+ return PacketDefBuilder<P, typename S::template Next<T>>(protocol, pktdef, next_ser);
}
} // namespace Net