refactor(streamer): adopt proxy backends and typed statuses
This commit is contained in:
@@ -15,6 +15,23 @@
|
||||
|
||||
namespace {
|
||||
|
||||
enum class TesterExitCode : int {
|
||||
Success = 0,
|
||||
OpenError = 2,
|
||||
SchemaError = 3,
|
||||
TopicMismatch = 4,
|
||||
TimestampError = 5,
|
||||
ParseError = 6,
|
||||
FormatMismatch = 7,
|
||||
EmptyPayload = 8,
|
||||
ThresholdError = 9,
|
||||
};
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr int exit_code(TesterExitCode code) {
|
||||
return static_cast<int>(code);
|
||||
}
|
||||
|
||||
struct Config {
|
||||
std::string input_path{};
|
||||
std::optional<std::string> expected_topic{};
|
||||
@@ -51,7 +68,7 @@ int main(int argc, char **argv) {
|
||||
const auto open_status = reader.open(config->input_path);
|
||||
if (!open_status.ok()) {
|
||||
spdlog::error("failed to open MCAP file '{}': {}", config->input_path, open_status.message);
|
||||
return 2;
|
||||
return exit_code(TesterExitCode::OpenError);
|
||||
}
|
||||
|
||||
std::uint64_t message_count{0};
|
||||
@@ -63,7 +80,7 @@ int main(int argc, char **argv) {
|
||||
if (it->schema == nullptr || it->channel == nullptr) {
|
||||
spdlog::error("MCAP message missing schema or channel metadata");
|
||||
reader.close();
|
||||
return 3;
|
||||
return exit_code(TesterExitCode::SchemaError);
|
||||
}
|
||||
if (it->schema->encoding != "protobuf" || it->schema->name != "foxglove.CompressedVideo") {
|
||||
continue;
|
||||
@@ -71,34 +88,34 @@ int main(int argc, char **argv) {
|
||||
if (it->channel->messageEncoding != "protobuf") {
|
||||
spdlog::error("unexpected MCAP message encoding: {}", it->channel->messageEncoding);
|
||||
reader.close();
|
||||
return 3;
|
||||
return exit_code(TesterExitCode::SchemaError);
|
||||
}
|
||||
if (config->expected_topic && it->channel->topic != *config->expected_topic) {
|
||||
spdlog::error("unexpected topic: expected '{}' got '{}'", *config->expected_topic, it->channel->topic);
|
||||
reader.close();
|
||||
return 4;
|
||||
return exit_code(TesterExitCode::TopicMismatch);
|
||||
}
|
||||
if (saw_log_time && it->message.logTime < previous_log_time) {
|
||||
spdlog::error("non-monotonic logTime detected: {} < {}", it->message.logTime, previous_log_time);
|
||||
reader.close();
|
||||
return 5;
|
||||
return exit_code(TesterExitCode::TimestampError);
|
||||
}
|
||||
|
||||
foxglove::CompressedVideo message{};
|
||||
if (!message.ParseFromArray(it->message.data, static_cast<int>(it->message.dataSize))) {
|
||||
spdlog::error("failed to parse foxglove.CompressedVideo payload");
|
||||
reader.close();
|
||||
return 6;
|
||||
return exit_code(TesterExitCode::ParseError);
|
||||
}
|
||||
if (config->expected_format && message.format() != *config->expected_format) {
|
||||
spdlog::error("unexpected format: expected '{}' got '{}'", *config->expected_format, message.format());
|
||||
reader.close();
|
||||
return 7;
|
||||
return exit_code(TesterExitCode::FormatMismatch);
|
||||
}
|
||||
if (message.data().empty()) {
|
||||
spdlog::error("compressed video payload is empty");
|
||||
reader.close();
|
||||
return 8;
|
||||
return exit_code(TesterExitCode::EmptyPayload);
|
||||
}
|
||||
|
||||
previous_log_time = it->message.logTime;
|
||||
@@ -110,9 +127,9 @@ int main(int argc, char **argv) {
|
||||
|
||||
if (message_count < config->min_messages) {
|
||||
spdlog::error("message threshold not met: {} < {}", message_count, config->min_messages);
|
||||
return 9;
|
||||
return exit_code(TesterExitCode::ThresholdError);
|
||||
}
|
||||
|
||||
spdlog::info("validated {} foxglove.CompressedVideo MCAP messages", message_count);
|
||||
return 0;
|
||||
return exit_code(TesterExitCode::Success);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user