mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[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:
@@ -4,27 +4,26 @@
|
||||
|
||||
#include "frc/geometry/proto/Translation2dProto.h"
|
||||
|
||||
#include <wpi/ProtoHelper.h>
|
||||
#include "wpimath/protobuf/geometry2d.npb.h"
|
||||
|
||||
#include "geometry2d.pb.h"
|
||||
std::optional<frc::Translation2d> wpi::Protobuf<frc::Translation2d>::Unpack(
|
||||
InputStream& stream) {
|
||||
wpi_proto_ProtobufTranslation2d msg;
|
||||
if (!stream.Decode(msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<frc::Translation2d>::New(
|
||||
google::protobuf::Arena* arena) {
|
||||
return wpi::CreateMessage<wpi::proto::ProtobufTranslation2d>(arena);
|
||||
}
|
||||
|
||||
frc::Translation2d wpi::Protobuf<frc::Translation2d>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufTranslation2d*>(&msg);
|
||||
return frc::Translation2d{
|
||||
units::meter_t{m->x()},
|
||||
units::meter_t{m->y()},
|
||||
units::meter_t{msg.x},
|
||||
units::meter_t{msg.y},
|
||||
};
|
||||
}
|
||||
|
||||
void wpi::Protobuf<frc::Translation2d>::Pack(google::protobuf::Message* msg,
|
||||
bool wpi::Protobuf<frc::Translation2d>::Pack(OutputStream& stream,
|
||||
const frc::Translation2d& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufTranslation2d*>(msg);
|
||||
m->set_x(value.X().value());
|
||||
m->set_y(value.Y().value());
|
||||
wpi_proto_ProtobufTranslation2d msg{
|
||||
.x = value.X().value(),
|
||||
.y = value.Y().value(),
|
||||
};
|
||||
return stream.Encode(msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user