[wpiutil] Change Struct to allow non-constexpr implementation (#5992)

This required changing the constant values (e.g. kSize) into functions
(e.g. GetSize()).

Fixed implementations of ForEachNested to be inline (as these are actually
templates).

Also added a ntcore Struct test.
This commit is contained in:
Peter Johnson
2023-12-02 23:36:44 -08:00
committed by GitHub
parent ca272de400
commit a583ca01e1
62 changed files with 812 additions and 450 deletions

View File

@@ -16,8 +16,8 @@ const ChassisSpeeds kExpectedData{
} // namespace
TEST(ChassisSpeedsStructTest, Roundtrip) {
uint8_t buffer[StructType::kSize];
std::memset(buffer, 0, StructType::kSize);
uint8_t buffer[StructType::GetSize()];
std::memset(buffer, 0, StructType::GetSize());
StructType::Pack(buffer, kExpectedData);
ChassisSpeeds unpacked_data = StructType::Unpack(buffer);

View File

@@ -16,8 +16,8 @@ const DifferentialDriveKinematics kExpectedData{
} // namespace
TEST(DifferentialDriveKinematicsStructTest, Roundtrip) {
uint8_t buffer[StructType::kSize];
std::memset(buffer, 0, StructType::kSize);
uint8_t buffer[StructType::GetSize()];
std::memset(buffer, 0, StructType::GetSize());
StructType::Pack(buffer, kExpectedData);
DifferentialDriveKinematics unpacked_data = StructType::Unpack(buffer);

View File

@@ -16,8 +16,8 @@ const DifferentialDriveWheelSpeeds kExpectedData{
} // namespace
TEST(DifferentialDriveWheelSpeedsStructTest, Roundtrip) {
uint8_t buffer[StructType::kSize];
std::memset(buffer, 0, StructType::kSize);
uint8_t buffer[StructType::GetSize()];
std::memset(buffer, 0, StructType::GetSize());
StructType::Pack(buffer, kExpectedData);
DifferentialDriveWheelSpeeds unpacked_data = StructType::Unpack(buffer);

View File

@@ -17,8 +17,8 @@ const MecanumDriveKinematics kExpectedData{MecanumDriveKinematics{
} // namespace
TEST(MecanumDriveKinematicsStructTest, Roundtrip) {
uint8_t buffer[StructType::kSize];
std::memset(buffer, 0, StructType::kSize);
uint8_t buffer[StructType::GetSize()];
std::memset(buffer, 0, StructType::GetSize());
StructType::Pack(buffer, kExpectedData);
MecanumDriveKinematics unpacked_data = StructType::Unpack(buffer);

View File

@@ -16,8 +16,8 @@ const MecanumDriveWheelPositions kExpectedData{
} // namespace
TEST(MecanumDriveWheelPositionsStructTest, Roundtrip) {
uint8_t buffer[StructType::kSize];
std::memset(buffer, 0, StructType::kSize);
uint8_t buffer[StructType::GetSize()];
std::memset(buffer, 0, StructType::GetSize());
StructType::Pack(buffer, kExpectedData);
MecanumDriveWheelPositions unpacked_data = StructType::Unpack(buffer);

View File

@@ -16,8 +16,8 @@ const MecanumDriveWheelSpeeds kExpectedData{
} // namespace
TEST(MecanumDriveWheelSpeedsStructTest, Roundtrip) {
uint8_t buffer[StructType::kSize];
std::memset(buffer, 0, StructType::kSize);
uint8_t buffer[StructType::GetSize()];
std::memset(buffer, 0, StructType::GetSize());
StructType::Pack(buffer, kExpectedData);
MecanumDriveWheelSpeeds unpacked_data = StructType::Unpack(buffer);

View File

@@ -16,8 +16,8 @@ const SwerveModulePosition kExpectedData{
} // namespace
TEST(SwerveModulePositionStructTest, Roundtrip) {
uint8_t buffer[StructType::kSize];
std::memset(buffer, 0, StructType::kSize);
uint8_t buffer[StructType::GetSize()];
std::memset(buffer, 0, StructType::GetSize());
StructType::Pack(buffer, kExpectedData);
SwerveModulePosition unpacked_data = StructType::Unpack(buffer);

View File

@@ -16,8 +16,8 @@ const SwerveModuleState kExpectedData{
} // namespace
TEST(SwerveModuleStateStructTest, Roundtrip) {
uint8_t buffer[StructType::kSize];
std::memset(buffer, 0, StructType::kSize);
uint8_t buffer[StructType::GetSize()];
std::memset(buffer, 0, StructType::GetSize());
StructType::Pack(buffer, kExpectedData);
SwerveModuleState unpacked_data = StructType::Unpack(buffer);