From: Mikko Rasa Date: Fri, 9 Dec 2022 16:48:23 +0000 (+0200) Subject: Use standard fixed-width integer types X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2fbfce0c327c852d33c6713af646abf07b241108;p=libs%2Fnet.git Use standard fixed-width integer types --- diff --git a/source/net/communicator.cpp b/source/net/communicator.cpp index 07a8494..c473d53 100644 --- a/source/net/communicator.cpp +++ b/source/net/communicator.cpp @@ -11,7 +11,7 @@ using namespace Msp::Net; struct Handshake { - Msp::UInt64 hash; + uint64_t hash; }; @@ -31,11 +31,11 @@ HandshakeProtocol::HandshakeProtocol(): class HandshakeReceiver: public PacketReceiver { private: - Msp::UInt64 hash; + uint64_t hash; public: HandshakeReceiver(); - Msp::UInt64 get_hash() const { return hash; } + uint64_t get_hash() const { return hash; } virtual void receive(const Handshake &); }; diff --git a/source/net/protocol.cpp b/source/net/protocol.cpp index 1be2402..17e4310 100644 --- a/source/net/protocol.cpp +++ b/source/net/protocol.cpp @@ -69,7 +69,7 @@ size_t Protocol::get_packet_size(const char *buf, size_t size) const 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) @@ -107,25 +107,25 @@ const char *Protocol::BasicSerializer::deserialize(T &value, const char *buf, } template char *Protocol::BasicSerializer::serialize(const bool &, char *, char *) const; -template char *Protocol::BasicSerializer::serialize(const Int8 &, char *, char *) const; -template char *Protocol::BasicSerializer::serialize(const Int16 &, char *, char *) const; -template char *Protocol::BasicSerializer::serialize(const Int32 &, char *, char *) const; -template char *Protocol::BasicSerializer::serialize(const Int64 &, char *, char *) const; -template char *Protocol::BasicSerializer::serialize(const UInt8 &, char *, char *) const; -template char *Protocol::BasicSerializer::serialize(const UInt16 &, char *, char *) const; -template char *Protocol::BasicSerializer::serialize(const UInt32 &, char *, char *) const; -template char *Protocol::BasicSerializer::serialize(const UInt64 &, char *, char *) const; +template char *Protocol::BasicSerializer::serialize(const int8_t &, char *, char *) const; +template char *Protocol::BasicSerializer::serialize(const int16_t &, char *, char *) const; +template char *Protocol::BasicSerializer::serialize(const int32_t &, char *, char *) const; +template char *Protocol::BasicSerializer::serialize(const int64_t &, char *, char *) const; +template char *Protocol::BasicSerializer::serialize(const uint8_t &, char *, char *) const; +template char *Protocol::BasicSerializer::serialize(const uint16_t &, char *, char *) const; +template char *Protocol::BasicSerializer::serialize(const uint32_t &, char *, char *) const; +template char *Protocol::BasicSerializer::serialize(const uint64_t &, char *, char *) const; template char *Protocol::BasicSerializer::serialize(const float &, char *, char *) const; template char *Protocol::BasicSerializer::serialize(const double &, char *, char *) const; template const char *Protocol::BasicSerializer::deserialize(bool &, const char *, const char *) const; -template const char *Protocol::BasicSerializer::deserialize(Int8 &, const char *, const char *) const; -template const char *Protocol::BasicSerializer::deserialize(Int16 &, const char *, const char *) const; -template const char *Protocol::BasicSerializer::deserialize(Int32 &, const char *, const char *) const; -template const char *Protocol::BasicSerializer::deserialize(Int64 &, const char *, const char *) const; -template const char *Protocol::BasicSerializer::deserialize(UInt8 &, const char *, const char *) const; -template const char *Protocol::BasicSerializer::deserialize(UInt16 &, const char *, const char *) const; -template const char *Protocol::BasicSerializer::deserialize(UInt32 &, const char *, const char *) const; -template const char *Protocol::BasicSerializer::deserialize(UInt64 &, const char *, const char *) const; +template const char *Protocol::BasicSerializer::deserialize(int8_t &, const char *, const char *) const; +template const char *Protocol::BasicSerializer::deserialize(int16_t &, const char *, const char *) const; +template const char *Protocol::BasicSerializer::deserialize(int32_t &, const char *, const char *) const; +template const char *Protocol::BasicSerializer::deserialize(int64_t &, const char *, const char *) const; +template const char *Protocol::BasicSerializer::deserialize(uint8_t &, const char *, const char *) const; +template const char *Protocol::BasicSerializer::deserialize(uint16_t &, const char *, const char *) const; +template const char *Protocol::BasicSerializer::deserialize(uint32_t &, const char *, const char *) const; +template const char *Protocol::BasicSerializer::deserialize(uint64_t &, const char *, const char *) const; template const char *Protocol::BasicSerializer::deserialize(float &, const char *, const char *) const; template const char *Protocol::BasicSerializer::deserialize(double &, const char *, const char *) const; @@ -145,7 +145,7 @@ char *Protocol::StringSerializer::serialize(const string &str, char *buf, char * 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(length)) throw buffer_error("underflow"); @@ -166,7 +166,7 @@ Protocol::PacketHeader::PacketHeader(): length(0) { } -Protocol::PacketHeader::PacketHeader(UInt16 t, UInt16 l): +Protocol::PacketHeader::PacketHeader(uint16_t t, uint16_t l): type(t), length(l) { } diff --git a/source/net/protocol.h b/source/net/protocol.h index e078caf..3457a9d 100644 --- a/source/net/protocol.h +++ b/source/net/protocol.h @@ -1,10 +1,10 @@ #ifndef MSP_NET_PROTOCOL_H_ #define MSP_NET_PROTOCOL_H_ +#include #include #include #include -#include #include "receiver.h" namespace Msp { @@ -29,7 +29,7 @@ public: class Protocol { private: - template + template struct BasicTraits; template @@ -76,7 +76,7 @@ private: typedef std::string ValueType; private: - BasicSerializer length_serializer; + BasicSerializer length_serializer; public: StringSerializer(const Protocol &); @@ -93,7 +93,7 @@ private: typedef A ValueType; private: - BasicSerializer length_serializer; + BasicSerializer length_serializer; typename Traits::Serializer element_serializer; public: @@ -219,11 +219,11 @@ private: 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 PacketMap; @@ -261,7 +261,7 @@ public: 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 @@ -305,7 +305,7 @@ std::size_t Protocol::serialize(const P &pkt, char *buf, std::size_t size) const template std::string Protocol::get_type_signature() { - const UInt16 sig = Traits::signature; + const std::uint16_t sig = Traits::signature; std::string result; result += sig&0xFF; if(sig>=0x100) @@ -314,42 +314,42 @@ std::string Protocol::get_type_signature() } -template +template struct Protocol::BasicTraits { - static const UInt16 signature = K | (sizeof(T)<<8); + static const std::uint16_t signature = K | (sizeof(T)<<8); typedef BasicSerializer Serializer; }; template struct Protocol::Traits { - static const UInt16 signature = 'C'; + static const std::uint16_t signature = 'C'; typedef CompoundSerializer Serializer; }; template<> struct Protocol::Traits: BasicTraits { }; -template<> struct Protocol::Traits: BasicTraits { }; -template<> struct Protocol::Traits: BasicTraits { }; -template<> struct Protocol::Traits: BasicTraits { }; -template<> struct Protocol::Traits: BasicTraits { }; -template<> struct Protocol::Traits: BasicTraits { }; -template<> struct Protocol::Traits: BasicTraits { }; -template<> struct Protocol::Traits: BasicTraits { }; -template<> struct Protocol::Traits: BasicTraits { }; +template<> struct Protocol::Traits: BasicTraits { }; +template<> struct Protocol::Traits: BasicTraits { }; +template<> struct Protocol::Traits: BasicTraits { }; +template<> struct Protocol::Traits: BasicTraits { }; +template<> struct Protocol::Traits: BasicTraits { }; +template<> struct Protocol::Traits: BasicTraits { }; +template<> struct Protocol::Traits: BasicTraits { }; +template<> struct Protocol::Traits: BasicTraits { }; template<> struct Protocol::Traits: BasicTraits { }; template<> struct Protocol::Traits: BasicTraits { }; template<> struct Protocol::Traits { - static const UInt16 signature = 'S'; + static const std::uint16_t signature = 'S'; typedef StringSerializer Serializer; }; template struct Protocol::Traits > { - static const UInt16 signature = 'A'; + static const std::uint16_t signature = 'A'; typedef ArraySerializer > Serializer; }; @@ -403,7 +403,7 @@ char *Protocol::ArraySerializer::serialize(const A &array, char *buf, char *e template const char *Protocol::ArraySerializer::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