diff --git a/wpimath/src/main/native/cpp/controller/struct/ArmFeedforwardStruct.cpp b/wpimath/src/main/native/cpp/controller/struct/ArmFeedforwardStruct.cpp index 0e6e8165ca..6b0070cb1e 100644 --- a/wpimath/src/main/native/cpp/controller/struct/ArmFeedforwardStruct.cpp +++ b/wpimath/src/main/native/cpp/controller/struct/ArmFeedforwardStruct.cpp @@ -13,7 +13,7 @@ constexpr size_t kKaOff = kKvOff + 8; using StructType = wpi::Struct; -frc::ArmFeedforward StructType::Unpack(std::span data) { +frc::ArmFeedforward StructType::Unpack(std::span data) { return frc::ArmFeedforward{ units::volt_t{wpi::UnpackStruct(data)}, units::volt_t{wpi::UnpackStruct(data)}, @@ -24,7 +24,7 @@ frc::ArmFeedforward StructType::Unpack(std::span data) { }; } -void StructType::Pack(std::span data, +void StructType::Pack(std::span data, const frc::ArmFeedforward& value) { wpi::PackStruct(data, value.kS()); wpi::PackStruct(data, value.kG()); diff --git a/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStruct.cpp b/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStruct.cpp index c056638eaf..22a79302b6 100644 --- a/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStruct.cpp +++ b/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStruct.cpp @@ -12,14 +12,14 @@ constexpr size_t kRightOff = kLeftOff + 8; using StructType = wpi::Struct; frc::DifferentialDriveWheelVoltages StructType::Unpack( - std::span data) { + std::span data) { return frc::DifferentialDriveWheelVoltages{ units::volt_t{wpi::UnpackStruct(data)}, units::volt_t{wpi::UnpackStruct(data)}, }; } -void StructType::Pack(std::span data, +void StructType::Pack(std::span data, const frc::DifferentialDriveWheelVoltages& value) { wpi::PackStruct(data, value.left.value()); wpi::PackStruct(data, value.right.value()); diff --git a/wpimath/src/main/native/cpp/controller/struct/ElevatorFeedforwardStruct.cpp b/wpimath/src/main/native/cpp/controller/struct/ElevatorFeedforwardStruct.cpp index 0572181c7f..ff28357bbb 100644 --- a/wpimath/src/main/native/cpp/controller/struct/ElevatorFeedforwardStruct.cpp +++ b/wpimath/src/main/native/cpp/controller/struct/ElevatorFeedforwardStruct.cpp @@ -13,8 +13,7 @@ constexpr size_t kKaOff = kKvOff + 8; using StructType = wpi::Struct; -frc::ElevatorFeedforward StructType::Unpack( - std::span data) { +frc::ElevatorFeedforward StructType::Unpack(std::span data) { return frc::ElevatorFeedforward{ units::volt_t{wpi::UnpackStruct(data)}, units::volt_t{wpi::UnpackStruct(data)}, @@ -25,7 +24,7 @@ frc::ElevatorFeedforward StructType::Unpack( }; } -void StructType::Pack(std::span data, +void StructType::Pack(std::span data, const frc::ElevatorFeedforward& value) { wpi::PackStruct(data, value.kS()); wpi::PackStruct(data, value.kG()); diff --git a/wpimath/src/main/native/cpp/system/plant/struct/DCMotorStruct.cpp b/wpimath/src/main/native/cpp/system/plant/struct/DCMotorStruct.cpp index 91438ca2c1..e7389a17ef 100644 --- a/wpimath/src/main/native/cpp/system/plant/struct/DCMotorStruct.cpp +++ b/wpimath/src/main/native/cpp/system/plant/struct/DCMotorStruct.cpp @@ -14,7 +14,7 @@ constexpr size_t kFreeSpeedOff = kFreeCurrentOff + 8; using StructType = wpi::Struct; -frc::DCMotor StructType::Unpack(std::span data) { +frc::DCMotor StructType::Unpack(std::span data) { return frc::DCMotor{ units::volt_t{wpi::UnpackStruct(data)}, units::newton_meter_t{wpi::UnpackStruct(data)}, @@ -25,8 +25,7 @@ frc::DCMotor StructType::Unpack(std::span data) { }; } -void StructType::Pack(std::span data, - const frc::DCMotor& value) { +void StructType::Pack(std::span data, const frc::DCMotor& value) { wpi::PackStruct(data, value.nominalVoltage.value()); wpi::PackStruct(data, value.stallTorque.value()); wpi::PackStruct(data, value.stallCurrent.value()); diff --git a/wpimath/src/main/native/include/frc/controller/struct/ArmFeedforwardStruct.h b/wpimath/src/main/native/include/frc/controller/struct/ArmFeedforwardStruct.h index 3f427da9d8..cfc585cb32 100644 --- a/wpimath/src/main/native/include/frc/controller/struct/ArmFeedforwardStruct.h +++ b/wpimath/src/main/native/include/frc/controller/struct/ArmFeedforwardStruct.h @@ -11,12 +11,16 @@ template <> struct WPILIB_DLLEXPORT wpi::Struct { - static constexpr std::string_view kTypeString = "struct:ArmFeedforward"; - static constexpr size_t kSize = 32; - static constexpr std::string_view kSchema = - "double ks;double kg;double kv;double ka"; + static constexpr std::string_view GetTypeString() { + return "struct:ArmFeedforward"; + } + static constexpr size_t GetSize() { return 32; } + static constexpr std::string_view GetSchema() { + return "double ks;double kg;double kv;double ka"; + } - static frc::ArmFeedforward Unpack(std::span data); - static void Pack(std::span data, - const frc::ArmFeedforward& value); + static frc::ArmFeedforward Unpack(std::span data); + static void Pack(std::span data, const frc::ArmFeedforward& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/controller/struct/DifferentialDriveWheelVoltagesStruct.h b/wpimath/src/main/native/include/frc/controller/struct/DifferentialDriveWheelVoltagesStruct.h index dae20ed489..cb5311f691 100644 --- a/wpimath/src/main/native/include/frc/controller/struct/DifferentialDriveWheelVoltagesStruct.h +++ b/wpimath/src/main/native/include/frc/controller/struct/DifferentialDriveWheelVoltagesStruct.h @@ -11,13 +11,18 @@ template <> struct WPILIB_DLLEXPORT wpi::Struct { - static constexpr std::string_view kTypeString = - "struct:DifferentialDriveWheelVoltages"; - static constexpr size_t kSize = 16; - static constexpr std::string_view kSchema = "double left;double right"; + static constexpr std::string_view GetTypeString() { + return "struct:DifferentialDriveWheelVoltages"; + } + static constexpr size_t GetSize() { return 16; } + static constexpr std::string_view GetSchema() { + return "double left;double right"; + } static frc::DifferentialDriveWheelVoltages Unpack( - std::span data); - static void Pack(std::span data, + std::span data); + static void Pack(std::span data, const frc::DifferentialDriveWheelVoltages& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/controller/struct/ElevatorFeedforwardStruct.h b/wpimath/src/main/native/include/frc/controller/struct/ElevatorFeedforwardStruct.h index 89c03f8fea..fafb7d73ec 100644 --- a/wpimath/src/main/native/include/frc/controller/struct/ElevatorFeedforwardStruct.h +++ b/wpimath/src/main/native/include/frc/controller/struct/ElevatorFeedforwardStruct.h @@ -11,12 +11,17 @@ template <> struct WPILIB_DLLEXPORT wpi::Struct { - static constexpr std::string_view kTypeString = "struct:ElevatorFeedforward"; - static constexpr size_t kSize = 32; - static constexpr std::string_view kSchema = - "double ks;double kg;double kv;double ka"; + static constexpr std::string_view GetTypeString() { + return "struct:ElevatorFeedforward"; + } + static constexpr size_t GetSize() { return 32; } + static constexpr std::string_view GetSchema() { + return "double ks;double kg;double kv;double ka"; + } - static frc::ElevatorFeedforward Unpack(std::span data); - static void Pack(std::span data, + static frc::ElevatorFeedforward Unpack(std::span data); + static void Pack(std::span data, const frc::ElevatorFeedforward& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/geometry/struct/Pose2dStruct.h b/wpimath/src/main/native/include/frc/geometry/struct/Pose2dStruct.h index a76eed546d..66e3295f91 100644 --- a/wpimath/src/main/native/include/frc/geometry/struct/Pose2dStruct.h +++ b/wpimath/src/main/native/include/frc/geometry/struct/Pose2dStruct.h @@ -29,4 +29,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { } }; +static_assert(wpi::StructSerializable); static_assert(wpi::HasNestedStruct); diff --git a/wpimath/src/main/native/include/frc/geometry/struct/Pose3dStruct.h b/wpimath/src/main/native/include/frc/geometry/struct/Pose3dStruct.h index e3c2eb489e..f47ffec964 100644 --- a/wpimath/src/main/native/include/frc/geometry/struct/Pose3dStruct.h +++ b/wpimath/src/main/native/include/frc/geometry/struct/Pose3dStruct.h @@ -29,4 +29,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { } }; +static_assert(wpi::StructSerializable); static_assert(wpi::HasNestedStruct); diff --git a/wpimath/src/main/native/include/frc/geometry/struct/QuaternionStruct.h b/wpimath/src/main/native/include/frc/geometry/struct/QuaternionStruct.h index 06410325fb..80420c0774 100644 --- a/wpimath/src/main/native/include/frc/geometry/struct/QuaternionStruct.h +++ b/wpimath/src/main/native/include/frc/geometry/struct/QuaternionStruct.h @@ -22,3 +22,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { static frc::Quaternion Unpack(std::span data); static void Pack(std::span data, const frc::Quaternion& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/geometry/struct/Rotation2dStruct.h b/wpimath/src/main/native/include/frc/geometry/struct/Rotation2dStruct.h index 127a2027af..85b6ae5178 100644 --- a/wpimath/src/main/native/include/frc/geometry/struct/Rotation2dStruct.h +++ b/wpimath/src/main/native/include/frc/geometry/struct/Rotation2dStruct.h @@ -20,3 +20,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { static frc::Rotation2d Unpack(std::span data); static void Pack(std::span data, const frc::Rotation2d& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/geometry/struct/Rotation3dStruct.h b/wpimath/src/main/native/include/frc/geometry/struct/Rotation3dStruct.h index d1cc1f0ca8..e94b75ee4b 100644 --- a/wpimath/src/main/native/include/frc/geometry/struct/Rotation3dStruct.h +++ b/wpimath/src/main/native/include/frc/geometry/struct/Rotation3dStruct.h @@ -27,4 +27,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { } }; +static_assert(wpi::StructSerializable); static_assert(wpi::HasNestedStruct); diff --git a/wpimath/src/main/native/include/frc/geometry/struct/Transform2dStruct.h b/wpimath/src/main/native/include/frc/geometry/struct/Transform2dStruct.h index 36438b577b..28ef463ab1 100644 --- a/wpimath/src/main/native/include/frc/geometry/struct/Transform2dStruct.h +++ b/wpimath/src/main/native/include/frc/geometry/struct/Transform2dStruct.h @@ -31,4 +31,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { } }; +static_assert(wpi::StructSerializable); static_assert(wpi::HasNestedStruct); diff --git a/wpimath/src/main/native/include/frc/geometry/struct/Transform3dStruct.h b/wpimath/src/main/native/include/frc/geometry/struct/Transform3dStruct.h index f4de9cafad..e4e88bcf49 100644 --- a/wpimath/src/main/native/include/frc/geometry/struct/Transform3dStruct.h +++ b/wpimath/src/main/native/include/frc/geometry/struct/Transform3dStruct.h @@ -31,4 +31,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { } }; +static_assert(wpi::StructSerializable); static_assert(wpi::HasNestedStruct); diff --git a/wpimath/src/main/native/include/frc/geometry/struct/Translation2dStruct.h b/wpimath/src/main/native/include/frc/geometry/struct/Translation2dStruct.h index a1c77e9003..df12760f85 100644 --- a/wpimath/src/main/native/include/frc/geometry/struct/Translation2dStruct.h +++ b/wpimath/src/main/native/include/frc/geometry/struct/Translation2dStruct.h @@ -20,3 +20,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { static frc::Translation2d Unpack(std::span data); static void Pack(std::span data, const frc::Translation2d& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/geometry/struct/Translation3dStruct.h b/wpimath/src/main/native/include/frc/geometry/struct/Translation3dStruct.h index 255e9ac900..b61a8758c6 100644 --- a/wpimath/src/main/native/include/frc/geometry/struct/Translation3dStruct.h +++ b/wpimath/src/main/native/include/frc/geometry/struct/Translation3dStruct.h @@ -22,3 +22,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { static frc::Translation3d Unpack(std::span data); static void Pack(std::span data, const frc::Translation3d& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/geometry/struct/Twist2dStruct.h b/wpimath/src/main/native/include/frc/geometry/struct/Twist2dStruct.h index adff1294b2..86bb4ada36 100644 --- a/wpimath/src/main/native/include/frc/geometry/struct/Twist2dStruct.h +++ b/wpimath/src/main/native/include/frc/geometry/struct/Twist2dStruct.h @@ -20,3 +20,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { static frc::Twist2d Unpack(std::span data); static void Pack(std::span data, const frc::Twist2d& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/geometry/struct/Twist3dStruct.h b/wpimath/src/main/native/include/frc/geometry/struct/Twist3dStruct.h index 64ca8abd3d..a346a1ad80 100644 --- a/wpimath/src/main/native/include/frc/geometry/struct/Twist3dStruct.h +++ b/wpimath/src/main/native/include/frc/geometry/struct/Twist3dStruct.h @@ -20,3 +20,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { static frc::Twist3d Unpack(std::span data); static void Pack(std::span data, const frc::Twist3d& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/kinematics/struct/ChassisSpeedsStruct.h b/wpimath/src/main/native/include/frc/kinematics/struct/ChassisSpeedsStruct.h index e8b6395910..8c65057da9 100644 --- a/wpimath/src/main/native/include/frc/kinematics/struct/ChassisSpeedsStruct.h +++ b/wpimath/src/main/native/include/frc/kinematics/struct/ChassisSpeedsStruct.h @@ -22,3 +22,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { static frc::ChassisSpeeds Unpack(std::span data); static void Pack(std::span data, const frc::ChassisSpeeds& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/kinematics/struct/DifferentialDriveKinematicsStruct.h b/wpimath/src/main/native/include/frc/kinematics/struct/DifferentialDriveKinematicsStruct.h index 79b44f65fb..0acbc76e47 100644 --- a/wpimath/src/main/native/include/frc/kinematics/struct/DifferentialDriveKinematicsStruct.h +++ b/wpimath/src/main/native/include/frc/kinematics/struct/DifferentialDriveKinematicsStruct.h @@ -21,3 +21,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { static void Pack(std::span data, const frc::DifferentialDriveKinematics& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/kinematics/struct/DifferentialDriveWheelSpeedsStruct.h b/wpimath/src/main/native/include/frc/kinematics/struct/DifferentialDriveWheelSpeedsStruct.h index 0680020604..12dc8431eb 100644 --- a/wpimath/src/main/native/include/frc/kinematics/struct/DifferentialDriveWheelSpeedsStruct.h +++ b/wpimath/src/main/native/include/frc/kinematics/struct/DifferentialDriveWheelSpeedsStruct.h @@ -24,3 +24,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { static void Pack(std::span data, const frc::DifferentialDriveWheelSpeeds& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveKinematicsStruct.h b/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveKinematicsStruct.h index 4dde54b1a2..a4fe3bddca 100644 --- a/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveKinematicsStruct.h +++ b/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveKinematicsStruct.h @@ -31,4 +31,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { } }; +static_assert(wpi::StructSerializable); static_assert(wpi::HasNestedStruct); diff --git a/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveWheelPositionsStruct.h b/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveWheelPositionsStruct.h index f14c3749b8..87b5f38624 100644 --- a/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveWheelPositionsStruct.h +++ b/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveWheelPositionsStruct.h @@ -24,3 +24,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { static void Pack(std::span data, const frc::MecanumDriveWheelPositions& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveWheelSpeedsStruct.h b/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveWheelSpeedsStruct.h index b0b0608c19..28f28e8c22 100644 --- a/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveWheelSpeedsStruct.h +++ b/wpimath/src/main/native/include/frc/kinematics/struct/MecanumDriveWheelSpeedsStruct.h @@ -24,3 +24,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { static void Pack(std::span data, const frc::MecanumDriveWheelSpeeds& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/main/native/include/frc/kinematics/struct/SwerveModulePositionStruct.h b/wpimath/src/main/native/include/frc/kinematics/struct/SwerveModulePositionStruct.h index ac0f852bf9..ee58a2c7cd 100644 --- a/wpimath/src/main/native/include/frc/kinematics/struct/SwerveModulePositionStruct.h +++ b/wpimath/src/main/native/include/frc/kinematics/struct/SwerveModulePositionStruct.h @@ -30,4 +30,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { } }; +static_assert(wpi::StructSerializable); static_assert(wpi::HasNestedStruct); diff --git a/wpimath/src/main/native/include/frc/kinematics/struct/SwerveModuleStateStruct.h b/wpimath/src/main/native/include/frc/kinematics/struct/SwerveModuleStateStruct.h index 589eb2a60d..06885fed51 100644 --- a/wpimath/src/main/native/include/frc/kinematics/struct/SwerveModuleStateStruct.h +++ b/wpimath/src/main/native/include/frc/kinematics/struct/SwerveModuleStateStruct.h @@ -30,4 +30,5 @@ struct WPILIB_DLLEXPORT wpi::Struct { } }; +static_assert(wpi::StructSerializable); static_assert(wpi::HasNestedStruct); diff --git a/wpimath/src/main/native/include/frc/system/plant/struct/DCMotorStruct.h b/wpimath/src/main/native/include/frc/system/plant/struct/DCMotorStruct.h index c16b65b4d6..22a6405d9a 100644 --- a/wpimath/src/main/native/include/frc/system/plant/struct/DCMotorStruct.h +++ b/wpimath/src/main/native/include/frc/system/plant/struct/DCMotorStruct.h @@ -11,12 +11,16 @@ template <> struct WPILIB_DLLEXPORT wpi::Struct { - static constexpr std::string_view kTypeString = "struct:DCMotor"; - static constexpr size_t kSize = 40; - static constexpr std::string_view kSchema = - "double nominal_voltage;double stall_torque;double stall_current;double " - "free_current;double free_speed"; + static constexpr std::string_view GetTypeString() { return "struct:DCMotor"; } + static constexpr size_t GetSize() { return 40; } + static constexpr std::string_view GetSchema() { + return "double nominal_voltage;double stall_torque;double " + "stall_current;double " + "free_current;double free_speed"; + } - static frc::DCMotor Unpack(std::span data); - static void Pack(std::span data, const frc::DCMotor& value); + static frc::DCMotor Unpack(std::span data); + static void Pack(std::span data, const frc::DCMotor& value); }; + +static_assert(wpi::StructSerializable); diff --git a/wpimath/src/test/native/cpp/controller/struct/ArmFeedforwardStructTest.cpp b/wpimath/src/test/native/cpp/controller/struct/ArmFeedforwardStructTest.cpp index 453061c56e..a76f52585a 100644 --- a/wpimath/src/test/native/cpp/controller/struct/ArmFeedforwardStructTest.cpp +++ b/wpimath/src/test/native/cpp/controller/struct/ArmFeedforwardStructTest.cpp @@ -20,8 +20,8 @@ const ArmFeedforward kExpectedData{Ks, Kg, Kv, Ka}; } // namespace TEST(ArmFeedforwardStructTest, 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); ArmFeedforward unpacked_data = StructType::Unpack(buffer); diff --git a/wpimath/src/test/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStructTest.cpp b/wpimath/src/test/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStructTest.cpp index 2b47e5a538..c72ac4aac9 100644 --- a/wpimath/src/test/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStructTest.cpp +++ b/wpimath/src/test/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStructTest.cpp @@ -16,8 +16,8 @@ const DifferentialDriveWheelVoltages kExpectedData{ } // namespace TEST(DifferentialDriveWheelVoltagesStructTest, 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); DifferentialDriveWheelVoltages unpacked_data = StructType::Unpack(buffer); diff --git a/wpimath/src/test/native/cpp/controller/struct/ElevatorFeedforwardStructTest.cpp b/wpimath/src/test/native/cpp/controller/struct/ElevatorFeedforwardStructTest.cpp index 299d39a34b..2e5c43a231 100644 --- a/wpimath/src/test/native/cpp/controller/struct/ElevatorFeedforwardStructTest.cpp +++ b/wpimath/src/test/native/cpp/controller/struct/ElevatorFeedforwardStructTest.cpp @@ -21,8 +21,8 @@ constexpr ElevatorFeedforward kExpectedData{Ks, Kg, Kv, Ka}; } // namespace TEST(ElevatorFeedforwardStructTest, 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); ElevatorFeedforward unpacked_data = StructType::Unpack(buffer); diff --git a/wpimath/src/test/native/cpp/system/plant/struct/DCMotorStructTest.cpp b/wpimath/src/test/native/cpp/system/plant/struct/DCMotorStructTest.cpp index 30306d2d5f..50d5c8b560 100644 --- a/wpimath/src/test/native/cpp/system/plant/struct/DCMotorStructTest.cpp +++ b/wpimath/src/test/native/cpp/system/plant/struct/DCMotorStructTest.cpp @@ -20,8 +20,8 @@ const DCMotor kExpectedData = DCMotor{units::volt_t{1.91}, } // namespace TEST(DCMotorStructTest, 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); DCMotor unpacked_data = StructType::Unpack(buffer); diff --git a/wpiutil/src/main/native/include/wpi/struct/Struct.h b/wpiutil/src/main/native/include/wpi/struct/Struct.h index 530607acda..58aca475d9 100644 --- a/wpiutil/src/main/native/include/wpi/struct/Struct.h +++ b/wpiutil/src/main/native/include/wpi/struct/Struct.h @@ -51,8 +51,8 @@ struct Struct {}; * - std::string_view GetTypeString(): function that returns the type string * - size_t GetSize(): function that returns the structure size in bytes * - std::string_view GetSchema(): function that returns the struct schema - * - T Unpack(std::span): function for deserialization - * - void Pack(std::span, T&& value): function for + * - T Unpack(std::span): function for deserialization + * - void Pack(std::span, T&& value): function for * serialization * * If possible, the GetTypeString(), GetSize(), and GetSchema() functions should @@ -411,9 +411,9 @@ struct Struct { */ template <> struct Struct { - static constexpr std::string_view kTypeString = "struct:int8"; - static constexpr size_t kSize = 1; - static constexpr std::string_view kSchema = "int8 value"; + static constexpr std::string_view GetTypeString() { return "struct:int8"; } + static constexpr size_t GetSize() { return 1; } + static constexpr std::string_view GetSchema() { return "int8 value"; } static int8_t Unpack(std::span data) { return data[0]; } static void Pack(std::span data, int8_t value) { data[0] = value;