Skip to content
This repository was archived by the owner on Jan 18, 2026. It is now read-only.

Commit 2d3dea2

Browse files
committed
expose native codec version
1 parent 6ee3e3b commit 2d3dea2

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

docs/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Add ` /guard:cf` by @johnthcall in #26.
44
- Where possible, increase "buffer size" variable resolution to `int64_t` (#28).
55
- Native and managed dependencies upgraded to the latest versions.
6+
- Added method to get native library version from C#.
67

78
## 1.6.3
89

managed/IronCompress.Test/IronTest.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public void CheckNoNativeGzip() {
7373

7474
[Fact]
7575
public void CheckVersion() {
76-
Assert.NotEmpty(Iron.GetNativeVersion());
76+
Assert.NotNull(Iron.GetNativeVersion());
77+
}
78+
79+
[Fact]
80+
public void CheckCodecVersion() {
81+
Assert.Equal("1.2.2", Iron.GetNativeCodecVersion(Codec.Snappy));
7782
}
7883
}

managed/IronCompress/Iron.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,28 @@ public static bool SupportsNative(Codec c) {
5050
return Native.iron_is_supported((int)c);
5151
}
5252

53+
/// <summary>
54+
/// Returns native library version string, or null if native library is not available
55+
/// </summary>
56+
/// <returns></returns>
5357
public static string? GetNativeVersion() {
5458
IntPtr ptr = Native.iron_version();
5559
string? version = Marshal.PtrToStringAnsi(ptr);
5660
return version;
5761
}
5862

63+
/// <summary>
64+
/// Retrieves the version string of the native library associated with the specified codec.
65+
/// </summary>
66+
/// <param name="codec">The codec for which to obtain the native library version.</param>
67+
/// <returns>A string containing the version of the native library for the specified codec, or null if the version cannot
68+
/// be determined.</returns>
69+
public static string? GetNativeCodecVersion(Codec codec) {
70+
IntPtr ptr = Native.get_native_library_version((int)codec);
71+
string? version = Marshal.PtrToStringAnsi(ptr);
72+
return version;
73+
}
74+
5975
/// <summary>
6076
/// Set to force specific platform. Used mostly in benchmarking tests, prefer not to set.
6177
/// </summary>

managed/IronCompress/Native.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ internal static extern unsafe bool iron_compress(bool compress,
5858
internal static extern IntPtr iron_version();
5959

6060
[DllImport(LibName)]
61-
internal static extern string get_native_library_version(int codec);
61+
internal static extern IntPtr get_native_library_version(int codec);
6262
}
6363
}

native/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
7272
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
7373
endif()
7474

75+
if(NOT DEFINED ENV{DOTNET_RID})
76+
# Default to win-x64 if not defined, for local testing
77+
set(ENV{DOTNET_RID} "win-x64")
78+
endif()
79+
7580
# https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#generator-expression-reference
7681
add_custom_command(
7782
TARGET ${PROJECT_NAME}

0 commit comments

Comments
 (0)