From fb363a49ef4851ddc6cdd6900784d8a9b379789d Mon Sep 17 00:00:00 2001 From: TimmRuppert Date: Fri, 20 Dec 2024 16:23:34 +0100 Subject: [PATCH] Do not overwrite channel metadata if already present (#14) Signed-off-by: Timm Ruppert --- src/tracefile/writer/MCAPTraceFileWriter.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tracefile/writer/MCAPTraceFileWriter.cpp b/src/tracefile/writer/MCAPTraceFileWriter.cpp index 5691ad5..ecf24b0 100644 --- a/src/tracefile/writer/MCAPTraceFileWriter.cpp +++ b/src/tracefile/writer/MCAPTraceFileWriter.cpp @@ -190,11 +190,17 @@ uint16_t MCAPTraceFileWriter::AddChannel(const std::string& topic, const google: path_schema = *it_schema; } - // add osi version to channel metadata as required by spec. - const auto osi_version = osi3::InterfaceVersion::descriptor()->file()->options().GetExtension(osi3::current_interface_version); - channel_metadata["net.asam.osi.trace.channel.osi_version"] = - std::to_string(osi_version.version_major()) + "." + std::to_string(osi_version.version_minor()) + "." + std::to_string(osi_version.version_patch()); - channel_metadata["net.asam.osi.trace.channel.protobuf_version"] = google::protobuf::internal::VersionString(GOOGLE_PROTOBUF_VERSION); + // add osi version (if not present) to channel metadata as required by spec. + if (channel_metadata.find("net.asam.osi.trace.channel.osi_version") == channel_metadata.end()) { + const auto osi_version = osi3::InterfaceVersion::descriptor()->file()->options().GetExtension(osi3::current_interface_version); + channel_metadata["net.asam.osi.trace.channel.osi_version"] = + std::to_string(osi_version.version_major()) + "." + std::to_string(osi_version.version_minor()) + "." + std::to_string(osi_version.version_patch()); + } + + // add protobuf version (if not present) to channel metadata as required by spec. + if (channel_metadata.find("net.asam.osi.trace.channel.protobuf_version") == channel_metadata.end()) { + channel_metadata["net.asam.osi.trace.channel.protobuf_version"] = google::protobuf::internal::VersionString(GOOGLE_PROTOBUF_VERSION); + } // add the channel to the writer/mcap file mcap::Channel channel(topic, "protobuf", path_schema.id, channel_metadata);