Skip to content

Commit

Permalink
add call to get native version
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed Sep 30, 2024
1 parent a12eb29 commit 522efcb
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 30 deletions.
5 changes: 5 additions & 0 deletions managed/IronCompress.Test/IronTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ public void CheckNativeLibAvailable() {
public void CheckNoNativeGzip() {
Assert.False(Iron.SupportsNative(Codec.Gzip));
}

[Fact]
public void CheckVersion() {
Assert.NotEmpty(Iron.GetNativeVersion());
}
}
4 changes: 4 additions & 0 deletions managed/IronCompress/Iron.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public static bool SupportsNative(Codec c) {
return Native.iron_is_supported((int)c);
}

public static string GetNativeVersion() {
return Native.iron_version();
}

/// <summary>
/// Set to force specific platform. Used mostly in benchmarking tests, prefer not to set.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions managed/IronCompress/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ internal static extern unsafe bool iron_compress(bool compress,

[DllImport(LibName)]
internal static extern bool iron_is_supported(int codec);

[DllImport(LibName)]
internal static extern string iron_version();
}
}
2 changes: 2 additions & 0 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ endif()
# ------- Dynamic Library -----------

add_library (${PROJECT_NAME} SHARED "api.cpp" "../minilzo/minilzo.c")
target_compile_definitions(${PROJECT_NAME} PRIVATE
IRON_VERSION="$ENV{VERSION}")
set_property(TARGET ${PROJECT_NAME} PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

Expand Down
6 changes: 5 additions & 1 deletion native/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,8 @@ bool iron_is_supported(compression_codec codec) {

bool iron_ping() {
return true;
}
}

const char* iron_version() {
return IRON_VERSION;
}
64 changes: 35 additions & 29 deletions native/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,41 @@ enum class compression_codec : int32_t {

extern "C"
{
/**
* @brief Encode (compress) or decompress
* @param compress When true this is compression, otherwise decompression.
* @param codec 1 - snappy, 2 - zstd, 3 - gzip, 4 - brotli, 5 - lzo, 6 - lz4
* @param input_buffer If this is set to nullptr, the function sets output_buffer_size to required maximum size of the compressed data.
* @param input_buffer_size
* @param output_buffer When output_buffer is nullptr, this is set to maximum buffer size required. Otherwise, to the size of the actual compressed data written to output_buffer.
* @param output_buffer_size
* @param compression_level 1 - fastest, 2 - balanced, 3 - best
* @return
*/
EXPORTED bool iron_compress(
bool compress,
compression_codec codec,
char* input_buffer,
int32_t input_buffer_size,
char* output_buffer,
int32_t* output_buffer_size,
compression_level compression_level);

/**
* @brief Rerturns true if the codec is supported by the library. Some architectures can have differences in supported codecs.
* @param codec
* @return
/**
* @brief Encode (compress) or decompress
* @param compress When true this is compression, otherwise decompression.
* @param codec 1 - snappy, 2 - zstd, 3 - gzip, 4 - brotli, 5 - lzo, 6 - lz4
* @param input_buffer If this is set to nullptr, the function sets output_buffer_size to required maximum size of the compressed data.
* @param input_buffer_size
* @param output_buffer When output_buffer is nullptr, this is set to maximum buffer size required. Otherwise, to the size of the actual compressed data written to output_buffer.
* @param output_buffer_size
* @param compression_level 1 - fastest, 2 - balanced, 3 - best
* @return
*/
EXPORTED bool iron_is_supported(compression_codec codec);
EXPORTED bool iron_compress(
bool compress,
compression_codec codec,
char* input_buffer,
int32_t input_buffer_size,
char* output_buffer,
int32_t* output_buffer_size,
compression_level compression_level);

/**
* @brief Used to just ping the library to test it's available at all
*/
EXPORTED bool iron_ping();
/**
* @brief Rerturns true if the codec is supported by the library. Some architectures can have differences in supported codecs.
* @param codec
* @return
*/
EXPORTED bool iron_is_supported(compression_codec codec);

/**
* @brief Used to just ping the library to test it's available at all
*/
EXPORTED bool iron_ping();

/**
* @brief Returns the version of the library
* @return
*/
EXPORTED const char* iron_version();
}
6 changes: 6 additions & 0 deletions native/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,10 @@ TEST(Infra, IsSupported) {
EXPECT_TRUE(iron_is_supported(compression_codec::brotli));
EXPECT_TRUE(iron_is_supported(compression_codec::lzo));
EXPECT_TRUE(iron_is_supported(compression_codec::lz4));
}

TEST(Infra, Version) {
const char* version = iron_version();
EXPECT_TRUE(version != nullptr);
EXPECT_TRUE(strlen(version) > 0);
}

0 comments on commit 522efcb

Please sign in to comment.