Skip to content

Commit

Permalink
v2.0 + .net8
Browse files Browse the repository at this point in the history
  • Loading branch information
NotOfficer committed Mar 31, 2024
1 parent eaa7451 commit 2f8d380
Show file tree
Hide file tree
Showing 20 changed files with 474 additions and 241 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/nuget_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: NuGet Push

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Restore dependencies
run: dotnet restore ./src

- name: Build
run: dotnet build ./src --no-restore --configuration Release

- name: Pack NuGet Package(s)
run: dotnet pack ./src --no-restore --no-build --configuration Release --output ./nuget-packages

- name: Upload Build Artifact(s)
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: ./nuget-packages

- name: Push NuGet Package(s)
run: dotnet nuget push ./nuget-packages/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Officer
Copyright (c) 2024 NotOfficer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 7 additions & 7 deletions src/Oodle.NET.Tests/Oodle.NET.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<TargetFramework>net8.0</TargetFramework>
<RootNamespace>OodleDotNet.Tests</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand All @@ -17,13 +17,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
57 changes: 0 additions & 57 deletions src/Oodle.NET.Tests/OodleCompressorTests.cs

This file was deleted.

53 changes: 53 additions & 0 deletions src/Oodle.NET.Tests/Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

using Xunit;

namespace OodleDotNet.Tests;

public class Tests
{
private readonly Oodle _oodle = new(Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
@"Libraries\oo2core_9_win64.dll"));

[Fact]
public void CompressAndDecompress()
{
const OodleCompressor compressor = OodleCompressor.Kraken;
var randomString = GetRandomString(8192);
var randomStringBuffer = Encoding.ASCII.GetBytes(randomString);

var compressedBufferSize = _oodle.GetCompressedBufferSizeNeeded(compressor, randomStringBuffer.Length);
Assert.NotEqual(0, compressedBufferSize);

var compressedBuffer = new byte[compressedBufferSize];
var compressedSize = (int)_oodle.Compress(compressor, OodleCompressionLevel.Max, randomStringBuffer, compressedBuffer);
Assert.NotEqual(0, compressedSize);

var decompressedBuffer = new byte[randomStringBuffer.Length];
var decompressedSize = (int)_oodle.Decompress(compressedBuffer.AsSpan(0, compressedSize), decompressedBuffer);
Assert.NotEqual(0, decompressedSize);

Assert.Equal(decompressedSize, randomStringBuffer.Length);
Assert.True(randomStringBuffer.AsSpan().SequenceEqual(decompressedBuffer));
}

private static string GetRandomString(int length)
{
const string chars = "0123456789ABCDEF";
var result = new string('\0', length);
var resultReadonlySpan = result.AsSpan();
var resultSpan = MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in resultReadonlySpan.GetPinnableReference()), length);

for (var i = 0; i < resultSpan.Length; i++)
{
resultSpan[i] = chars[Random.Shared.Next(chars.Length)];
}

return result;
}
}
8 changes: 4 additions & 4 deletions src/Oodle.NET.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31112.23
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Oodle.NET", "Oodle.NET\Oodle.NET.csproj", "{AFF75C15-8DFA-454A-B24B-09F19BE68559}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oodle.NET", "Oodle.NET\Oodle.NET.csproj", "{AFF75C15-8DFA-454A-B24B-09F19BE68559}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Oodle.NET.Tests", "Oodle.NET.Tests\Oodle.NET.Tests.csproj", "{0482F51C-6992-49AD-90AC-A4689FA32C52}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oodle.NET.Tests", "Oodle.NET.Tests\Oodle.NET.Tests.csproj", "{0482F51C-6992-49AD-90AC-A4689FA32C52}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
179 changes: 179 additions & 0 deletions src/Oodle.NET/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
namespace OodleDotNet;

public enum OodleVerbosity
{
None = 0,
Minimal = 1,
Some = 2,
Lots = 3,
Force32 = 0x40000000
}

public enum OodleFuzzSafe
{
No = 0,
Yes = 1
}

