[wpiutil] Change C++ protobuf to nanopb (#7309)

The Google C++ protobuf implementation has issues with dynamic linkage across DLL boundaries because it uses global variables.  It also has a compile-time dependency because the protoc version must exactly match the libprotobuf version.  Using nanopb with a customized generator fixes both of these issues.

Co-authored-by: Gold856 <117957790+Gold856@users.noreply.github.com>
This commit is contained in:
Thad House
2024-11-07 22:42:50 -08:00
committed by GitHub
parent fd2e0c0427
commit 8b8b634f65
166 changed files with 17522 additions and 1571 deletions

View File

@@ -4,27 +4,42 @@
#include "frc/geometry/proto/Transform3dProto.h"
#include <wpi/ProtoHelper.h>
#include <wpi/protobuf/ProtobufCallbacks.h>
#include "geometry3d.pb.h"
#include "wpimath/protobuf/geometry3d.npb.h"
google::protobuf::Message* wpi::Protobuf<frc::Transform3d>::New(
google::protobuf::Arena* arena) {
return wpi::CreateMessage<wpi::proto::ProtobufTransform3d>(arena);
}
std::optional<frc::Transform3d> wpi::Protobuf<frc::Transform3d>::Unpack(
InputStream& stream) {
wpi::UnpackCallback<frc::Translation3d> tsln;
wpi::UnpackCallback<frc::Rotation3d> rot;
wpi_proto_ProtobufTransform3d msg{
.translation = tsln.Callback(),
.rotation = rot.Callback(),
};
if (!stream.Decode(msg)) {
return {};
}
auto itsln = tsln.Items();
auto irot = rot.Items();
if (itsln.empty() || irot.empty()) {
return {};
}
frc::Transform3d wpi::Protobuf<frc::Transform3d>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufTransform3d*>(&msg);
return frc::Transform3d{
wpi::UnpackProtobuf<frc::Translation3d>(m->wpi_translation()),
wpi::UnpackProtobuf<frc::Rotation3d>(m->wpi_rotation()),
itsln[0],
irot[0],
};
}
void wpi::Protobuf<frc::Transform3d>::Pack(google::protobuf::Message* msg,
bool wpi::Protobuf<frc::Transform3d>::Pack(OutputStream& stream,
const frc::Transform3d& value) {
auto m = static_cast<wpi::proto::ProtobufTransform3d*>(msg);
wpi::PackProtobuf(m->mutable_translation(), value.Translation());
wpi::PackProtobuf(m->mutable_rotation(), value.Rotation());
wpi::PackCallback tsln{&value.Translation()};
wpi::PackCallback rot{&value.Rotation()};
wpi_proto_ProtobufTransform3d msg{
.translation = tsln.Callback(),
.rotation = rot.Callback(),
};
return stream.Encode(msg);
}