[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

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Ellipse2d.h"
@@ -11,19 +11,19 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Ellipse2d>;
const Ellipse2d kExpectedData{
Pose2d{Translation2d{0.191_m, 2.2_m}, Rotation2d{22.9_rad}}, 1.2_m, 2.3_m};
} // namespace
TEST(Ellipse2dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Ellipse2d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.Center(), unpacked_data.Center());
EXPECT_EQ(kExpectedData.XSemiAxis(), unpacked_data.XSemiAxis());
EXPECT_EQ(kExpectedData.YSemiAxis(), unpacked_data.YSemiAxis());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.Center(), unpacked_data->Center());
EXPECT_EQ(kExpectedData.XSemiAxis(), unpacked_data->XSemiAxis());
EXPECT_EQ(kExpectedData.YSemiAxis(), unpacked_data->YSemiAxis());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Pose2d.h"
@@ -11,18 +11,18 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Pose2d>;
const Pose2d kExpectedData =
Pose2d{Translation2d{0.191_m, 2.2_m}, Rotation2d{22.9_rad}};
} // namespace
TEST(Pose2dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Pose2d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.Translation(), unpacked_data.Translation());
EXPECT_EQ(kExpectedData.Rotation(), unpacked_data.Rotation());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.Translation(), unpacked_data->Translation());
EXPECT_EQ(kExpectedData.Rotation(), unpacked_data->Rotation());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Pose3d.h"
@@ -11,19 +11,19 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Pose3d>;
const Pose3d kExpectedData =
Pose3d{Translation3d{1.1_m, 2.2_m, 1.1_m},
Rotation3d{Quaternion{1.91, 0.3504, 3.3, 1.74}}};
} // namespace
TEST(Pose3dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Pose3d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.Translation(), unpacked_data.Translation());
EXPECT_EQ(kExpectedData.Rotation(), unpacked_data.Rotation());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.Translation(), unpacked_data->Translation());
EXPECT_EQ(kExpectedData.Rotation(), unpacked_data->Rotation());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Quaternion.h"
@@ -11,19 +11,19 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Quaternion>;
const Quaternion kExpectedData = Quaternion{1.1, 0.191, 35.04, 19.1};
} // namespace
TEST(QuaternionProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Quaternion unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.W(), unpacked_data.W());
EXPECT_EQ(kExpectedData.X(), unpacked_data.X());
EXPECT_EQ(kExpectedData.Y(), unpacked_data.Y());
EXPECT_EQ(kExpectedData.Z(), unpacked_data.Z());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.W(), unpacked_data->W());
EXPECT_EQ(kExpectedData.X(), unpacked_data->X());
EXPECT_EQ(kExpectedData.Y(), unpacked_data->Y());
EXPECT_EQ(kExpectedData.Z(), unpacked_data->Z());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Rectangle2d.h"
@@ -11,19 +11,19 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Rectangle2d>;
const Rectangle2d kExpectedData{
Pose2d{Translation2d{0.191_m, 2.2_m}, Rotation2d{22.9_rad}}, 1.2_m, 2.3_m};
} // namespace
TEST(Rectangle2dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Rectangle2d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.Center(), unpacked_data.Center());
EXPECT_EQ(kExpectedData.XWidth(), unpacked_data.XWidth());
EXPECT_EQ(kExpectedData.YWidth(), unpacked_data.YWidth());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.Center(), unpacked_data->Center());
EXPECT_EQ(kExpectedData.XWidth(), unpacked_data->XWidth());
EXPECT_EQ(kExpectedData.YWidth(), unpacked_data->YWidth());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Rotation2d.h"
@@ -11,16 +11,15 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Rotation2d>;
const Rotation2d kExpectedData = Rotation2d{1.91_rad};
} // namespace
TEST(Rotation2dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Rotation2d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.Radians().value(), unpacked_data.Radians().value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.Radians().value(), unpacked_data->Radians().value());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Rotation3d.h"
@@ -11,17 +11,17 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Rotation3d>;
const Rotation3d kExpectedData =
Rotation3d{Quaternion{2.29, 0.191, 0.191, 17.4}};
} // namespace
TEST(Rotation3dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Rotation3d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.GetQuaternion(), unpacked_data.GetQuaternion());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.GetQuaternion(), unpacked_data->GetQuaternion());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Transform2d.h"
@@ -11,18 +11,18 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Transform2d>;
const Transform2d kExpectedData =
Transform2d{Translation2d{0.191_m, 2.2_m}, Rotation2d{4.4_rad}};
} // namespace
TEST(Transform2dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Transform2d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.Translation(), unpacked_data.Translation());
EXPECT_EQ(kExpectedData.Rotation(), unpacked_data.Rotation());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.Translation(), unpacked_data->Translation());
EXPECT_EQ(kExpectedData.Rotation(), unpacked_data->Rotation());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Transform3d.h"
@@ -11,19 +11,19 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Transform3d>;
const Transform3d kExpectedData =
Transform3d{Translation3d{0.3504_m, 22.9_m, 3.504_m},
Rotation3d{Quaternion{0.3504, 35.04, 2.29, 0.3504}}};
} // namespace
TEST(Transform3dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Transform3d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.Translation(), unpacked_data.Translation());
EXPECT_EQ(kExpectedData.Rotation(), unpacked_data.Rotation());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.Translation(), unpacked_data->Translation());
EXPECT_EQ(kExpectedData.Rotation(), unpacked_data->Rotation());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Translation2d.h"
@@ -11,17 +11,16 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Translation2d>;
const Translation2d kExpectedData = Translation2d{3.504_m, 22.9_m};
} // namespace
TEST(Translation2dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Translation2d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.X().value(), unpacked_data.X().value());
EXPECT_EQ(kExpectedData.Y().value(), unpacked_data.Y().value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.X().value(), unpacked_data->X().value());
EXPECT_EQ(kExpectedData.Y().value(), unpacked_data->Y().value());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Translation3d.h"
@@ -11,18 +11,18 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Translation3d>;
const Translation3d kExpectedData = Translation3d{35.04_m, 22.9_m, 3.504_m};
} // namespace
TEST(Translation3dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Translation3d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.X(), unpacked_data.X());
EXPECT_EQ(kExpectedData.Y(), unpacked_data.Y());
EXPECT_EQ(kExpectedData.Z(), unpacked_data.Z());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.X(), unpacked_data->X());
EXPECT_EQ(kExpectedData.Y(), unpacked_data->Y());
EXPECT_EQ(kExpectedData.Z(), unpacked_data->Z());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Twist2d.h"
@@ -11,18 +11,18 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Twist2d>;
const Twist2d kExpectedData = Twist2d{2.29_m, 35.04_m, 35.04_rad};
} // namespace
TEST(Twist2dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Twist2d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.dx.value(), unpacked_data.dx.value());
EXPECT_EQ(kExpectedData.dy.value(), unpacked_data.dy.value());
EXPECT_EQ(kExpectedData.dtheta.value(), unpacked_data.dtheta.value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.dx.value(), unpacked_data->dx.value());
EXPECT_EQ(kExpectedData.dy.value(), unpacked_data->dy.value());
EXPECT_EQ(kExpectedData.dtheta.value(), unpacked_data->dtheta.value());
}

