|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include "fieldDescriptor.hpp" |
| 4 | +#include "outputPlugin.hpp" |
| 5 | + |
| 6 | +namespace ipxp { |
| 7 | + |
| 8 | +inline std::ostream& operator<<(std::ostream& os, std::byte b) |
| 9 | +{ |
| 10 | + os << "0x" << std::hex << std::uppercase << static_cast<int>(b); |
| 11 | + return os; |
| 12 | +} |
| 13 | + |
| 14 | +template<typename T> |
| 15 | +static void |
| 16 | +printScalar(const FieldDescriptor& field, const ScalarAccessor<T>& accessor, const void* data) |
| 17 | +{ |
| 18 | + std::cout << "[" << field.getGroup() << "] " << field.getName() << ": " << accessor(data) |
| 19 | + << "\n"; |
| 20 | +} |
| 21 | + |
| 22 | +template<typename T> |
| 23 | +static void |
| 24 | +printVector(const FieldDescriptor& field, const VectorAccessor<T>& accessor, const void* data) |
| 25 | +{ |
| 26 | + std::cout << "[" << field.getGroup() << "] " << field.getName() << ": ["; |
| 27 | + |
| 28 | + bool first = true; |
| 29 | + for (const auto& value : accessor(data)) { |
| 30 | + if (!first) |
| 31 | + std::cout << ", "; |
| 32 | + std::cout << value; |
| 33 | + first = false; |
| 34 | + } |
| 35 | + |
| 36 | + std::cout << "]\n"; |
| 37 | +} |
| 38 | + |
| 39 | +static void |
| 40 | +printScalarVariant(const FieldDescriptor& field, const ScalarValueGetter& variant, const void* data) |
| 41 | +{ |
| 42 | + const auto visitor = [&](const auto& accessor) { printScalar(field, accessor, data); }; |
| 43 | + std::visit(visitor, variant); |
| 44 | +} |
| 45 | + |
| 46 | +static void |
| 47 | +printVectorVariant(const FieldDescriptor& field, const VectorValueGetter& variant, const void* data) |
| 48 | +{ |
| 49 | + const auto visitor = [&](const auto& accessor) { printVector(field, accessor, data); }; |
| 50 | + std::visit(visitor, variant); |
| 51 | +} |
| 52 | + |
| 53 | +class TextOutputPlugin : public OutputPlugin { |
| 54 | +public: |
| 55 | + TextOutputPlugin(const FieldManager& manager, const std::vector<ProcessPluginEntry>& plugins) |
| 56 | + : OutputPlugin(manager, plugins) |
| 57 | + { |
| 58 | + } |
| 59 | + |
| 60 | + void processRecord(FlowRecordUniquePtr& flowRecord) override |
| 61 | + { |
| 62 | + auto outputFields = m_fieldManager.getBiflowFields(); |
| 63 | + auto fn = [&](ProcessPlugin* processPlugin) { |
| 64 | + // const void* pluginExportData = processPlugin->getExportData(); |
| 65 | + const void* pluginExportData = flowRecord->getPluginContext(0); |
| 66 | + |
| 67 | + for (const auto& outputField : outputFields) { |
| 68 | + if (!outputField.isInRecord(*flowRecord.get())) { |
| 69 | + continue; |
| 70 | + } |
| 71 | + |
| 72 | + const auto& getter = outputField.getValueGetter(); |
| 73 | + |
| 74 | + std::visit( |
| 75 | + [&](const auto& variant) { |
| 76 | + using GetterT = std::decay_t<decltype(variant)>; |
| 77 | + if constexpr (std::is_same_v<GetterT, ScalarValueGetter>) { |
| 78 | + printScalarVariant(outputField, variant, pluginExportData); |
| 79 | + } else if constexpr (std::is_same_v<GetterT, VectorValueGetter>) { |
| 80 | + printVectorVariant(outputField, variant, pluginExportData); |
| 81 | + } |
| 82 | + }, |
| 83 | + getter); |
| 84 | + } |
| 85 | + }; |
| 86 | + |
| 87 | + for (const auto& pluginEntry : m_plugins) { |
| 88 | + std::cout << "Processing " << pluginEntry.name << "\n"; |
| 89 | + fn(reinterpret_cast<ProcessPlugin*>(pluginEntry.plugin.get())); |
| 90 | + } |
| 91 | + } |
| 92 | +}; |
| 93 | + |
| 94 | +} // namespace ipxp |
0 commit comments