Skip to content

Commit

Permalink
Use integer for spec version
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Nov 22, 2024
1 parent 4cfd00b commit 85d9413
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions choreolib/py/choreo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
load_event_marker,
)

SPEC_VERSION = "v2025.0.0"
SPEC_VERSION = 1


def load_differential_trajectory_string(
Expand All @@ -22,7 +22,7 @@ def load_differential_trajectory_string(
"""
data = json.loads(trajectory_json_string)
name = data["name"]
version = data["version"]
version = int(data["version"])
if version != SPEC_VERSION:
raise ValueError(
f"{name}.traj: Wrong version {version}. Expected {SPEC_VERSION}"
Expand Down
2 changes: 1 addition & 1 deletion choreolib/py/choreo/test/choreolib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
TRAJECTORY = """
{
"name":"New Path",
"version":"v2025.0.0",
"version":1,
"snapshot":{
"waypoints":[
{"x":0.0, "y":0.0, "heading":0.0, "intervals":9, "split":false, "fixTranslation":true, "fixHeading":true, "overrideIntervals":false},
Expand Down
2 changes: 1 addition & 1 deletion choreolib/py/choreo/test/resources/swerve_test.traj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"test",
"version":"v2025.0.0",
"version":1,
"snapshot":{
"waypoints":[
{"x":2.6185336112976074, "y":6.034867286682129, "heading":0.0, "intervals":16, "split":false, "fixTranslation":true, "fixHeading":true, "overrideIntervals":false},
Expand Down
10 changes: 5 additions & 5 deletions choreolib/src/main/java/choreo/Choreo.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class Choreo {
.registerTypeAdapter(EventMarker.class, new EventMarker.Deserializer())
.create();
private static final String TRAJECTORY_FILE_EXTENSION = ".traj";
private static final String SPEC_VERSION = "v2025.0.0";
private static final int SPEC_VERSION = 1;

private static File CHOREO_DIR = new File(Filesystem.getDeployDirectory(), "choreo");

Expand Down Expand Up @@ -81,8 +81,8 @@ public static ProjectFile getProjectFile() {
String str = reader.lines().reduce("", (a, b) -> a + b);
reader.close();
JsonObject json = GSON.fromJson(str, JsonObject.class);
String version = json.get("version").getAsString();
if (!SPEC_VERSION.equals(version)) {
int version = json.get("version").getAsInt();
if (version != SPEC_VERSION) {
throw new RuntimeException(
".chor project file: Wrong version " + version + ". Expected " + SPEC_VERSION);
}
Expand Down Expand Up @@ -159,8 +159,8 @@ static Trajectory<? extends TrajectorySample<?>> loadTrajectoryString(
String trajectoryJsonString, ProjectFile projectFile) {
JsonObject wholeTrajectory = GSON.fromJson(trajectoryJsonString, JsonObject.class);
String name = wholeTrajectory.get("name").getAsString();
String version = wholeTrajectory.get("version").getAsString();
if (!SPEC_VERSION.equals(version)) {
int version = wholeTrajectory.get("version").getAsInt();
if (version != SPEC_VERSION) {
throw new RuntimeException(
name + ".traj: Wrong version: " + version + ". Expected " + SPEC_VERSION);
}
Expand Down
4 changes: 2 additions & 2 deletions choreolib/src/main/java/choreo/trajectory/ProjectFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static class Config {
public final String name;

/** The version of the project. */
public final String version;
public final int version;

/** The sample type for the project */
public final String type;
Expand All @@ -132,7 +132,7 @@ public static class Config {
public final List<String> generationFeatures;

ProjectFile(
String name, String version, String type, Config config, List<String> generationFeatures) {
String name, int version, String type, Config config, List<String> generationFeatures) {
this.name = name;
this.version = version;
this.type = type;
Expand Down
8 changes: 4 additions & 4 deletions choreolib/src/main/native/include/choreo/Choreo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace choreo {

inline constexpr std::string_view kSpecVersion = "v2025.0.0";
inline constexpr uint32_t kSpecVersion = 1;

template <TrajectorySample SampleType, int Year>
class AutoFactory;
Expand Down Expand Up @@ -73,7 +73,7 @@ class Choreo {
}

wpi::json json = wpi::json::parse(fileBuffer.value()->GetCharBuffer());
std::string version = json["version"];
uint32_t version = json["version"];
if (kSpecVersion != version) {
throw fmt::format(".chor project file: Wrong version {}. Expected {}",
version, kSpecVersion);
Expand Down Expand Up @@ -145,8 +145,8 @@ class Choreo {
static std::optional<Trajectory<SampleType>> LoadTrajectoryString(
std::string_view trajectoryJsonString, std::string_view trajectoryName) {
wpi::json json = wpi::json::parse(trajectoryJsonString);
std::string version = json["version"];
if (kSpecVersion != version) {
uint32_t version = json["version"];
if (version != kSpecVersion) {
throw fmt::format("{}.traj: Wrong version {}. Expected {}",
trajectoryName, version, kSpecVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct ProjectFile {
std::string name;

/// The version of the project.
std::string version;
uint32_t version;

/// The sample type for the project.
std::string type;
Expand Down
4 changes: 2 additions & 2 deletions choreolib/src/test/java/choreo/ChoreoTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ChoreoTests {
"""
{
"name":"New Path",
"version":"v2025.0.0",
"version":1,
"snapshot":{
"waypoints":[
{"x":0.0, "y":0.0, "heading":0.0, "intervals":9, "split":false, "fixTranslation":true, "fixHeading":true, "overrideIntervals":false},
Expand Down Expand Up @@ -59,7 +59,7 @@ public class ChoreoTests {
public static final String PROJ =
"{"
+ " \"name\": \"idk\","
+ " \"version\": \"v2025.0.0\","
+ " \"version\": 1,"
+ " \"type\": \"Swerve\","
+ " \"variables\": {"
+ " \"expressions\": {},"
Expand Down
4 changes: 2 additions & 2 deletions choreolib/src/test/native/cpp/ProjectFileTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace choreo;

constexpr std::string_view projectJsonString = R"({
"name":"test",
"version":"v2025.0.0",
"version":1,
"type":"Swerve",
"variables":{
"expressions":{
Expand Down Expand Up @@ -116,7 +116,7 @@ const wpi::json projectJson = wpi::json::parse(projectJsonString);

const ProjectFile correctProjFile{
"test",
"v2025.0.0",
1,
"Swerve",
{{"test", Variable{"Number", Expression{"2", 2.0}}}},
{{"test2", Pose{Expression{"2 m", 2.0}, Expression{"3 m", 3.0},
Expand Down
2 changes: 1 addition & 1 deletion choreolib/src/test/native/cpp/TrajectoryFileTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using namespace choreo;
constexpr std::string_view swerveTrajectoryString =
R"({
"name":"New Path",
"version":"v2025.0.0",
"version":1,
"snapshot":{
"waypoints":[
{"x":0.0, "y":0.0, "heading":0.0, "intervals":9, "split":false, "fixTranslation":true, "fixHeading":true, "overrideIntervals":false},
Expand Down

0 comments on commit 85d9413

Please sign in to comment.