View File

@@ -2,8 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/geometry/Twist3d.h"
@@ -11,22 +11,22 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::Twist3d>;
const Twist3d kExpectedData =
Twist3d{1.1_m, 2.29_m, 35.04_m, 0.174_rad, 19.1_rad, 4.4_rad};
} // namespace
TEST(Twist3dProtoTest, Roundtrip) {
google::protobuf::Arena arena;
google::protobuf::Message* proto = ProtoType::New(&arena);
ProtoType::Pack(proto, kExpectedData);
wpi::ProtobufMessage<decltype(kExpectedData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Twist3d unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.dx.value(), unpacked_data.dx.value());
EXPECT_EQ(kExpectedData.dy.value(), unpacked_data.dy.value());
EXPECT_EQ(kExpectedData.dz.value(), unpacked_data.dz.value());
EXPECT_EQ(kExpectedData.rx.value(), unpacked_data.rx.value());
EXPECT_EQ(kExpectedData.ry.value(), unpacked_data.ry.value());
EXPECT_EQ(kExpectedData.rz.value(), unpacked_data.rz.value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.dx.value(), unpacked_data->dx.value());
EXPECT_EQ(kExpectedData.dy.value(), unpacked_data->dy.value());
EXPECT_EQ(kExpectedData.dz.value(), unpacked_data->dz.value());
EXPECT_EQ(kExpectedData.rx.value(), unpacked_data->rx.value());
EXPECT_EQ(kExpectedData.ry.value(), unpacked_data->ry.value());
EXPECT_EQ(kExpectedData.rz.value(), unpacked_data->rz.value());
}