2015-05-15 03:36:57 +02:00
|
|
|
|
|
|
|
#include "svc_usermessage.h"
|
2015-06-25 05:59:39 +02:00
|
|
|
#include "base/bitfile.h"
|
|
|
|
#include "base/jsonfile.h"
|
2015-05-15 03:36:57 +02:00
|
|
|
#include "netmath.h"
|
|
|
|
#include "netcontants.h"
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
namespace NetHandlers
|
|
|
|
{
|
2015-06-19 02:23:26 +02:00
|
|
|
bool SVC_UserMessage_BitRead_Internal(BitRead& bitbuf, SourceGameContext& context, NetMsg::SVC_UserMessage* data)
|
2015-05-15 03:36:57 +02:00
|
|
|
{
|
|
|
|
data->msgType = bitbuf.ReadByte();
|
|
|
|
data->dataLengthInBits = bitbuf.ReadUBitLong(11);
|
|
|
|
assert(math::BitsToBytes(data->dataLengthInBits) <= MAX_USER_MSG_DATA);
|
|
|
|
data->data.reset(new uint8_t[math::BitsToBytes(data->dataLengthInBits)]);
|
|
|
|
bitbuf.ReadBits(data->data.get(), data->dataLengthInBits);
|
|
|
|
return !bitbuf.IsOverflowed();
|
|
|
|
}
|
|
|
|
|
2015-06-19 02:23:26 +02:00
|
|
|
bool SVC_UserMessage_BitWrite_Internal(BitWrite& bitbuf, const SourceGameContext& context, NetMsg::SVC_UserMessage* data)
|
2015-05-15 03:36:57 +02:00
|
|
|
{
|
|
|
|
bitbuf.WriteByte(data->msgType);
|
|
|
|
bitbuf.WriteUBitLong(data->dataLengthInBits, 11);
|
|
|
|
bitbuf.WriteBits(data->data.get(), data->dataLengthInBits);
|
|
|
|
return !bitbuf.IsOverflowed();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SVC_UserMessage_JsonRead_Internal(JsonRead& jsonbuf, SourceGameContext& context, NetMsg::SVC_UserMessage* data)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-15 08:49:51 +02:00
|
|
|
bool SVC_UserMessage_JsonWrite_Internal(JsonWrite& jsonbuf, const SourceGameContext& context, NetMsg::SVC_UserMessage* data)
|
2015-05-15 03:36:57 +02:00
|
|
|
{
|
2015-06-25 05:59:39 +02:00
|
|
|
jsonbuf.StartObject("svc_usermessage");
|
|
|
|
jsonbuf.WriteUInt32("msgType", data->msgType);
|
|
|
|
jsonbuf.WriteUInt32("dataLengthInBits", data->dataLengthInBits);
|
|
|
|
jsonbuf.WriteBits("data", data->data.get(), data->dataLengthInBits);
|
|
|
|
jsonbuf.EndObject();
|
2015-05-15 03:36:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVC_UserMessage_ToString_Internal(std::ostringstream& out, NetMsg::SVC_UserMessage* data)
|
|
|
|
{
|
2015-05-15 06:37:14 +02:00
|
|
|
out << "svc_UserMessage: type " << static_cast<uint32_t>(data->msgType)
|
2015-05-15 03:36:57 +02:00
|
|
|
<< ", bytes " << math::BitsToBytes(data->dataLengthInBits);
|
|
|
|
}
|
|
|
|
}
|