[glass] Add protobuf decode error log message (#5812)

This commit is contained in:
Peter Johnson
2023-10-23 23:36:23 -07:00
committed by GitHub
parent 928e87b4f4
commit 23ea188e60
3 changed files with 18 additions and 10 deletions

View File

@@ -895,12 +895,16 @@ void NetworkTablesModel::Update() {
entry->info.type_str == "proto:FileDescriptorProto") {
// protobuf descriptor handling
auto filename = wpi::drop_front(entry->info.name, 15);
m_protoDb.Add(filename, entry->value.GetRaw());
// loop over all protobuf entries and update (conservatively)
for (auto&& entryPair : m_entries) {
auto ts = entryPair.second->info.type_str;
if (wpi::starts_with(ts, "proto:")) {
entryPair.second->UpdateFromValue(*this);
if (!m_protoDb.Add(filename, entry->value.GetRaw())) {
fmt::print("could not decode protobuf '{}' filename '{}'\n",
entry->info.name, filename);
} else {
// loop over all protobuf entries and update (conservatively)
for (auto&& entryPair : m_entries) {
auto& ts = entryPair.second->info.type_str;
if (wpi::starts_with(ts, "proto:")) {
entryPair.second->UpdateFromValue(*this);
}
}
}
}

View File

@@ -12,12 +12,15 @@ using google::protobuf::Arena;
using google::protobuf::FileDescriptorProto;
using google::protobuf::Message;
void ProtobufMessageDatabase::Add(std::string_view filename,
bool ProtobufMessageDatabase::Add(std::string_view filename,
std::span<const uint8_t> data) {
auto& file = m_files[filename];
if (file.complete) {
file.complete = false;
m_factory.reset();
m_msgs.clear();
// rebuild the pool EXCEPT for this descriptor
m_pool = std::make_unique<google::protobuf::DescriptorPool>();
@@ -31,7 +34,6 @@ void ProtobufMessageDatabase::Add(std::string_view filename,
}
// clear messages and reset factory; Find() will recreate as needed
m_msgs.clear();
m_factory = std::make_unique<google::protobuf::DynamicMessageFactory>();
}
@@ -49,10 +51,11 @@ void ProtobufMessageDatabase::Add(std::string_view filename,
// parse data
if (!file.proto->ParseFromArray(data.data(), data.size())) {
return;
return false;
}
Build(filename, file);
return true;
}
Message* ProtobufMessageDatabase::Find(std::string_view name) const {

View File

@@ -33,8 +33,9 @@ class ProtobufMessageDatabase {
*
* @param filename filename
* @param data FileDescriptorProto serialized data
* @return False if could not parse data
*/
void Add(std::string_view filename, std::span<const uint8_t> data);
bool Add(std::string_view filename, std::span<const uint8_t> data);
/**
* Finds a message in the database by name.