Changed json output to an object stream based format
This commit is contained in:
parent
43745b85f5
commit
2e597565bf
|
@ -25,6 +25,10 @@ namespace base
|
|||
void JsonWriterFile::Flush()
|
||||
{
|
||||
m_fileStream.Flush();
|
||||
|
||||
void JsonWriterFile::Reset()
|
||||
{
|
||||
m_writer.Reset(m_fileStream);
|
||||
}
|
||||
|
||||
bool JsonWriterFile::IsComplete() const
|
||||
|
@ -62,6 +66,13 @@ namespace base
|
|||
m_writer.EndArray();
|
||||
}
|
||||
|
||||
void JsonWriterFile::WriteNull(const char* name)
|
||||
{
|
||||
auto& writer = m_writer;
|
||||
writer.String(name);
|
||||
writer.Null();
|
||||
}
|
||||
|
||||
void JsonWriterFile::WriteBool(const char* name, bool value)
|
||||
{
|
||||
auto& writer = m_writer;
|
||||
|
@ -76,6 +87,20 @@ namespace base
|
|||
writer.Int(value);
|
||||
}
|
||||
|
||||
void JsonWriterFile::WriteInt32(const char* name, std::int32_t value, bool writeCondition)
|
||||
{
|
||||
auto& writer = m_writer;
|
||||
writer.String(name);
|
||||
if (writeCondition)
|
||||
{
|
||||
writer.Int(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Null();
|
||||
}
|
||||
}
|
||||
|
||||
void JsonWriterFile::WriteInt64(const char* name, std::int64_t value)
|
||||
{
|
||||
auto& writer = m_writer;
|
||||
|
@ -90,6 +115,20 @@ namespace base
|
|||
writer.Uint(value);
|
||||
}
|
||||
|
||||
void JsonWriterFile::WriteUInt32(const char* name, std::uint32_t value, bool writeCondition)
|
||||
{
|
||||
auto& writer = m_writer;
|
||||
writer.String(name);
|
||||
if (writeCondition)
|
||||
{
|
||||
writer.Uint(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Null();
|
||||
}
|
||||
}
|
||||
|
||||
void JsonWriterFile::WriteUint64(const char* name, std::uint64_t value)
|
||||
{
|
||||
auto& writer = m_writer;
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace base
|
|||
|
||||
FILE* GetFp() const;
|
||||
void Flush();
|
||||
void Reset();
|
||||
bool IsComplete() const;
|
||||
|
||||
void StartObject(const char* name = nullptr);
|
||||
|
@ -28,8 +29,10 @@ namespace base
|
|||
void WriteNull(const char* name);
|
||||
void WriteBool(const char* name, bool value);
|
||||
void WriteInt32(const char* name, std::int32_t value);
|
||||
void WriteInt32(const char* name, std::int32_t value, bool writeCondition);
|
||||
void WriteInt64(const char* name, std::int64_t value);
|
||||
void WriteUInt32(const char* name, std::uint32_t value);
|
||||
void WriteUInt32(const char* name, std::uint32_t value, bool writeCondition);
|
||||
void WriteUint64(const char* name, std::uint64_t value);
|
||||
void WriteString(const char* name, const char* value);
|
||||
void WriteString(const char* name, const char* value, std::int32_t length);
|
||||
|
|
|
@ -41,50 +41,63 @@ JsonWriter::JsonWriter(FILE* outputFp):
|
|||
void JsonWriter::StartWriting(demoheader_t& header)
|
||||
{
|
||||
auto& jsonFile = m_jsonFile;
|
||||
jsonFile.Reset();
|
||||
jsonFile.StartObject();
|
||||
|
||||
DemoJsonWriter::WriteDemoHeader(jsonFile, header);
|
||||
jsonFile.StartArray("demmessages");
|
||||
jsonFile.EndObject();
|
||||
}
|
||||
|
||||
void JsonWriter::EndWriting()
|
||||
{
|
||||
auto& jsonFile = m_jsonFile;
|
||||
jsonFile.EndArray();
|
||||
jsonFile.EndObject();
|
||||
jsonFile.Flush();
|
||||
assert(jsonFile.IsComplete());
|
||||
}
|
||||
|
||||
void JsonWriter::StartCommandPacket(const CommandPacket& packet)
|
||||
{
|
||||
auto& jsonFile = m_jsonFile;
|
||||
jsonFile.Reset();
|
||||
jsonFile.StartObject();
|
||||
jsonFile.WriteInt32("tick", packet.tick);
|
||||
jsonFile.StartObject(DemoCmdToString(packet.cmd));
|
||||
jsonFile.WriteString("cmd", DemoCmdToString(packet.cmd));
|
||||
jsonFile.EndObject();
|
||||
|
||||
jsonFile.Reset();
|
||||
jsonFile.StartObject();
|
||||
DemHandlers::DemMsg_JsonWrite(packet.cmd, jsonFile, packet.data);
|
||||
jsonFile.EndObject();
|
||||
assert(jsonFile.IsComplete());
|
||||
|
||||
if (packet.cmd == dem_packet || packet.cmd == dem_signon)
|
||||
{
|
||||
m_writingNetPackets = true;
|
||||
jsonFile.StartArray("netpackets");
|
||||
}
|
||||
}
|
||||
|
||||
void JsonWriter::EndCommandPacket(const PacketTrailingBits& trailingBits)
|
||||
{
|
||||
auto& jsonFile = m_jsonFile;
|
||||
if (m_writingNetPackets)
|
||||
{
|
||||
m_writingNetPackets = false;
|
||||
jsonFile.EndArray();
|
||||
auto& jsonFile = m_jsonFile;
|
||||
jsonFile.Reset();
|
||||
jsonFile.StartObject();
|
||||
jsonFile.StartObject("netpackets_end");
|
||||
jsonFile.WriteInt32("numTrailingBits", trailingBits.numTrailingBits);
|
||||
jsonFile.WriteInt32("trailingBitsValue", trailingBits.value, (trailingBits.numTrailingBits > 0));
|
||||
jsonFile.EndObject();
|
||||
jsonFile.EndObject();
|
||||
assert(jsonFile.IsComplete());
|
||||
}
|
||||
jsonFile.EndObject();
|
||||
jsonFile.EndObject();
|
||||
}
|
||||
|
||||
void JsonWriter::WriteNetPacket(NetPacket& packet, SourceGameContext& context)
|
||||
{
|
||||
auto& jsonFile = m_jsonFile;
|
||||
jsonFile.Reset();
|
||||
jsonFile.StartObject();
|
||||
NetHandlers::NetMsg_JsonWrite(packet.type, jsonFile, context, packet.data);
|
||||
jsonFile.EndObject();
|
||||
assert(jsonFile.IsComplete());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user