Skip to content

Commit e6a3537

Browse files
dfa1claude
andauthored
feat: expose Zstd.versionNumber() (#16)
* refactor: make NativeCall.requireNative return void Every caller uses it as a guard statement and discards the returned segment, so the fluent return was dead. Drop it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * feat: expose Zstd.versionNumber() Wire up the previously-unused VERSION_NUMBER binding as a public int Zstd.versionNumber() (MAJOR*10000 + MINOR*100 + PATCH, e.g. 10507 for 1.5.7), paralleling version() for programmatic version checks. Test asserts it stays consistent with the version() string. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 18b8ace commit e6a3537

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

zstd/src/main/java/io/github/dfa1/zstd/Zstd.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ public static String version() {
227227
}
228228
}
229229

230+
/// Runtime zstd version as a single number for programmatic comparison,
231+
/// encoded `MAJOR * 10000 + MINOR * 100 + PATCH` — e.g. `10507` for `1.5.7`.
232+
///
233+
/// @return the linked zstd library version number
234+
public static int versionNumber() {
235+
try {
236+
return (int) Bindings.VERSION_NUMBER.invokeExact();
237+
} catch (Throwable t) {
238+
throw NativeCall.rethrow(t);
239+
}
240+
}
241+
230242
// --- package-private helpers shared with the context classes ---
231243
// Native-call status checking and segment guards live in NativeCall.
232244

zstd/src/test/java/io/github/dfa1/zstd/ZstdTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,20 @@ void reportsSemanticVersion() {
135135
// When the runtime version is read / Then it is an x.y.z string
136136
assertThat(Zstd.version()).matches("\\d+\\.\\d+\\.\\d+");
137137
}
138+
139+
@Test
140+
void reportsVersionNumberConsistentWithTheString() {
141+
// Given the x.y.z version string split into its parts
142+
String[] parts = Zstd.version().split("\\.");
143+
int expected = Integer.parseInt(parts[0]) * 10000
144+
+ Integer.parseInt(parts[1]) * 100
145+
+ Integer.parseInt(parts[2]);
146+
147+
// When the numeric version is read
148+
int number = Zstd.versionNumber();
149+
150+
// Then it encodes MAJOR * 10000 + MINOR * 100 + PATCH
151+
assertThat(number).isEqualTo(expected);
152+
}
138153
}
139154
}

0 commit comments

Comments
 (0)