public enum OodleCheckCRC
{
No = 0,
Yes = 1,
Force32 = 0x40000000
}

public enum OodleDecodeThreadPhase
{
Phase1 = 1,
Phase2 = 2,
All = 3,
Unthreaded = All
}

public enum OodleCompressionLevel
{
/// <summary>
/// don't compress, just copy raw bytes
/// </summary>
None=0,
/// <summary>
/// super fast mode, lower compression ratio
/// </summary>
SuperFast=1,
/// <summary>
/// fastest LZ mode with still decent compression ratio
/// </summary>
VeryFast=2,
/// <summary>
/// fast - good for daily use
/// </summary>
Fast=3,
/// <summary>
/// standard medium speed LZ mode
/// </summary>
Normal=4,

/// <summary>
/// optimal parse level 1 (faster optimal encoder)
/// </summary>
Optimal1=5,
/// <summary>
/// optimal parse level 2 (recommended baseline optimal encoder)
/// </summary>
Optimal2=6,
/// <summary>
/// optimal parse level 3 (slower optimal encoder)
/// </summary>
Optimal3=7,
/// <summary>
/// optimal parse level 4 (very slow optimal encoder)
/// </summary>
Optimal4=8,
/// <summary>
/// optimal parse level 5 (don't care about encode speed, maximum compression)
/// </summary>
Optimal5=9,

/// <summary>
/// faster than SuperFast, less compression
/// </summary>
HyperFast1=-1,
/// <summary>
/// faster than HyperFast1, less compression
/// </summary>
HyperFast2=-2,
/// <summary>
/// faster than HyperFast2, less compression
/// </summary>
HyperFast3=-3,
/// <summary>
/// fastest, less compression
/// </summary>
HyperFast4=-4,

/// <summary>
/// alias hyperfast base level
/// </summary>
HyperFast=HyperFast1,
/// <summary>
/// alias optimal standard level
/// </summary>
Optimal = Optimal2,
/// <summary>
/// maximum compression level
/// </summary>
Max = Optimal5,
/// <summary>
/// fastest compression level
/// </summary>
Min = HyperFast4,

Force32 = 0x40000000,
Invalid = Force32
}

public enum OodleCompressor
{
Invalid = -1,
/// <summary>
/// None = memcpy, pass through uncompressed bytes
/// </summary>
None = 3,

/// <summary>
/// Fast decompression and high compression ratios, amazing!
/// </summary>
Kraken = 8,
/// <summary>
/// Leviathan = Kraken's big brother with higher compression, slightly slower decompression.
/// </summary>
Leviathan = 13,
/// <summary>
/// Mermaid is between Kraken
/// </summary>& Selkie - crazy fast, still decent compression.
Mermaid = 9,
/// <summary>
/// Selkie is a super-fast relative of Mermaid. For maximum decode speed.
/// </summary>
Selkie = 11,
/// <summary>
/// Hydra, the many-headed beast = Leviathan, Kraken, Mermaid, or Selkie (see $OodleLZ_About_Hydra)
/// </summary>
Hydra = 12,

/// <summary>
/// no longer supported as of Oodle 2.9.0
/// </summary>
BitKnit = 10,
/// <summary>
/// no longer supported as of Oodle 2.9.0
/// </summary>
LZB16 = 4,
/// <summary>
/// no longer supported as of Oodle 2.9.0
/// </summary>
LZNA = 7,
/// <summary>
/// no longer supported as of Oodle 2.9.0
/// </summary>
LZH = 0,
/// <summary>
/// no longer supported as of Oodle 2.9.0
/// </summary>
LZHLW = 1,
/// <summary>
/// no longer supported as of Oodle 2.9.0
/// </summary>
LZNIB = 2,
/// <summary>
/// no longer supported as of Oodle 2.9.0
/// </summary>
LZBLW = 5,
/// <summary>
/// no longer supported as of Oodle 2.9.0
/// </summary>
LZA = 6,

Count = 14,
Force32 = 0x40000000
}
Loading

0 comments on commit 2f8d380

Please sign in to comment.