mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[glass] Add protobuf decode error log message (#5812)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user