2021-10-18 10:54:01 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "cycle_t.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2021-10-18 16:19:28 +00:00
|
|
|
cycle_t::action_t cycle_t::to_action(std::string value) noexcept {
|
2021-10-18 10:54:01 +00:00
|
|
|
if (value == "read")
|
|
|
|
return action_t::read;
|
|
|
|
if (value == "write")
|
|
|
|
return action_t::write;
|
2021-10-18 16:19:28 +00:00
|
|
|
return action_t::unknown;
|
2021-10-18 10:54:01 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 16:19:28 +00:00
|
|
|
std::string cycle_t::to_string(action_t value) noexcept {
|
2021-10-18 10:54:01 +00:00
|
|
|
if (value == action_t::read)
|
|
|
|
return "read";
|
|
|
|
if (value == action_t::write)
|
|
|
|
return "write";
|
2021-10-18 16:19:28 +00:00
|
|
|
return "unknown";
|
2021-10-18 10:54:01 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 16:19:28 +00:00
|
|
|
cycle_t::cycle_t(uint16_t address, uint8_t value, action_t action) noexcept
|
2021-10-18 10:54:01 +00:00
|
|
|
: m_address(address),
|
|
|
|
m_value(value),
|
|
|
|
m_action(action) {}
|
|
|
|
|
|
|
|
#ifdef USE_SIMDJSON_JSON
|
|
|
|
|
2021-10-18 16:19:28 +00:00
|
|
|
cycle_t::cycle_t(simdjson::dom::element input) noexcept
|
2021-10-18 10:54:01 +00:00
|
|
|
: cycle_t(input.get_array()) {}
|
|
|
|
|
2021-10-18 16:19:28 +00:00
|
|
|
cycle_t::cycle_t(simdjson::dom::array input) noexcept
|
2021-10-18 19:40:13 +00:00
|
|
|
: m_iterator(input.begin()),
|
|
|
|
m_address((uint16_t)(uint64_t)*m_iterator),
|
|
|
|
m_value((uint8_t)(uint64_t)*++m_iterator),
|
|
|
|
m_action(to_action((std::string)*++m_iterator)) {
|
2021-10-18 10:54:01 +00:00
|
|
|
assert(input.size() == 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-10-18 23:39:26 +00:00
|
|
|
#ifdef USE_RAPIDJSON_JSON
|
|
|
|
|
|
|
|
cycle_t::cycle_t(const rapidjson::Value& input)
|
|
|
|
: m_address((uint8_t)input[0].GetInt64()),
|
|
|
|
m_value((uint8_t)input[1].GetInt64()),
|
|
|
|
m_action(to_action(input[2].GetString())) {
|
2021-10-18 23:59:02 +00:00
|
|
|
assert(input.Size() == 3);
|
2021-10-18 23:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-10-18 10:54:01 +00:00
|
|
|
#ifdef USE_BOOST_JSON
|
|
|
|
|
2021-10-18 19:40:13 +00:00
|
|
|
cycle_t::cycle_t(const boost::json::value& input) noexcept
|
|
|
|
: cycle_t(input.get_array()) {}
|
2021-10-18 10:54:01 +00:00
|
|
|
|
2021-10-18 19:40:13 +00:00
|
|
|
cycle_t::cycle_t(const boost::json::array& input) noexcept
|
|
|
|
: m_address((uint16_t)input[0].get_int64()),
|
|
|
|
m_value((uint8_t)input[1].get_int64()),
|
|
|
|
m_action(to_action((std::string)input[2].get_string())) {
|
2021-10-18 10:54:01 +00:00
|
|
|
assert(input.size() == 3);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_NLOHMANN_JSON
|
|
|
|
|
2021-10-18 19:40:13 +00:00
|
|
|
cycle_t::cycle_t(const nlohmann::json& input) noexcept
|
2021-10-18 10:54:01 +00:00
|
|
|
: m_address(input[0].get<uint16_t>()),
|
|
|
|
m_value(input[1].get<uint8_t>()),
|
|
|
|
m_action(to_action(input[2].get<std::string>())) {
|
|
|
|
assert(input.size() == 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_JSONCPP_JSON
|
|
|
|
|
|
|
|
cycle_t::cycle_t(const Json::Value& input)
|
2021-10-18 11:07:24 +00:00
|
|
|
: m_address(input[0].asUInt()),
|
|
|
|
m_value(input[1].asUInt()),
|
|
|
|
m_action(to_action(input[2].asString())) {
|
2021-10-18 10:54:01 +00:00
|
|
|
assert(input.size() == 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|