// // Created by Johnathon Slightham on 2025-06-30. // #ifndef SENSORMESSAGEBUILDER_H #define SENSORMESSAGEBUILDER_H #include #include #include "flatbuffers_generated/SensorMessage_generated.h" namespace Flatbuffers { struct target_angle { int16_t angle; }; struct current_angle { int16_t angle; }; struct current_text { std::string text; }; typedef std::variant sensor_value; class SensorMessageBuilder { public: SensorMessageBuilder() : builder_(1024) {} static const Messaging::SensorMessage * parse_sensor_message(const std::uint8_t *buffer); template static std::optional build_sensor_value(Messaging::SensorValue type, T value) { switch (type) { case Messaging::SensorValue_TargetAngle: { const Messaging::TargetAngle *target = static_cast(value); return target_angle{target->value()}; } case Messaging::SensorValue_CurrentAngle: { const Messaging::CurrentAngle *current = static_cast(value); return current_angle{current->value()}; } case Messaging::SensorValue_CurrentText: { const Messaging::CurrentText *current = static_cast(value); return current_text{current->value()->str()}; } default: return std::nullopt; } } private: flatbuffers::FlatBufferBuilder builder_; }; } // namespace Flatbuffers #endif // TOPOLOGYMESSAGEBUILDER_H