summaryrefslogtreecommitdiffstats
path: root/veslibrary/ves_cpplibrary/src/lib/encode/XBatchImp.cpp
blob: 6610d2f5f90ed73b84d9bfcd9f1de65c8ebddde0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "XBatchImp.h"

std::string XBatchImp::toString()
{
    try
    {
        auto js = toJson();
        return js.dump();
    }
    catch (json::exception& e)
    {
        SPDLOG_ERROR("Fail to dump XIpmiNic to json string:{}.", e.what());
        return "";
    }
}

void XBatchImp::addEvent(shared_ptr<XSerialable> event)
{
    events_.push_back(event);
}

nlohmann::json vagt::encode::XBatchImp::toJson()
{
    try
    {
        json field = json::array();

        for (auto event : events_)
        {
            if (event)
            {
                field.push_back( dynamic_pointer_cast<XJsonable>(event)->toJson()["event"]);
            }
        }

        json jsEvent;
        jsEvent["eventList"] = field;
        return jsEvent;
    }
    catch (json::exception& e)
    {
        SPDLOG_ERROR("Fail to build XBatch to json object:{}.", e.what());
        return json();
    }
}