[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,8 +4,8 @@
#pragma once
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include <wpi/protobuf/Protobuf.h>
template <typename T>
@@ -14,41 +14,14 @@ class ProtoTest : public testing::Test {};
TYPED_TEST_SUITE_P(ProtoTest);
TYPED_TEST_P(ProtoTest, RoundTrip) {
using Type = typename TypeParam::Type;
google::protobuf::Arena arena;
google::protobuf::Message* proto = wpi::Protobuf<Type>::New(&arena);
wpi::PackProtobuf(proto, TypeParam::kTestData);
wpi::ProtobufMessage<decltype(TypeParam::kTestData)> message;
wpi::SmallVector<uint8_t, 64> buf;
Type unpacked_data = wpi::UnpackProtobuf<Type>(*proto);
TypeParam::CheckEq(TypeParam::kTestData, unpacked_data);
ASSERT_TRUE(message.Pack(buf, TypeParam::kTestData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
TypeParam::CheckEq(TypeParam::kTestData, *unpacked_data);
}
TYPED_TEST_P(ProtoTest, DoublePack) {
using Type = typename TypeParam::Type;
google::protobuf::Arena arena;
google::protobuf::Message* proto = wpi::Protobuf<Type>::New(&arena);
wpi::PackProtobuf(proto, TypeParam::kTestData);
wpi::PackProtobuf(proto, TypeParam::kTestData);
Type unpacked_data = wpi::UnpackProtobuf<Type>(*proto);
TypeParam::CheckEq(TypeParam::kTestData, unpacked_data);
}
TYPED_TEST_P(ProtoTest, DoubleUnpack) {
using Type = typename TypeParam::Type;
google::protobuf::Arena arena;
google::protobuf::Message* proto = wpi::Protobuf<Type>::New(&arena);
wpi::PackProtobuf(proto, TypeParam::kTestData);
{
Type unpacked_data = wpi::UnpackProtobuf<Type>(*proto);
TypeParam::CheckEq(TypeParam::kTestData, unpacked_data);
}
{
Type unpacked_data = wpi::UnpackProtobuf<Type>(*proto);
TypeParam::CheckEq(TypeParam::kTestData, unpacked_data);
}
}
REGISTER_TYPED_TEST_SUITE_P(ProtoTest, RoundTrip, DoublePack, DoubleUnpack);
REGISTER_TYPED_TEST_SUITE_P(ProtoTest, RoundTrip);

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/controller/ArmFeedforward.h"
@@ -11,8 +11,6 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::ArmFeedforward>;
static constexpr auto Ks = 1.91_V;
static constexpr auto Kg = 2.29_V;
static constexpr auto Kv = 35.04_V * 1_s / 1_rad;
@@ -21,13 +19,15 @@ const ArmFeedforward kExpectedData{Ks, Kg, Kv, Ka};
} // namespace
TEST(ArmFeedforwardProtoTest, 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;
ArmFeedforward unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.GetKs().value(), unpacked_data.GetKs().value());
EXPECT_EQ(kExpectedData.GetKg().value(), unpacked_data.GetKg().value());
EXPECT_EQ(kExpectedData.GetKv().value(), unpacked_data.GetKv().value());
EXPECT_EQ(kExpectedData.GetKa().value(), unpacked_data.GetKa().value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.GetKs().value(), unpacked_data->GetKs().value());
EXPECT_EQ(kExpectedData.GetKg().value(), unpacked_data->GetKg().value());
EXPECT_EQ(kExpectedData.GetKv().value(), unpacked_data->GetKv().value());
EXPECT_EQ(kExpectedData.GetKa().value(), unpacked_data->GetKa().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/controller/DifferentialDriveWheelVoltages.h"
@@ -18,11 +18,12 @@ const DifferentialDriveWheelVoltages kExpectedData =
} // namespace
TEST(DifferentialDriveWheelVoltagesProtoTest, 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;
DifferentialDriveWheelVoltages unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.left.value(), unpacked_data.left.value());
EXPECT_EQ(kExpectedData.right.value(), unpacked_data.right.value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.left.value(), unpacked_data->left.value());
EXPECT_EQ(kExpectedData.right.value(), unpacked_data->right.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/controller/ElevatorFeedforward.h"
@@ -11,8 +11,6 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::ElevatorFeedforward>;
static constexpr auto Ks = 1.91_V;
static constexpr auto Kg = 2.29_V;
static constexpr auto Kv = 35.04_V * 1_s / 1_m;
@@ -22,13 +20,15 @@ constexpr ElevatorFeedforward kExpectedData{Ks, Kg, Kv, Ka};
} // namespace
TEST(ElevatorFeedforwardProtoTest, 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;
ElevatorFeedforward unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.GetKs().value(), unpacked_data.GetKs().value());
EXPECT_EQ(kExpectedData.GetKg().value(), unpacked_data.GetKg().value());
EXPECT_EQ(kExpectedData.GetKv().value(), unpacked_data.GetKv().value());
EXPECT_EQ(kExpectedData.GetKa().value(), unpacked_data.GetKa().value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.GetKs().value(), unpacked_data->GetKs().value());
EXPECT_EQ(kExpectedData.GetKg().value(), unpacked_data->GetKg().value());
EXPECT_EQ(kExpectedData.GetKv().value(), unpacked_data->GetKv().value());
EXPECT_EQ(kExpectedData.GetKa().value(), unpacked_data->GetKa().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/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());
}

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/kinematics/ChassisSpeeds.h"
@@ -11,19 +11,19 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::ChassisSpeeds>;
const ChassisSpeeds kExpectedData =
ChassisSpeeds{2.29_mps, 2.2_mps, 0.3504_rad_per_s};
} // namespace
TEST(ChassisSpeedsProtoTest, 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;
ChassisSpeeds unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.vx.value(), unpacked_data.vx.value());
EXPECT_EQ(kExpectedData.vy.value(), unpacked_data.vy.value());
EXPECT_EQ(kExpectedData.omega.value(), unpacked_data.omega.value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.vx.value(), unpacked_data->vx.value());
EXPECT_EQ(kExpectedData.vy.value(), unpacked_data->vy.value());
EXPECT_EQ(kExpectedData.omega.value(), unpacked_data->omega.value());
}

