|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * @author Richard Plny <[email protected]> |
| 4 | + * @brief Unirec reporter implementation |
| 5 | + * |
| 6 | + * SPDX-License-Identifier: BSD-3-Clause |
| 7 | + */ |
| 8 | + |
| 9 | +#include "wif/reporters/unirecReporter.hpp" |
| 10 | + |
| 11 | +namespace WIF { |
| 12 | + |
| 13 | +UnirecReporter::UnirecReporter(Nemea::UnirecOutputInterface& outputInterface) |
| 14 | + : m_outputInterface(outputInterface) |
| 15 | +{ |
| 16 | +} |
| 17 | + |
| 18 | +void UnirecReporter::updateUnirecFieldIDs(const std::vector<ur_field_id_t>& unirecFieldIDs) |
| 19 | +{ |
| 20 | + m_unirecFieldIDs = unirecFieldIDs; |
| 21 | +} |
| 22 | + |
| 23 | +void UnirecReporter::onRecordStart() |
| 24 | +{ |
| 25 | + m_currentUnirecID = 0; |
| 26 | +} |
| 27 | + |
| 28 | +void UnirecReporter::report(const DataVariant& data) |
| 29 | +{ |
| 30 | + ur_field_id_t fieldID = m_unirecFieldIDs[m_currentUnirecID++]; |
| 31 | + auto& record = m_outputInterface.getUnirecRecord(); |
| 32 | + |
| 33 | + if (std::holds_alternative<uint8_t>(data)) { |
| 34 | + auto value = std::get<uint8_t>(data); |
| 35 | + record.setFieldFromType<uint8_t>(value, fieldID); |
| 36 | + } else if (std::holds_alternative<uint16_t>(data)) { |
| 37 | + auto value = std::get<uint16_t>(data); |
| 38 | + record.setFieldFromType<uint16_t>(value, fieldID); |
| 39 | + } else if (std::holds_alternative<uint32_t>(data)) { |
| 40 | + auto value = std::get<uint32_t>(data); |
| 41 | + record.setFieldFromType<uint32_t>(value, fieldID); |
| 42 | + } else if (std::holds_alternative<uint64_t>(data)) { |
| 43 | + auto value = std::get<uint64_t>(data); |
| 44 | + record.setFieldFromType<uint64_t>(value, fieldID); |
| 45 | + } else if (std::holds_alternative<double>(data)) { |
| 46 | + auto value = std::get<double>(data); |
| 47 | + record.setFieldFromType<double>(value, fieldID); |
| 48 | + } else if (std::holds_alternative<std::string>(data)) { |
| 49 | + auto value = std::get<std::string>(data); |
| 50 | + record.setFieldFromType<std::string>(value, fieldID); |
| 51 | + } else if (std::holds_alternative<IpAddress>(data)) { |
| 52 | + auto value = std::get<IpAddress>(data); |
| 53 | + Nemea::IpAddress nemeaIp(value.toString()); |
| 54 | + record.setFieldFromType<Nemea::IpAddress>(nemeaIp, fieldID); |
| 55 | + } else if (std::holds_alternative<std::vector<double>>(data)) { |
| 56 | + auto value = std::get<std::vector<double>>(data); |
| 57 | + record.setFieldFromVector<double>(value, fieldID); |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +void UnirecReporter::onRecordEnd() |
| 62 | +{ |
| 63 | + m_outputInterface.send(m_outputInterface.getUnirecRecord()); |
| 64 | +} |
| 65 | + |
| 66 | +void UnirecReporter::flush() |
| 67 | +{ |
| 68 | + m_outputInterface.sendFlush(); |
| 69 | +} |
| 70 | + |
| 71 | +} // namespace WIF |
0 commit comments