You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to generate a *.mcap file based on my own protobuf defination.
But it seems the generated mcap file couldn't decoded by foxglove.
Please help to see what's the problem’
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to generate a *.mcap file based on my own protobuf defination.
But it seems the generated mcap file couldn't decoded by foxglove.
Please help to see what's the problem’
here is my main cpp function.
#include
#include
#include "mcap/writer.hpp"
#include
#include "serialize_mv_planning_output_info.h"
#define MCAP_IMPLEMENTATION
// #include <mcap/writer.hpp>
#include
#include
#include
#include
#include
//
mcap::Timestamp now() {
return mcap::Timestamp(std::chrono::duration_caststd::chrono::nanoseconds(
std::chrono::system_clock::now().time_since_epoch())
.count());
}
int main() {
//
mcap::McapWriter writer;
auto status = writer.open("output.mcap", mcap::McapWriterOptions("protobuf"));
if (!status.ok()) {
std::cerr << "Failed to open MCAP file for writing: " << status.message << "\n";
return 1;
}
//
mcap::Schema mvPlanningOutputInfoSchema(
"MvPlanningOutputInfoTest",
"protobuf",
R"proto(
message MvPlanningOutputInfo {
int32 id = 1;
float x = 2;
float y = 3;
string name = 4;
}
)proto"
);
writer.addSchema(mvPlanningOutputInfoSchema);
//
mcap::Channel planningOutputChannel(
"/planning_output",
"protobuf",
mvPlanningOutputInfoSchema.id
);
writer.addChannel(planningOutputChannel);
//
MvPlanningOutputInfo info;
info.id = 123;
info.x = 10.5;
info.y = 20.5;
info.name = "SampleName";
//
std::vectorstd::byte serializedData = serializeMvPlanningOutputInfo(info);
//
mcap::Status TransferState;
mcap::Message msg;
msg.channelId = planningOutputChannel.id;
msg.sequence = 1; //
msg.logTime = now(); //
msg.publishTime = msg.logTime; //
msg.dataSize = serializedData.size();
msg.data = serializedData.data();
TransferState = writer.write(msg);
if (!TransferState.ok()) {
std::cerr << "Failed to write message to MCAP file: " << TransferState.message << "\n";
return 1;
}
//
writer.close();
return 0;
}
And there is my subfunction called serializeMvPlanningOutputInfo
// serialize_mv_planning_output_info.cpp
#include "serialize_mv_planning_output_info.h"
#include "writer.inl"
#include "types.inl"
#include
#include
std::vectorstd::byte serializeMvPlanningOutputInfo(const MvPlanningOutputInfo& info) {
//
MvPlanningOutputInfoProto protoMsg;
const uint32_t length = binaryData.size();
//
std::vectorstd::byte serializedData(binaryData.size()+4);
std::memcpy(serializedData.data(), &length, 4);
std::memcpy(serializedData.data() + 4, binaryData.data(), binaryData.size()+4);
return serializedData;
}
Beta Was this translation helpful? Give feedback.
All reactions