AstraLog-HPC
Loading...
Searching...
No Matches
Validator.hpp
Go to the documentation of this file.
1
6#pragma once
7#include "simdjson.h"
8#include <string>
9#include <unordered_set>
10#include <stdexcept>
11
12
18 bool valid = false;
19 std::string sensor_id;
20 std::string timestamp;
21};
22
28class Validator {
29public:
34 Validator(const std::string& path) {
35 load_sensors(path);
36 }
37
41 ~Validator() = default;
42
48 ValidationResult evaluate(const std::string& json);
49
54 int get_sensor_count();
55private:
56 simdjson::ondemand::parser parser;
57 std::unordered_set<std::string> sensors;
58 int sensor_count = 0;
59
64 void load_sensors(const std::string& path);
65};
Validates incoming raw telemetry packets against a known set of sensors.
Definition Validator.hpp:28
int sensor_count
The total number of valid sensors loaded.
Definition Validator.hpp:58
simdjson::ondemand::parser parser
The simdjson parser instance used for fast JSON processing.
Definition Validator.hpp:56
Validator(const std::string &path)
Constructs a new Validator and loads the allowed sensors from a configuration file.
Definition Validator.hpp:34
ValidationResult evaluate(const std::string &json)
Validates a raw JSON telemetry packet.
Definition Validator.cpp:35
void load_sensors(const std::string &path)
Parses the configuration file and populates the internal set of allowed sensors.
Definition Validator.cpp:13
~Validator()=default
Default destructor.
int get_sensor_count()
Gets the total number of valid sensors loaded from the configuration file.
Definition Validator.cpp:126
std::unordered_set< std::string > sensors
The set of valid sensor IDs loaded from the configuration.
Definition Validator.hpp:57
Represents the outcome of a telemetry packet validation attempt.
Definition Validator.hpp:17
bool valid
True if the packet is valid and the sensor is recognised, false otherwise.
Definition Validator.hpp:18
std::string sensor_id
Set once both ID fields parse as strings, even if the packet is later rejected.
Definition Validator.hpp:19
std::string timestamp
Set once both ID fields parse as strings, even if the packet is later rejected.
Definition Validator.hpp:20