View File

@@ -4,6 +4,7 @@
#include <google/protobuf/arena.h>
#include <gtest/gtest.h>
#include <wpi/SmallVector.h>
#include "frc/kinematics/DifferentialDriveKinematics.h"
@@ -11,17 +12,18 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::DifferentialDriveKinematics>;
const DifferentialDriveKinematics kExpectedData =
DifferentialDriveKinematics{1.74_m};
} // namespace
TEST(DifferentialDriveKinematicsProtoTest, 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;
DifferentialDriveKinematics unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.trackWidth.value(), unpacked_data.trackWidth.value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.trackWidth.value(),
unpacked_data->trackWidth.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/kinematics/DifferentialDriveWheelSpeeds.h"
@@ -11,18 +11,18 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::DifferentialDriveWheelSpeeds>;
const DifferentialDriveWheelSpeeds kExpectedData =
DifferentialDriveWheelSpeeds{1.74_mps, 35.04_mps};
} // namespace
TEST(DifferentialDriveWheelSpeedsProtoTest, 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;
DifferentialDriveWheelSpeeds unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.left.value(), unpacked_data.left.value());
EXPECT_EQ(kExpectedData.right.value(), unpacked_data.right.value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.left.value(), unpacked_data->left.value());
EXPECT_EQ(kExpectedData.right.value(), unpacked_data->right.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/kinematics/MecanumDriveKinematics.h"
@@ -11,21 +11,21 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::MecanumDriveKinematics>;
const MecanumDriveKinematics kExpectedData = MecanumDriveKinematics{
Translation2d{19.1_m, 2.2_m}, Translation2d{35.04_m, 1.91_m},
Translation2d{1.74_m, 3.504_m}, Translation2d{3.504_m, 1.91_m}};
} // namespace
TEST(MecanumDriveKinematicsProtoTest, 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;
MecanumDriveKinematics unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.GetFrontLeft(), unpacked_data.GetFrontLeft());
EXPECT_EQ(kExpectedData.GetFrontRight(), unpacked_data.GetFrontRight());
EXPECT_EQ(kExpectedData.GetRearLeft(), unpacked_data.GetRearLeft());
EXPECT_EQ(kExpectedData.GetRearRight(), unpacked_data.GetRearRight());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.GetFrontLeft(), unpacked_data->GetFrontLeft());
EXPECT_EQ(kExpectedData.GetFrontRight(), unpacked_data->GetFrontRight());
EXPECT_EQ(kExpectedData.GetRearLeft(), unpacked_data->GetRearLeft());
EXPECT_EQ(kExpectedData.GetRearRight(), unpacked_data->GetRearRight());
}

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/kinematics/MecanumDriveWheelPositions.h"
@@ -11,20 +11,21 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::MecanumDriveWheelPositions>;
const MecanumDriveWheelPositions kExpectedData =
MecanumDriveWheelPositions{17.4_m, 2.29_m, 22.9_m, 1.74_m};
} // namespace
TEST(MecanumDriveWheelPositionsProtoTest, 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;
MecanumDriveWheelPositions unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.frontLeft.value(), unpacked_data.frontLeft.value());
EXPECT_EQ(kExpectedData.frontRight.value(), unpacked_data.frontRight.value());
EXPECT_EQ(kExpectedData.rearLeft.value(), unpacked_data.rearLeft.value());
EXPECT_EQ(kExpectedData.rearRight.value(), unpacked_data.rearRight.value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.frontLeft.value(), unpacked_data->frontLeft.value());
EXPECT_EQ(kExpectedData.frontRight.value(),
unpacked_data->frontRight.value());
EXPECT_EQ(kExpectedData.rearLeft.value(), unpacked_data->rearLeft.value());
EXPECT_EQ(kExpectedData.rearRight.value(), unpacked_data->rearRight.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/kinematics/MecanumDriveWheelSpeeds.h"
@@ -11,20 +11,21 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::MecanumDriveWheelSpeeds>;
const MecanumDriveWheelSpeeds kExpectedData =
MecanumDriveWheelSpeeds{2.29_mps, 17.4_mps, 4.4_mps, 0.229_mps};
} // namespace
TEST(MecanumDriveWheelSpeedsProtoTest, 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;
MecanumDriveWheelSpeeds unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.frontLeft.value(), unpacked_data.frontLeft.value());
EXPECT_EQ(kExpectedData.frontRight.value(), unpacked_data.frontRight.value());
EXPECT_EQ(kExpectedData.rearLeft.value(), unpacked_data.rearLeft.value());
EXPECT_EQ(kExpectedData.rearRight.value(), unpacked_data.rearRight.value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.frontLeft.value(), unpacked_data->frontLeft.value());
EXPECT_EQ(kExpectedData.frontRight.value(),
unpacked_data->frontRight.value());
EXPECT_EQ(kExpectedData.rearLeft.value(), unpacked_data->rearLeft.value());
EXPECT_EQ(kExpectedData.rearRight.value(), unpacked_data->rearRight.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/kinematics/SwerveModulePosition.h"
@@ -11,18 +11,18 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::SwerveModulePosition>;
const SwerveModulePosition kExpectedData =
SwerveModulePosition{3.504_m, Rotation2d{17.4_rad}};
} // namespace
TEST(SwerveModulePositionProtoTest, 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;
SwerveModulePosition unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.distance.value(), unpacked_data.distance.value());
EXPECT_EQ(kExpectedData.angle, unpacked_data.angle);
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.distance.value(), unpacked_data->distance.value());
EXPECT_EQ(kExpectedData.angle, unpacked_data->angle);
}

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/kinematics/SwerveModuleState.h"
@@ -11,18 +11,18 @@ using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::SwerveModuleState>;
const SwerveModuleState kExpectedData =
SwerveModuleState{22.9_mps, Rotation2d{3.3_rad}};
} // namespace
TEST(SwerveModuleStateProtoTest, 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;
SwerveModuleState unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.speed.value(), unpacked_data.speed.value());
EXPECT_EQ(kExpectedData.angle, unpacked_data.angle);
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.speed.value(), unpacked_data->speed.value());
EXPECT_EQ(kExpectedData.angle, unpacked_data->angle);
}

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/system/plant/DCMotor.h"
@@ -15,21 +15,23 @@ inline constexpr DCMotor kExpectedData =
DCMotor{1.91_V, 19.1_Nm, 1.74_A, 2.29_A, 2.2_rad_per_s, 2};
TEST(DCMotorProtoTest, 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;
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
DCMotor unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.nominalVoltage.value(),
unpacked_data.nominalVoltage.value());
unpacked_data->nominalVoltage.value());
EXPECT_EQ(kExpectedData.stallTorque.value(),
unpacked_data.stallTorque.value());
unpacked_data->stallTorque.value());
EXPECT_EQ(kExpectedData.stallCurrent.value(),
unpacked_data.stallCurrent.value());
unpacked_data->stallCurrent.value());
EXPECT_EQ(kExpectedData.freeCurrent.value(),
unpacked_data.freeCurrent.value());
EXPECT_EQ(kExpectedData.freeSpeed.value(), unpacked_data.freeSpeed.value());
EXPECT_EQ(kExpectedData.R.value(), unpacked_data.R.value());
EXPECT_EQ(kExpectedData.Kv.value(), unpacked_data.Kv.value());
EXPECT_EQ(kExpectedData.Kt.value(), unpacked_data.Kt.value());
unpacked_data->freeCurrent.value());
EXPECT_EQ(kExpectedData.freeSpeed.value(), unpacked_data->freeSpeed.value());
EXPECT_EQ(kExpectedData.R.value(), unpacked_data->R.value());
EXPECT_EQ(kExpectedData.Kv.value(), unpacked_data->Kv.value());
EXPECT_EQ(kExpectedData.Kt.value(), unpacked_data->Kt.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/trajectory/Trajectory.h"
@@ -26,10 +26,11 @@ const Trajectory kExpectedData = Trajectory{std::vector<frc::Trajectory::State>{
} // namespace
TEST(TrajectoryProtoTest, 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;
Trajectory unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.States(), unpacked_data.States());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.States(), unpacked_data->States());
}

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/trajectory/Trajectory.h"
@@ -20,15 +20,17 @@ const Trajectory::State kExpectedData = Trajectory::State{
} // namespace
TEST(TrajectoryStateProtoTest, 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;
Trajectory::State unpacked_data = ProtoType::Unpack(*proto);
EXPECT_EQ(kExpectedData.t.value(), unpacked_data.t.value());
EXPECT_EQ(kExpectedData.velocity.value(), unpacked_data.velocity.value());
ASSERT_TRUE(message.Pack(buf, kExpectedData));
auto unpacked_data = message.Unpack(buf);
ASSERT_TRUE(unpacked_data.has_value());
EXPECT_EQ(kExpectedData.t.value(), unpacked_data->t.value());
EXPECT_EQ(kExpectedData.velocity.value(), unpacked_data->velocity.value());
EXPECT_EQ(kExpectedData.acceleration.value(),
unpacked_data.acceleration.value());
EXPECT_EQ(kExpectedData.pose, unpacked_data.pose);
EXPECT_EQ(kExpectedData.curvature.value(), unpacked_data.curvature.value());
unpacked_data->acceleration.value());
EXPECT_EQ(kExpectedData.pose, unpacked_data->pose);
EXPECT_EQ(kExpectedData.curvature.value(), unpacked_data->curvature.value());
}