mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-04 22:11:18 +12:00
GCC build
This commit is contained in:
parent
be0f062de8
commit
c8c9fad128
48 changed files with 327 additions and 273 deletions
|
@ -11,97 +11,6 @@ public:
|
|||
template<typename T> T readBE();
|
||||
template<typename T> T readLE();
|
||||
|
||||
template<> uint8 readBE()
|
||||
{
|
||||
if (!reserveReadLength(sizeof(uint8)))
|
||||
return 0;
|
||||
uint8 v = m_data[m_cursorPos];
|
||||
m_cursorPos += sizeof(uint8);
|
||||
return v;
|
||||
}
|
||||
|
||||
template<> uint16 readBE()
|
||||
{
|
||||
if (!reserveReadLength(sizeof(uint16)))
|
||||
return 0;
|
||||
const uint8* p = m_data + m_cursorPos;
|
||||
uint16 v;
|
||||
std::memcpy(&v, p, sizeof(v));
|
||||
v = _BE(v);
|
||||
m_cursorPos += sizeof(uint16);
|
||||
return v;
|
||||
}
|
||||
|
||||
template<> uint32 readBE()
|
||||
{
|
||||
if (!reserveReadLength(sizeof(uint32)))
|
||||
return 0;
|
||||
const uint8* p = m_data + m_cursorPos;
|
||||
uint32 v;
|
||||
std::memcpy(&v, p, sizeof(v));
|
||||
v = _BE(v);
|
||||
m_cursorPos += sizeof(uint32);
|
||||
return v;
|
||||
}
|
||||
|
||||
template<> uint64 readBE()
|
||||
{
|
||||
if (!reserveReadLength(sizeof(uint64)))
|
||||
return 0;
|
||||
const uint8* p = m_data + m_cursorPos;
|
||||
uint64 v;
|
||||
std::memcpy(&v, p, sizeof(v));
|
||||
v = _BE(v);
|
||||
m_cursorPos += sizeof(uint64);
|
||||
return v;
|
||||
}
|
||||
|
||||
template<> std::string readBE()
|
||||
{
|
||||
std::string s;
|
||||
uint32 stringSize = readBE<uint32>();
|
||||
if (hasError())
|
||||
return s;
|
||||
if (stringSize >= (32 * 1024 * 1024))
|
||||
{
|
||||
// out of bounds read or suspiciously large string
|
||||
m_hasError = true;
|
||||
return std::string();
|
||||
}
|
||||
s.resize(stringSize);
|
||||
readData(s.data(), stringSize);
|
||||
return s;
|
||||
}
|
||||
|
||||
template<> uint8 readLE()
|
||||
{
|
||||
return readBE<uint8>();
|
||||
}
|
||||
|
||||
template<> uint32 readLE()
|
||||
{
|
||||
if (!reserveReadLength(sizeof(uint32)))
|
||||
return 0;
|
||||
const uint8* p = m_data + m_cursorPos;
|
||||
uint32 v;
|
||||
std::memcpy(&v, p, sizeof(v));
|
||||
v = _LE(v);
|
||||
m_cursorPos += sizeof(uint32);
|
||||
return v;
|
||||
}
|
||||
|
||||
template<> uint64 readLE()
|
||||
{
|
||||
if (!reserveReadLength(sizeof(uint64)))
|
||||
return 0;
|
||||
const uint8* p = m_data + m_cursorPos;
|
||||
uint64 v;
|
||||
std::memcpy(&v, p, sizeof(v));
|
||||
v = _LE(v);
|
||||
m_cursorPos += sizeof(uint64);
|
||||
return v;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::vector<T> readPODVector()
|
||||
{
|
||||
|
@ -224,6 +133,7 @@ private:
|
|||
bool m_hasError{ false };
|
||||
};
|
||||
|
||||
|
||||
class MemStreamWriter
|
||||
{
|
||||
public:
|
||||
|
@ -243,67 +153,8 @@ public:
|
|||
}
|
||||
|
||||
template<typename T> void writeBE(const T& v);
|
||||
|
||||
template<>
|
||||
void writeBE<uint64>(const uint64& v)
|
||||
{
|
||||
m_buffer.resize(m_buffer.size() + 8);
|
||||
uint8* p = m_buffer.data() + m_buffer.size() - 8;
|
||||
uint64 tmp = _BE(v);
|
||||
std::memcpy(p, &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
template<>
|
||||
void writeBE<uint32>(const uint32& v)
|
||||
{
|
||||
m_buffer.resize(m_buffer.size() + 4);
|
||||
uint8* p = m_buffer.data() + m_buffer.size() - 4;
|
||||
uint32 tmp = _BE(v);
|
||||
std::memcpy(p, &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
template<>
|
||||
void writeBE<uint16>(const uint16& v)
|
||||
{
|
||||
m_buffer.resize(m_buffer.size() + 2);
|
||||
uint8* p = m_buffer.data() + m_buffer.size() - 2;
|
||||
uint16 tmp = _BE(v);
|
||||
std::memcpy(p, &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
template<>
|
||||
void writeBE<uint8>(const uint8& v)
|
||||
{
|
||||
m_buffer.emplace_back(v);
|
||||
}
|
||||
|
||||
template<>
|
||||
void writeBE<std::string>(const std::string& v)
|
||||
{
|
||||
writeBE<uint32>((uint32)v.size());
|
||||
writeData(v.data(), v.size());
|
||||
}
|
||||
|
||||
template<typename T> void writeLE(const T& v);
|
||||
|
||||
template<>
|
||||
void writeLE<uint64>(const uint64& v)
|
||||
{
|
||||
m_buffer.resize(m_buffer.size() + 8);
|
||||
uint8* p = m_buffer.data() + m_buffer.size() - 8;
|
||||
uint64 tmp = _LE(v);
|
||||
std::memcpy(p, &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
template<>
|
||||
void writeLE<uint32>(const uint32& v)
|
||||
{
|
||||
m_buffer.resize(m_buffer.size() + 4);
|
||||
uint8* p = m_buffer.data() + m_buffer.size() - 4;
|
||||
uint32 tmp = _LE(v);
|
||||
std::memcpy(p, &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void writePODVector(const std::vector<T>& v)
|
||||
{
|
||||
|
@ -328,6 +179,7 @@ private:
|
|||
std::vector<uint8> m_buffer;
|
||||
};
|
||||
|
||||
|
||||
class SerializerHelper
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue