Implement NetworkMessage endianness

This commit is contained in:
DankParrot 2020-07-31 18:10:43 -07:00
parent a53140890d
commit 1667740c23
1 changed files with 13 additions and 6 deletions

View File

@ -1,5 +1,7 @@
#pragma once
#include "util/ByteUtil.h"
#include <cstdint>
#include <cstring>
#include <vector>
@ -29,11 +31,19 @@ namespace Feather
std::memcpy(&m_data[offset], data, size);
}
template <typename T>
// Writes a value, converting to big endian by default
template <typename T, Endian asEndian = Endian::Big>
inline void Write(const T& value)
{
// Todo: Endian-ness
WriteData(&value, sizeof(T));
if constexpr (asEndian == Endian::Big && sizeof(T) > 1)
{
T valueReversed = ReverseBytes<T>(value);
WriteData(&valueReversed, sizeof(T));
}
else
{
WriteData(&value, sizeof(T));
}
}
inline void WriteVarInt(int32_t value)
@ -63,9 +73,6 @@ namespace Feather
#endif
}
// Inlining and 'final' should ideally avert vtable lookups
// TOOD: Make these separate functions if vtable is not averted
inline const uint8_t* GetData() const
{
#ifdef _DEBUG