Commit 05c91823 authored by Hubert Denkmair's avatar Hubert Denkmair

add support for new stats message

parent 143d569b
......@@ -164,6 +164,7 @@ void MsgPackProtocol::to_json(nlohmann::json &j, const MsgPackProtocol::BotStats
for (auto& item: msg.items)
{
data[std::to_string(item.bot_id)] = {
{ "m", item.mass },
{ "n", item.natural_food_consumed },
{ "c", item.carrison_food_consumed },
{ "h", item.hunted_food_consumed }
......
......@@ -79,6 +79,7 @@ namespace MsgPackProtocol
double natural_food_consumed;
double carrison_food_consumed;
double hunted_food_consumed;
double mass;
};
struct Message
......@@ -548,11 +549,12 @@ namespace msgpack {
{
template <typename Stream> msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, MsgPackProtocol::BotStatsItem const& v) const
{
o.pack_array(4);
o.pack_array(5);
o.pack(v.bot_id);
o.pack(v.natural_food_consumed);
o.pack(v.carrison_food_consumed);
o.pack(v.hunted_food_consumed);
o.pack(v.mass);
return o;
}
};
......@@ -562,11 +564,12 @@ namespace msgpack {
msgpack::object const& operator()(msgpack::object const& o, MsgPackProtocol::BotStatsItem& v) const
{
if (o.type != msgpack::type::ARRAY) throw msgpack::type_error();
if (o.via.array.size != 4) throw msgpack::type_error();
if (o.via.array.size != 5) throw msgpack::type_error();
o.via.array.ptr[0] >> v.bot_id;
o.via.array.ptr[1] >> v.natural_food_consumed;
o.via.array.ptr[2] >> v.carrison_food_consumed;
o.via.array.ptr[3] >> v.hunted_food_consumed;
o.via.array.ptr[4] >> v.mass;
return o;
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment