[*] Made AuMemoryViewRead/Writes to bytebuffer less ambiguous

This commit is contained in:
Reece Wilson 2024-07-19 08:24:51 +01:00
parent 2d2523e679
commit 1fb355520e
2 changed files with 33 additions and 20 deletions

View File

@ -375,16 +375,6 @@ namespace Aurora::Memory
inline auline AuUInt Write(const void *buffer, AuUInt requestLength);
inline auline AuUInt Read(void *out, AuUInt requestedLength, bool peek = false);
inline auline AuUInt Write(const MemoryViewRead &read)
{
return Write(read.ptr, read.length);
}
inline auline AuUInt Read(const MemoryViewWrite &write)
{
return Read(write.ptr, write.length);
}
// String API
inline bool WriteString(AuROString string, EStringType type = EStringType::eStringDword, Locale::ECodePage codepage = Locale::ECodePage::eUTF8);
@ -411,13 +401,24 @@ namespace Aurora::Memory
T ReadChecked();
template<typename T>
bool Write(const T &in);
using ReadHack_t = AuConditional_t<AuIsSame_v<MemoryViewWrite, T>, AuUInt, bool>;
template<typename T>
bool Write(T &in);
using WriteHack_t = AuConditional_t<AuIsSame_v<MemoryViewRead, T>, AuUInt, bool>;
template<typename T>
bool Read(T &out);
WriteHack_t<T> Write(const T &in);
template<typename T>
WriteHack_t<T> Write(T &in);
template<typename T>
ReadHack_t<T> Read(T &out);
inline auline AuUInt Read(const MemoryViewWrite &write)
{
return Read(write.ptr, write.length);
}
template<typename T>
bool WriteTagged(const T &in);

View File

@ -150,11 +150,15 @@ namespace Aurora::Memory
}
template<typename T>
bool ByteBuffer::Read(T &out)
ByteBuffer::ReadHack_t<T> ByteBuffer::Read(T &out)
{
if constexpr (AuIsClass_v<T>)
{
if constexpr (__detail::AuHasDeserializeBool<AuRemoveReference_t<T>>::type::value)
if constexpr (AuIsSame_v<T, MemoryViewWrite>)
{
return Read(out.ptr, out.length);
}
else if constexpr (__detail::AuHasDeserializeBool<AuRemoveReference_t<T>>::type::value)
{
if (!out.Deserialize(*this))
{
@ -331,12 +335,16 @@ namespace Aurora::Memory
}
template<typename T>
bool ByteBuffer::Write(T &in)
ByteBuffer::WriteHack_t<T> ByteBuffer::Write(T &in)
{
if constexpr (AuIsClass_v<T>)
{
if constexpr (__detail::AuHasSerializeBool<AuRemoveReference_t<T>>::type::value ||
__detail::AuHasSerializeBool2<AuRemoveReference_t<T>>::type::value)
if constexpr (AuIsSame_v<T, MemoryViewRead>)
{
return Write(in.ptr, in.length);
}
else if constexpr (__detail::AuHasSerializeBool<AuRemoveReference_t<T>>::type::value ||
__detail::AuHasSerializeBool2<AuRemoveReference_t<T>>::type::value)
{
if (!in.Serialize(*this))
{
@ -366,11 +374,15 @@ namespace Aurora::Memory
}
template<typename T>
bool ByteBuffer::Write(const T &in)
ByteBuffer::WriteHack_t<T> ByteBuffer::Write(const T &in)
{
if constexpr (AuIsClass_v<T>)
{
if constexpr (__detail::AuHasSerializeBool2<AuRemoveReference_t<T>>::type::value)
if constexpr (AuIsSame_v<T, MemoryViewRead>)
{
return Write(in.ptr, in.length);
}
else if constexpr (__detail::AuHasSerializeBool2<AuRemoveReference_t<T>>::type::value)
{
if (!in.Serialize(*this))
{