[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

@@ -7,26 +7,19 @@
namespace {
constexpr size_t kTranslationOff = 0;
constexpr size_t kRotationOff =
kTranslationOff + wpi::Struct<frc::Translation2d>::kSize;
kTranslationOff + wpi::GetStructSize<frc::Translation2d>();
} // namespace
using StructType = wpi::Struct<frc::Pose2d>;
frc::Pose2d StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::Pose2d StructType::Unpack(std::span<const uint8_t> data) {
return frc::Pose2d{
wpi::UnpackStruct<frc::Translation2d, kTranslationOff>(data),
wpi::UnpackStruct<frc::Rotation2d, kRotationOff>(data),
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
const frc::Pose2d& value) {
void StructType::Pack(std::span<uint8_t> data, const frc::Pose2d& value) {
wpi::PackStruct<kTranslationOff>(data, value.Translation());
wpi::PackStruct<kRotationOff>(data, value.Rotation());
}
void StructType::ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation2d>(fn);
wpi::ForEachStructSchema<frc::Rotation2d>(fn);
}

View File

@@ -7,26 +7,19 @@
namespace {
constexpr size_t kTranslationOff = 0;
constexpr size_t kRotationOff =
kTranslationOff + wpi::Struct<frc::Translation3d>::kSize;
kTranslationOff + wpi::GetStructSize<frc::Translation3d>();
} // namespace
using StructType = wpi::Struct<frc::Pose3d>;
frc::Pose3d StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::Pose3d StructType::Unpack(std::span<const uint8_t> data) {
return frc::Pose3d{
wpi::UnpackStruct<frc::Translation3d, kTranslationOff>(data),
wpi::UnpackStruct<frc::Rotation3d, kRotationOff>(data),
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
const frc::Pose3d& value) {
void StructType::Pack(std::span<uint8_t> data, const frc::Pose3d& value) {
wpi::PackStruct<kTranslationOff>(data, value.Translation());
wpi::PackStruct<kRotationOff>(data, value.Rotation());
}
void StructType::ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation3d>(fn);
wpi::ForEachStructSchema<frc::Rotation3d>(fn);
}

View File

@@ -13,7 +13,7 @@ constexpr size_t kZOff = kYOff + 8;
using StructType = wpi::Struct<frc::Quaternion>;
frc::Quaternion StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::Quaternion StructType::Unpack(std::span<const uint8_t> data) {
return frc::Quaternion{
wpi::UnpackStruct<double, kWOff>(data),
wpi::UnpackStruct<double, kXOff>(data),
@@ -22,8 +22,7 @@ frc::Quaternion StructType::Unpack(std::span<const uint8_t, kSize> data) {
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
const frc::Quaternion& value) {
void StructType::Pack(std::span<uint8_t> data, const frc::Quaternion& value) {
wpi::PackStruct<kWOff>(data, value.W());
wpi::PackStruct<kXOff>(data, value.X());
wpi::PackStruct<kYOff>(data, value.Y());

View File

@@ -10,13 +10,12 @@ constexpr size_t kValueOff = 0;
using StructType = wpi::Struct<frc::Rotation2d>;
frc::Rotation2d StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::Rotation2d StructType::Unpack(std::span<const uint8_t> data) {
return frc::Rotation2d{
units::radian_t{wpi::UnpackStruct<double, kValueOff>(data)},
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
const frc::Rotation2d& value) {
void StructType::Pack(std::span<uint8_t> data, const frc::Rotation2d& value) {
wpi::PackStruct<kValueOff>(data, value.Radians().value());
}

View File

@@ -10,18 +10,12 @@ constexpr size_t kQOff = 0;
using StructType = wpi::Struct<frc::Rotation3d>;
frc::Rotation3d StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::Rotation3d StructType::Unpack(std::span<const uint8_t> data) {
return frc::Rotation3d{
wpi::UnpackStruct<frc::Quaternion, kQOff>(data),
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
const frc::Rotation3d& value) {
void StructType::Pack(std::span<uint8_t> data, const frc::Rotation3d& value) {
wpi::PackStruct<kQOff>(data, value.GetQuaternion());
}
void StructType::ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Quaternion>(fn);
}

View File

@@ -7,26 +7,19 @@
namespace {
constexpr size_t kTranslationOff = 0;
constexpr size_t kRotationOff =
kTranslationOff + wpi::Struct<frc::Translation2d>::kSize;
kTranslationOff + wpi::GetStructSize<frc::Translation2d>();
} // namespace
using StructType = wpi::Struct<frc::Transform2d>;
frc::Transform2d StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::Transform2d StructType::Unpack(std::span<const uint8_t> data) {
return frc::Transform2d{
wpi::UnpackStruct<frc::Translation2d, kTranslationOff>(data),
wpi::UnpackStruct<frc::Rotation2d, kRotationOff>(data),
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
const frc::Transform2d& value) {
void StructType::Pack(std::span<uint8_t> data, const frc::Transform2d& value) {
wpi::PackStruct<kTranslationOff>(data, value.Translation());
wpi::PackStruct<kRotationOff>(data, value.Rotation());
}
void StructType::ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation2d>(fn);
wpi::ForEachStructSchema<frc::Rotation2d>(fn);
}

View File

@@ -7,26 +7,19 @@
namespace {
constexpr size_t kTranslationOff = 0;
constexpr size_t kRotationOff =
kTranslationOff + wpi::Struct<frc::Translation3d>::kSize;
kTranslationOff + wpi::GetStructSize<frc::Translation3d>();
} // namespace
using StructType = wpi::Struct<frc::Transform3d>;
frc::Transform3d StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::Transform3d StructType::Unpack(std::span<const uint8_t> data) {
return frc::Transform3d{
wpi::UnpackStruct<frc::Translation3d, kTranslationOff>(data),
wpi::UnpackStruct<frc::Rotation3d, kRotationOff>(data),
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
const frc::Transform3d& value) {
void StructType::Pack(std::span<uint8_t> data, const frc::Transform3d& value) {
wpi::PackStruct<kTranslationOff>(data, value.Translation());
wpi::PackStruct<kRotationOff>(data, value.Rotation());
}
void StructType::ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation3d>(fn);
wpi::ForEachStructSchema<frc::Rotation3d>(fn);
}

View File

@@ -11,14 +11,14 @@ constexpr size_t kYOff = kXOff + 8;
using StructType = wpi::Struct<frc::Translation2d>;
frc::Translation2d StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::Translation2d StructType::Unpack(std::span<const uint8_t> data) {
return frc::Translation2d{
units::meter_t{wpi::UnpackStruct<double, kXOff>(data)},
units::meter_t{wpi::UnpackStruct<double, kYOff>(data)},
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
void StructType::Pack(std::span<uint8_t> data,
const frc::Translation2d& value) {
wpi::PackStruct<kXOff>(data, value.X().value());
wpi::PackStruct<kYOff>(data, value.Y().value());

View File

@@ -12,7 +12,7 @@ constexpr size_t kZOff = kYOff + 8;
using StructType = wpi::Struct<frc::Translation3d>;
frc::Translation3d StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::Translation3d StructType::Unpack(std::span<const uint8_t> data) {
return frc::Translation3d{
units::meter_t{wpi::UnpackStruct<double, kXOff>(data)},
units::meter_t{wpi::UnpackStruct<double, kYOff>(data)},
@@ -20,7 +20,7 @@ frc::Translation3d StructType::Unpack(std::span<const uint8_t, kSize> data) {
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
void StructType::Pack(std::span<uint8_t> data,
const frc::Translation3d& value) {
wpi::PackStruct<kXOff>(data, value.X().value());
wpi::PackStruct<kYOff>(data, value.Y().value());

View File

@@ -12,7 +12,7 @@ constexpr size_t kDthetaOff = kDyOff + 8;
using StructType = wpi::Struct<frc::Twist2d>;
frc::Twist2d StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::Twist2d StructType::Unpack(std::span<const uint8_t> data) {
return frc::Twist2d{
units::meter_t{wpi::UnpackStruct<double, kDxOff>(data)},
units::meter_t{wpi::UnpackStruct<double, kDyOff>(data)},
@@ -20,8 +20,7 @@ frc::Twist2d StructType::Unpack(std::span<const uint8_t, kSize> data) {
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
const frc::Twist2d& value) {
void StructType::Pack(std::span<uint8_t> data, const frc::Twist2d& value) {
wpi::PackStruct<kDxOff>(data, value.dx.value());
wpi::PackStruct<kDyOff>(data, value.dy.value());
wpi::PackStruct<kDthetaOff>(data, value.dtheta.value());

View File

@@ -15,7 +15,7 @@ constexpr size_t kRzOff = kRyOff + 8;
using StructType = wpi::Struct<frc::Twist3d>;
frc::Twist3d StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::Twist3d StructType::Unpack(std::span<const uint8_t> data) {
return frc::Twist3d{
units::meter_t{wpi::UnpackStruct<double, kDxOff>(data)},
units::meter_t{wpi::UnpackStruct<double, kDyOff>(data)},
@@ -26,8 +26,7 @@ frc::Twist3d StructType::Unpack(std::span<const uint8_t, kSize> data) {
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
const frc::Twist3d& value) {
void StructType::Pack(std::span<uint8_t> data, const frc::Twist3d& value) {
wpi::PackStruct<kDxOff>(data, value.dx.value());
wpi::PackStruct<kDyOff>(data, value.dy.value());
wpi::PackStruct<kDzOff>(data, value.dz.value());

View File

@@ -12,7 +12,7 @@ constexpr size_t kOmegaOff = kVyOff + 8;
using StructType = wpi::Struct<frc::ChassisSpeeds>;
frc::ChassisSpeeds StructType::Unpack(std::span<const uint8_t, kSize> data) {
frc::ChassisSpeeds StructType::Unpack(std::span<const uint8_t> data) {
return frc::ChassisSpeeds{
units::meters_per_second_t{wpi::UnpackStruct<double, kVxOff>(data)},
units::meters_per_second_t{wpi::UnpackStruct<double, kVyOff>(data)},
@@ -20,7 +20,7 @@ frc::ChassisSpeeds StructType::Unpack(std::span<const uint8_t, kSize> data) {
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
void StructType::Pack(std::span<uint8_t> data,
const frc::ChassisSpeeds& value) {
wpi::PackStruct<kVxOff>(data, value.vx.value());
wpi::PackStruct<kVyOff>(data, value.vy.value());

View File

@@ -11,13 +11,13 @@ constexpr size_t kTrackWidthOff = 0;
using StructType = wpi::Struct<frc::DifferentialDriveKinematics>;
frc::DifferentialDriveKinematics StructType::Unpack(
std::span<const uint8_t, kSize> data) {
std::span<const uint8_t> data) {
return frc::DifferentialDriveKinematics{
units::meter_t{wpi::UnpackStruct<double, kTrackWidthOff>(data)},
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
void StructType::Pack(std::span<uint8_t> data,
const frc::DifferentialDriveKinematics& value) {
wpi::PackStruct<kTrackWidthOff>(data, value.trackWidth.value());
}

View File

@@ -12,14 +12,14 @@ constexpr size_t kRightOff = kLeftOff + 8;
using StructType = wpi::Struct<frc::DifferentialDriveWheelSpeeds>;
frc::DifferentialDriveWheelSpeeds StructType::Unpack(
std::span<const uint8_t, kSize> data) {
std::span<const uint8_t> data) {
return frc::DifferentialDriveWheelSpeeds{
units::meters_per_second_t{wpi::UnpackStruct<double, kLeftOff>(data)},
units::meters_per_second_t{wpi::UnpackStruct<double, kRightOff>(data)},
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
void StructType::Pack(std::span<uint8_t> data,
const frc::DifferentialDriveWheelSpeeds& value) {
wpi::PackStruct<kLeftOff>(data, value.left.value());
wpi::PackStruct<kRightOff>(data, value.right.value());

View File

@@ -7,17 +7,16 @@
namespace {
constexpr size_t kFrontLeftOff = 0;
constexpr size_t kFrontRightOff =
kFrontLeftOff + wpi::Struct<frc::Translation2d>::kSize;
kFrontLeftOff + wpi::GetStructSize<frc::Translation2d>();
constexpr size_t kRearLeftOff =
kFrontRightOff + wpi::Struct<frc::Translation2d>::kSize;
kFrontRightOff + wpi::GetStructSize<frc::Translation2d>();
constexpr size_t kRearRightOff =
kRearLeftOff + wpi::Struct<frc::Translation2d>::kSize;
kRearLeftOff + wpi::GetStructSize<frc::Translation2d>();
} // namespace
using StructType = wpi::Struct<frc::MecanumDriveKinematics>;
frc::MecanumDriveKinematics StructType::Unpack(
std::span<const uint8_t, kSize> data) {
frc::MecanumDriveKinematics StructType::Unpack(std::span<const uint8_t> data) {
return frc::MecanumDriveKinematics{
wpi::UnpackStruct<frc::Translation2d, kFrontLeftOff>(data),
wpi::UnpackStruct<frc::Translation2d, kFrontRightOff>(data),
@@ -26,15 +25,10 @@ frc::MecanumDriveKinematics StructType::Unpack(
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
void StructType::Pack(std::span<uint8_t> data,
const frc::MecanumDriveKinematics& value) {
wpi::PackStruct<kFrontLeftOff>(data, value.GetFrontLeftWheel());
wpi::PackStruct<kFrontRightOff>(data, value.GetFrontRightWheel());
wpi::PackStruct<kRearLeftOff>(data, value.GetRearLeftWheel());
wpi::PackStruct<kRearRightOff>(data, value.GetRearRightWheel());
}
void StructType::ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation2d>(fn);
}

View File

@@ -14,7 +14,7 @@ constexpr size_t kRearRightOff = kRearLeftOff + 8;
using StructType = wpi::Struct<frc::MecanumDriveWheelPositions>;
frc::MecanumDriveWheelPositions StructType::Unpack(
std::span<const uint8_t, kSize> data) {
std::span<const uint8_t> data) {
return frc::MecanumDriveWheelPositions{
units::meter_t{wpi::UnpackStruct<double, kFrontLeftOff>(data)},
units::meter_t{wpi::UnpackStruct<double, kFrontRightOff>(data)},
@@ -23,7 +23,7 @@ frc::MecanumDriveWheelPositions StructType::Unpack(
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
void StructType::Pack(std::span<uint8_t> data,
const frc::MecanumDriveWheelPositions& value) {
wpi::PackStruct<kFrontLeftOff>(data, value.frontLeft.value());
wpi::PackStruct<kFrontRightOff>(data, value.frontRight.value());

View File

@@ -13,8 +13,7 @@ constexpr size_t kRearRightOff = kRearLeftOff + 8;
using StructType = wpi::Struct<frc::MecanumDriveWheelSpeeds>;
frc::MecanumDriveWheelSpeeds StructType::Unpack(
std::span<const uint8_t, kSize> data) {
frc::MecanumDriveWheelSpeeds StructType::Unpack(std::span<const uint8_t> data) {
return frc::MecanumDriveWheelSpeeds{
units::meters_per_second_t{
wpi::UnpackStruct<double, kFrontLeftOff>(data)},
@@ -26,7 +25,7 @@ frc::MecanumDriveWheelSpeeds StructType::Unpack(
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
void StructType::Pack(std::span<uint8_t> data,
const frc::MecanumDriveWheelSpeeds& value) {
wpi::PackStruct<kFrontLeftOff>(data, value.frontLeft.value());
wpi::PackStruct<kFrontRightOff>(data, value.frontRight.value());

View File

@@ -11,21 +11,15 @@ constexpr size_t kAngleOff = kDistanceOff + 8;
using StructType = wpi::Struct<frc::SwerveModulePosition>;
frc::SwerveModulePosition StructType::Unpack(
std::span<const uint8_t, kSize> data) {
frc::SwerveModulePosition StructType::Unpack(std::span<const uint8_t> data) {
return frc::SwerveModulePosition{
units::meter_t{wpi::UnpackStruct<double, kDistanceOff>(data)},
wpi::UnpackStruct<frc::Rotation2d, kAngleOff>(data),
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
void StructType::Pack(std::span<uint8_t> data,
const frc::SwerveModulePosition& value) {
wpi::PackStruct<kDistanceOff>(data, value.distance.value());
wpi::PackStruct<kAngleOff>(data, value.angle);
}
void StructType::ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Rotation2d>(fn);
}

View File

@@ -11,21 +11,15 @@ constexpr size_t kAngleOff = kSpeedOff + 8;
using StructType = wpi::Struct<frc::SwerveModuleState>;
frc::SwerveModuleState StructType::Unpack(
std::span<const uint8_t, kSize> data) {
frc::SwerveModuleState StructType::Unpack(std::span<const uint8_t> data) {
return frc::SwerveModuleState{
units::meters_per_second_t{wpi::UnpackStruct<double, kSpeedOff>(data)},
wpi::UnpackStruct<frc::Rotation2d, kAngleOff>(data),
};
}
void StructType::Pack(std::span<uint8_t, kSize> data,
void StructType::Pack(std::span<uint8_t> data,
const frc::SwerveModuleState& value) {
wpi::PackStruct<kSpeedOff>(data, value.speed.value());
wpi::PackStruct<kAngleOff>(data, value.angle);
}
void StructType::ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Rotation2d>(fn);
}

View File

@@ -11,16 +11,22 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Pose2d> {
static constexpr std::string_view kTypeString = "struct:Pose2d";
static constexpr size_t kSize = wpi::Struct<frc::Translation2d>::kSize +
wpi::Struct<frc::Rotation2d>::kSize;
static constexpr std::string_view kSchema =
"Translation2d translation;Rotation2d rotation";
static constexpr std::string_view GetTypeString() { return "struct:Pose2d"; }
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Translation2d>() +
wpi::GetStructSize<frc::Rotation2d>();
}
static constexpr std::string_view GetSchema() {
return "Translation2d translation;Rotation2d rotation";
}
static frc::Pose2d Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data, const frc::Pose2d& value);
static frc::Pose2d Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::Pose2d& value);
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn);
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation2d>(fn);
wpi::ForEachStructSchema<frc::Rotation2d>(fn);
}
};
static_assert(wpi::HasNestedStruct<frc::Pose2d>);

View File

@@ -11,16 +11,22 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Pose3d> {
static constexpr std::string_view kTypeString = "struct:Pose3d";
static constexpr size_t kSize = wpi::Struct<frc::Translation3d>::kSize +
wpi::Struct<frc::Rotation3d>::kSize;
static constexpr std::string_view kSchema =
"Translation3d translation;Rotation3d rotation";
static constexpr std::string_view GetTypeString() { return "struct:Pose3d"; }
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Translation3d>() +
wpi::GetStructSize<frc::Rotation3d>();
}
static constexpr std::string_view GetSchema() {
return "Translation3d translation;Rotation3d rotation";
}
static frc::Pose3d Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data, const frc::Pose3d& value);
static frc::Pose3d Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::Pose3d& value);
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn);
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation3d>(fn);
wpi::ForEachStructSchema<frc::Rotation3d>(fn);
}
};
static_assert(wpi::HasNestedStruct<frc::Pose3d>);

View File

@@ -11,12 +11,14 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Quaternion> {
static constexpr std::string_view kTypeString = "struct:Quaternion";
static constexpr size_t kSize = 32;
static constexpr std::string_view kSchema =
"double w;double x;double y;double z";
static constexpr std::string_view GetTypeString() {
return "struct:Quaternion";
}
static constexpr size_t GetSize() { return 32; }
static constexpr std::string_view GetSchema() {
return "double w;double x;double y;double z";
}
static frc::Quaternion Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
const frc::Quaternion& value);
static frc::Quaternion Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::Quaternion& value);
};

View File

@@ -11,11 +11,12 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Rotation2d> {
static constexpr std::string_view kTypeString = "struct:Rotation2d";
static constexpr size_t kSize = 8;
static constexpr std::string_view kSchema = "double value";
static constexpr std::string_view GetTypeString() {
return "struct:Rotation2d";
}
static constexpr size_t GetSize() { return 8; }
static constexpr std::string_view GetSchema() { return "double value"; }
static frc::Rotation2d Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
const frc::Rotation2d& value);
static frc::Rotation2d Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::Rotation2d& value);
};

View File

@@ -11,15 +11,20 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Rotation3d> {
static constexpr std::string_view kTypeString = "struct:Rotation3d";
static constexpr size_t kSize = wpi::Struct<frc::Quaternion>::kSize;
static constexpr std::string_view kSchema = "Quaternion q";
static constexpr std::string_view GetTypeString() {
return "struct:Rotation3d";
}
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Quaternion>();
}
static constexpr std::string_view GetSchema() { return "Quaternion q"; }
static frc::Rotation3d Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
const frc::Rotation3d& value);
static frc::Rotation3d Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::Rotation3d& value);
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn);
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Quaternion>(fn);
}
};
static_assert(wpi::HasNestedStruct<frc::Rotation3d>);

View File

@@ -11,17 +11,24 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Transform2d> {
static constexpr std::string_view kTypeString = "struct:Transform2d";
static constexpr size_t kSize = wpi::Struct<frc::Translation2d>::kSize +
wpi::Struct<frc::Rotation2d>::kSize;
static constexpr std::string_view kSchema =
"Translation2d translation;Rotation2d rotation";
static constexpr std::string_view GetTypeString() {
return "struct:Transform2d";
}
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Translation2d>() +
wpi::GetStructSize<frc::Rotation2d>();
}
static constexpr std::string_view GetSchema() {
return "Translation2d translation;Rotation2d rotation";
}
static frc::Transform2d Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
const frc::Transform2d& value);
static frc::Transform2d Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::Transform2d& value);
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn);
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation2d>(fn);
wpi::ForEachStructSchema<frc::Rotation2d>(fn);
}
};
static_assert(wpi::HasNestedStruct<frc::Transform2d>);

View File

@@ -11,17 +11,24 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Transform3d> {
static constexpr std::string_view kTypeString = "struct:Transform3d";
static constexpr size_t kSize = wpi::Struct<frc::Translation3d>::kSize +
wpi::Struct<frc::Rotation3d>::kSize;
static constexpr std::string_view kSchema =
"Translation3d translation;Rotation3d rotation";
static constexpr std::string_view GetTypeString() {
return "struct:Transform3d";
}
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Translation3d>() +
wpi::GetStructSize<frc::Rotation3d>();
}
static constexpr std::string_view GetSchema() {
return "Translation3d translation;Rotation3d rotation";
}
static frc::Transform3d Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
const frc::Transform3d& value);
static frc::Transform3d Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::Transform3d& value);
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn);
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation3d>(fn);
wpi::ForEachStructSchema<frc::Rotation3d>(fn);
}
};
static_assert(wpi::HasNestedStruct<frc::Transform3d>);

View File

@@ -11,11 +11,12 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Translation2d> {
static constexpr std::string_view kTypeString = "struct:Translation2d";
static constexpr size_t kSize = 16;
static constexpr std::string_view kSchema = "double x;double y";
static constexpr std::string_view GetTypeString() {
return "struct:Translation2d";
}
static constexpr size_t GetSize() { return 16; }
static constexpr std::string_view GetSchema() { return "double x;double y"; }
static frc::Translation2d Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
const frc::Translation2d& value);
static frc::Translation2d Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::Translation2d& value);
};

View File

@@ -11,11 +11,14 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Translation3d> {
static constexpr std::string_view kTypeString = "struct:Translation3d";
static constexpr size_t kSize = 24;
static constexpr std::string_view kSchema = "double x;double y;double z";
static constexpr std::string_view GetTypeString() {
return "struct:Translation3d";
}
static constexpr size_t GetSize() { return 24; }
static constexpr std::string_view GetSchema() {
return "double x;double y;double z";
}
static frc::Translation3d Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
const frc::Translation3d& value);
static frc::Translation3d Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::Translation3d& value);
};

View File

@@ -11,11 +11,12 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Twist2d> {
static constexpr std::string_view kTypeString = "struct:Twist2d";
static constexpr size_t kSize = 24;
static constexpr std::string_view kSchema =
"double dx;double dy;double dtheta";
static constexpr std::string_view GetTypeString() { return "struct:Twist2d"; }
static constexpr size_t GetSize() { return 24; }
static constexpr std::string_view GetSchema() {
return "double dx;double dy;double dtheta";
}
static frc::Twist2d Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data, const frc::Twist2d& value);
static frc::Twist2d Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::Twist2d& value);
};

View File

@@ -11,11 +11,12 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Twist3d> {
static constexpr std::string_view kTypeString = "struct:Twist3d";
static constexpr size_t kSize = 48;
static constexpr std::string_view kSchema =
"double dx;double dy;double dz;double rx;double ry;double rz";
static constexpr std::string_view GetTypeString() { return "struct:Twist3d"; }
static constexpr size_t GetSize() { return 48; }
static constexpr std::string_view GetSchema() {
return "double dx;double dy;double dz;double rx;double ry;double rz";
}
static frc::Twist3d Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data, const frc::Twist3d& value);
static frc::Twist3d Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::Twist3d& value);
};

View File

@@ -11,12 +11,14 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::ChassisSpeeds> {
static constexpr std::string_view kTypeString = "struct:ChassisSpeeds";
static constexpr size_t kSize = 24;
static constexpr std::string_view kSchema =
"double vx;double vy;double omega";
static constexpr std::string_view GetTypeString() {
return "struct:ChassisSpeeds";
}
static constexpr size_t GetSize() { return 24; }
static constexpr std::string_view GetSchema() {
return "double vx;double vy;double omega";
}
static frc::ChassisSpeeds Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
const frc::ChassisSpeeds& value);
static frc::ChassisSpeeds Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data, const frc::ChassisSpeeds& value);
};

View File

@@ -11,13 +11,13 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::DifferentialDriveKinematics> {
static constexpr std::string_view kTypeString =
"struct:DifferentialDriveKinematics";
static constexpr size_t kSize = 8;
static constexpr std::string_view kSchema = "double track_width";
static constexpr std::string_view GetTypeString() {
return "struct:DifferentialDriveKinematics";
}
static constexpr size_t GetSize() { return 8; }
static constexpr std::string_view GetSchema() { return "double track_width"; }
static frc::DifferentialDriveKinematics Unpack(
std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
static frc::DifferentialDriveKinematics Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data,
const frc::DifferentialDriveKinematics& value);
};

View File

@@ -11,13 +11,16 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::DifferentialDriveWheelSpeeds> {
static constexpr std::string_view kTypeString =
"struct:DifferentialDriveWheelSpeeds";
static constexpr size_t kSize = 16;
static constexpr std::string_view kSchema = "double left;double right";
static constexpr std::string_view GetTypeString() {
return "struct:DifferentialDriveWheelSpeeds";
}
static constexpr size_t GetSize() { return 16; }
static constexpr std::string_view GetSchema() {
return "double left;double right";
}
static frc::DifferentialDriveWheelSpeeds Unpack(
std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data,
const frc::DifferentialDriveWheelSpeeds& value);
};

View File

@@ -11,19 +11,24 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::MecanumDriveKinematics> {
static constexpr std::string_view kTypeString =
"struct:MecanumDriveKinematics";
static constexpr size_t kSize = 4 * wpi::Struct<frc::Translation2d>::kSize;
static constexpr std::string_view kSchema =
"Translation2d front_left;Translation2d front_right;Translation2d "
"rear_left;Translation2d rear_right";
static constexpr std::string_view GetTypeString() {
return "struct:MecanumDriveKinematics";
}
static constexpr size_t GetSize() {
return 4 * wpi::GetStructSize<frc::Translation2d>();
}
static constexpr std::string_view GetSchema() {
return "Translation2d front_left;Translation2d front_right;Translation2d "
"rear_left;Translation2d rear_right";
}
static frc::MecanumDriveKinematics Unpack(
std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
static frc::MecanumDriveKinematics Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data,
const frc::MecanumDriveKinematics& value);
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn);
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation2d>(fn);
}
};
static_assert(wpi::HasNestedStruct<frc::MecanumDriveKinematics>);

View File

@@ -11,14 +11,16 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::MecanumDriveWheelPositions> {
static constexpr std::string_view kTypeString =
"struct:MecanumDriveWheelPositions";
static constexpr size_t kSize = 32;
static constexpr std::string_view kSchema =
"double front_left;double front_right;double rear_left;double rear_right";
static constexpr std::string_view GetTypeString() {
return "struct:MecanumDriveWheelPositions";
}
static constexpr size_t GetSize() { return 32; }
static constexpr std::string_view GetSchema() {
return "double front_left;double front_right;double rear_left;double "
"rear_right";
}
static frc::MecanumDriveWheelPositions Unpack(
std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
static frc::MecanumDriveWheelPositions Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data,
const frc::MecanumDriveWheelPositions& value);
};

View File

@@ -11,14 +11,16 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::MecanumDriveWheelSpeeds> {
static constexpr std::string_view kTypeString =
"struct:MecanumDriveWheelSpeeds";
static constexpr size_t kSize = 32;
static constexpr std::string_view kSchema =
"double front_left;double front_right;double rear_left;double rear_right";
static constexpr std::string_view GetTypeString() {
return "struct:MecanumDriveWheelSpeeds";
}
static constexpr size_t GetSize() { return 32; }
static constexpr std::string_view GetSchema() {
return "double front_left;double front_right;double rear_left;"
"double rear_right";
}
static frc::MecanumDriveWheelSpeeds Unpack(
std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
static frc::MecanumDriveWheelSpeeds Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data,
const frc::MecanumDriveWheelSpeeds& value);
};

View File

@@ -11,16 +11,23 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::SwerveModulePosition> {
static constexpr std::string_view kTypeString = "struct:SwerveModulePosition";
static constexpr size_t kSize = 8 + wpi::Struct<frc::Rotation2d>::kSize;
static constexpr std::string_view kSchema =
"double distance;Rotation2d angle";
static constexpr std::string_view GetTypeString() {
return "struct:SwerveModulePosition";
}
static constexpr size_t GetSize() {
return 8 + wpi::GetStructSize<frc::Rotation2d>();
}
static constexpr std::string_view GetSchema() {
return "double distance;Rotation2d angle";
}
static frc::SwerveModulePosition Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
static frc::SwerveModulePosition Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data,
const frc::SwerveModulePosition& value);
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn);
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Rotation2d>(fn);
}
};
static_assert(wpi::HasNestedStruct<frc::SwerveModulePosition>);

View File

@@ -11,15 +11,23 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::SwerveModuleState> {
static constexpr std::string_view kTypeString = "struct:SwerveModuleState";
static constexpr size_t kSize = 8 + wpi::Struct<frc::Rotation2d>::kSize;
static constexpr std::string_view kSchema = "double speed;Rotation2d angle";
static constexpr std::string_view GetTypeString() {
return "struct:SwerveModuleState";
}
static constexpr size_t GetSize() {
return 8 + wpi::GetStructSize<frc::Rotation2d>();
}
static constexpr std::string_view GetSchema() {
return "double speed;Rotation2d angle";
}
static frc::SwerveModuleState Unpack(std::span<const uint8_t, kSize> data);
static void Pack(std::span<uint8_t, kSize> data,
static frc::SwerveModuleState Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data,
const frc::SwerveModuleState& value);
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn);
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Rotation2d>(fn);
}
};
static_assert(wpi::HasNestedStruct<frc::SwerveModuleState>);