Add 64 bit serialisation support.

This commit is contained in:
Matt 2019-01-02 05:18:36 +01:00
parent fafd2081e3
commit a8254aa292
2 changed files with 20 additions and 1 deletions

View File

@ -51,7 +51,7 @@ template<typename T> struct DataSerializerTraitsIntegral
else if constexpr (sizeof(T) == 4)
snprintf(temp, sizeof(temp), "%08X", val);
else if constexpr (sizeof(T) == 8)
snprintf(temp, sizeof(temp), "%16X", val);
snprintf(temp, sizeof(temp), "%016llX", val);
else
static_assert("Invalid size");
@ -102,6 +102,14 @@ template<> struct DataSerializerTraits<int32_t> : public DataSerializerTraitsInt
{
};
template<> struct DataSerializerTraits<uint64_t> : public DataSerializerTraitsIntegral<uint64_t>
{
};
template<> struct DataSerializerTraits<int64_t> : public DataSerializerTraitsIntegral<int64_t>
{
};
template<> struct DataSerializerTraits<std::string>
{
static void encode(IStream* stream, const std::string& str)

View File

@ -39,6 +39,17 @@ template<> struct ByteSwapT<4>
}
};
template<> struct ByteSwapT<8>
{
static uint64_t SwapBE(uint64_t value)
{
value = (value & 0x00000000FFFFFFFF) << 32 | (value & 0xFFFFFFFF00000000) >> 32;
value = (value & 0x0000FFFF0000FFFF) << 16 | (value & 0xFFFF0000FFFF0000) >> 16;
value = (value & 0x00FF00FF00FF00FF) << 8 | (value & 0xFF00FF00FF00FF00) >> 8;
return value;
}
};
template<typename T> static T ByteSwapBE(const T& value)
{
return ByteSwapT<sizeof(T)>::SwapBE(value);