[General] RW functions return true on success

0.6.3
Koncord 7 years ago
parent 45c7c3a0b6
commit 7639db02f3

@ -46,16 +46,17 @@ namespace mwmp
protected: protected:
template<class templateType> template<class templateType>
void RW(templateType &data, uint32_t size, bool write) bool RW(templateType &data, uint32_t size, bool write)
{ {
if (write) if (write)
bs->Write(data, size); bs->Write(data, size);
else else
bs->Read(data, size); return bs->Read(data, size);
return true;
} }
template<class templateType> template<class templateType>
void RW(templateType &data, bool write, bool compress = 0) bool RW(templateType &data, bool write, bool compress = 0)
{ {
if (write) if (write)
{ {
@ -63,28 +64,31 @@ namespace mwmp
bs->WriteCompressed(data); bs->WriteCompressed(data);
else else
bs->Write(data); bs->Write(data);
return true;
} }
else else
{ {
if (compress) if (compress)
bs->ReadCompressed(data); return bs->ReadCompressed(data);
else else
bs->Read(data); return bs->Read(data);
} }
} }
void RW(bool &data, bool write) bool RW(bool &data, bool write)
{ {
if (write) if (write)
bs->Write(data); bs->Write(data);
else else
bs->Read(data); return bs->Read(data);
return true;
} }
const static uint32_t maxStrSize = 64 * 1024; // 64 KiB const static uint32_t maxStrSize = 64 * 1024; // 64 KiB
void RW(std::string &str, bool write, bool compress = false, std::string::size_type maxSize = maxStrSize) bool RW(std::string &str, bool write, bool compress = false, std::string::size_type maxSize = maxStrSize)
{ {
bool res = true;
if (write) if (write)
{ {
if (compress) if (compress)
@ -100,13 +104,19 @@ namespace mwmp
{ {
RakNet::RakString rstr; RakNet::RakString rstr;
if (compress) if (compress)
rstr.DeserializeCompressed(bs); res = rstr.DeserializeCompressed(bs);
else else
bs->Read(rstr); res = bs->Read(rstr);
if (res)
{
rstr.Truncate(rstr.GetLength() > maxSize ? maxSize : rstr.GetLength()); rstr.Truncate(rstr.GetLength() > maxSize ? maxSize : rstr.GetLength());
str = rstr.C_String(); str = rstr.C_String();
} }
else
str = std::string();
}
return res;
} }
protected: protected:

Loading…
Cancel
Save