return header.length;
}
-UInt64 Protocol::get_hash() const
+uint64_t Protocol::get_hash() const
{
string description;
for(PacketMap::const_iterator i=packet_id_defs.begin(); i!=packet_id_defs.end(); ++i)
}
template char *Protocol::BasicSerializer<bool>::serialize(const bool &, char *, char *) const;
-template char *Protocol::BasicSerializer<Int8>::serialize(const Int8 &, char *, char *) const;
-template char *Protocol::BasicSerializer<Int16>::serialize(const Int16 &, char *, char *) const;
-template char *Protocol::BasicSerializer<Int32>::serialize(const Int32 &, char *, char *) const;
-template char *Protocol::BasicSerializer<Int64>::serialize(const Int64 &, char *, char *) const;
-template char *Protocol::BasicSerializer<UInt8>::serialize(const UInt8 &, char *, char *) const;
-template char *Protocol::BasicSerializer<UInt16>::serialize(const UInt16 &, char *, char *) const;
-template char *Protocol::BasicSerializer<UInt32>::serialize(const UInt32 &, char *, char *) const;
-template char *Protocol::BasicSerializer<UInt64>::serialize(const UInt64 &, char *, char *) const;
+template char *Protocol::BasicSerializer<int8_t>::serialize(const int8_t &, char *, char *) const;
+template char *Protocol::BasicSerializer<int16_t>::serialize(const int16_t &, char *, char *) const;
+template char *Protocol::BasicSerializer<int32_t>::serialize(const int32_t &, char *, char *) const;
+template char *Protocol::BasicSerializer<int64_t>::serialize(const int64_t &, char *, char *) const;
+template char *Protocol::BasicSerializer<uint8_t>::serialize(const uint8_t &, char *, char *) const;
+template char *Protocol::BasicSerializer<uint16_t>::serialize(const uint16_t &, char *, char *) const;
+template char *Protocol::BasicSerializer<uint32_t>::serialize(const uint32_t &, char *, char *) const;
+template char *Protocol::BasicSerializer<uint64_t>::serialize(const uint64_t &, char *, char *) const;
template char *Protocol::BasicSerializer<float>::serialize(const float &, char *, char *) const;
template char *Protocol::BasicSerializer<double>::serialize(const double &, char *, char *) const;
template const char *Protocol::BasicSerializer<bool>::deserialize(bool &, const char *, const char *) const;
-template const char *Protocol::BasicSerializer<Int8>::deserialize(Int8 &, const char *, const char *) const;
-template const char *Protocol::BasicSerializer<Int16>::deserialize(Int16 &, const char *, const char *) const;
-template const char *Protocol::BasicSerializer<Int32>::deserialize(Int32 &, const char *, const char *) const;
-template const char *Protocol::BasicSerializer<Int64>::deserialize(Int64 &, const char *, const char *) const;
-template const char *Protocol::BasicSerializer<UInt8>::deserialize(UInt8 &, const char *, const char *) const;
-template const char *Protocol::BasicSerializer<UInt16>::deserialize(UInt16 &, const char *, const char *) const;
-template const char *Protocol::BasicSerializer<UInt32>::deserialize(UInt32 &, const char *, const char *) const;
-template const char *Protocol::BasicSerializer<UInt64>::deserialize(UInt64 &, const char *, const char *) const;
+template const char *Protocol::BasicSerializer<int8_t>::deserialize(int8_t &, const char *, const char *) const;
+template const char *Protocol::BasicSerializer<int16_t>::deserialize(int16_t &, const char *, const char *) const;
+template const char *Protocol::BasicSerializer<int32_t>::deserialize(int32_t &, const char *, const char *) const;
+template const char *Protocol::BasicSerializer<int64_t>::deserialize(int64_t &, const char *, const char *) const;
+template const char *Protocol::BasicSerializer<uint8_t>::deserialize(uint8_t &, const char *, const char *) const;
+template const char *Protocol::BasicSerializer<uint16_t>::deserialize(uint16_t &, const char *, const char *) const;
+template const char *Protocol::BasicSerializer<uint32_t>::deserialize(uint32_t &, const char *, const char *) const;
+template const char *Protocol::BasicSerializer<uint64_t>::deserialize(uint64_t &, const char *, const char *) const;
template const char *Protocol::BasicSerializer<float>::deserialize(float &, const char *, const char *) const;
template const char *Protocol::BasicSerializer<double>::deserialize(double &, const char *, const char *) const;
const char *Protocol::StringSerializer::deserialize(string &str, const char *buf, const char *end) const
{
- UInt16 length;
+ uint16_t length;
buf = length_serializer.deserialize(length, buf, end);
if(end-buf<static_cast<int>(length))
throw buffer_error("underflow");
length(0)
{ }
-Protocol::PacketHeader::PacketHeader(UInt16 t, UInt16 l):
+Protocol::PacketHeader::PacketHeader(uint16_t t, uint16_t l):
type(t),
length(l)
{ }
#ifndef MSP_NET_PROTOCOL_H_
#define MSP_NET_PROTOCOL_H_
+#include <cstdint>
#include <map>
#include <stdexcept>
#include <vector>
-#include <msp/core/inttypes.h>
#include "receiver.h"
namespace Msp {
class Protocol
{
private:
- template<typename T, UInt8 K>
+ template<typename T, std::uint8_t K>
struct BasicTraits;
template<typename T>
typedef std::string ValueType;
private:
- BasicSerializer<UInt16> length_serializer;
+ BasicSerializer<std::uint16_t> length_serializer;
public:
StringSerializer(const Protocol &);
typedef A ValueType;
private:
- BasicSerializer<UInt16> length_serializer;
+ BasicSerializer<std::uint16_t> length_serializer;
typename Traits<typename A::value_type>::Serializer element_serializer;
public:
struct PacketHeader
{
- UInt16 type;
- UInt16 length;
+ std::uint16_t type;
+ std::uint16_t length;
PacketHeader();
- PacketHeader(UInt16, UInt16);
+ PacketHeader(std::uint16_t, std::uint16_t);
};
typedef std::map<unsigned, PacketDefBase *> PacketMap;
std::size_t get_packet_size(const char *, std::size_t) const;
std::size_t dispatch(ReceiverBase &, const char *, std::size_t) const;
- UInt64 get_hash() const;
+ std::uint64_t get_hash() const;
private:
template<typename T>
template<typename T>
std::string Protocol::get_type_signature()
{
- const UInt16 sig = Traits<T>::signature;
+ const std::uint16_t sig = Traits<T>::signature;
std::string result;
result += sig&0xFF;
if(sig>=0x100)
}
-template<typename T, UInt8 K>
+template<typename T, std::uint8_t K>
struct Protocol::BasicTraits
{
- static const UInt16 signature = K | (sizeof(T)<<8);
+ static const std::uint16_t signature = K | (sizeof(T)<<8);
typedef BasicSerializer<T> Serializer;
};
template<typename T>
struct Protocol::Traits
{
- static const UInt16 signature = 'C';
+ static const std::uint16_t signature = 'C';
typedef CompoundSerializer<T> Serializer;
};
template<> struct Protocol::Traits<bool>: BasicTraits<bool, 'B'> { };
-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<std::int8_t>: BasicTraits<std::int8_t, 'I'> { };
+template<> struct Protocol::Traits<std::uint8_t>: BasicTraits<std::uint8_t, 'U'> { };
+template<> struct Protocol::Traits<std::int16_t>: BasicTraits<std::int16_t, 'I'> { };
+template<> struct Protocol::Traits<std::uint16_t>: BasicTraits<std::uint16_t, 'U'> { };
+template<> struct Protocol::Traits<std::int32_t>: BasicTraits<std::int32_t, 'I'> { };
+template<> struct Protocol::Traits<std::uint32_t>: BasicTraits<std::uint32_t, 'U'> { };
+template<> struct Protocol::Traits<std::int64_t>: BasicTraits<std::int64_t, 'I'> { };
+template<> struct Protocol::Traits<std::uint64_t>: BasicTraits<std::uint64_t, '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';
+ static const std::uint16_t signature = 'S';
typedef StringSerializer Serializer;
};
template<typename T>
struct Protocol::Traits<std::vector<T> >
{
- static const UInt16 signature = 'A';
+ static const std::uint16_t signature = 'A';
typedef ArraySerializer<std::vector<T> > Serializer;
};
template<typename A>
const char *Protocol::ArraySerializer<A>::deserialize(A &array, const char *buf, const char *end) const
{
- UInt16 length;
+ std::uint16_t length;
buf = length_serializer.deserialize(length, buf, end);
array.resize(length);
for(unsigned i=0; i<length; ++i)