mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-30 05:15:59 +02:00
zlib interface
This commit is contained in:
parent
c3644d15de
commit
345746d34d
3 changed files with 199 additions and 0 deletions
57
BeefLibs/Beefy2D/src/utils/Compression.bf
Normal file
57
BeefLibs/Beefy2D/src/utils/Compression.bf
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class Compression
|
||||
{
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
extern static Span<uint8> Compression_Compress(void* ptr, int size);
|
||||
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
extern static Span<uint8> Compression_Decompress(void* ptr, int size);
|
||||
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
extern static void Compression_Free(void* ptr);
|
||||
|
||||
public static Result<void> Compress(Span<uint8> inData, List<uint8> outData)
|
||||
{
|
||||
var outSpan = Compression_Compress(inData.Ptr, inData.Length);
|
||||
if ((outSpan.Length == 0) && (inData.Length != 0))
|
||||
return .Err;
|
||||
outData.AddRange(outSpan);
|
||||
Compression_Free(outSpan.Ptr);
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
public static Result<void> Compress(Span<uint8> inData, String outData)
|
||||
{
|
||||
var outSpan = Compression_Compress(inData.Ptr, inData.Length);
|
||||
if ((outSpan.Length == 0) && (inData.Length != 0))
|
||||
return .Err;
|
||||
outData.Insert(outData.Length, StringView((.)outSpan.Ptr, outSpan.Length));
|
||||
Compression_Free(outSpan.Ptr);
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
public static Result<void> Decompress(Span<uint8> inData, List<uint8> outData)
|
||||
{
|
||||
var outSpan = Compression_Decompress(inData.Ptr, inData.Length);
|
||||
if ((outSpan.Length == 0) && (inData.Length != 0))
|
||||
return .Err;
|
||||
outData.AddRange(outSpan);
|
||||
Compression_Free(outSpan.Ptr);
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
public static Result<void> Decompress(Span<uint8> inData, String outData)
|
||||
{
|
||||
var outSpan = Compression_Decompress(inData.Ptr, inData.Length);
|
||||
if ((outSpan.Length == 0) && (inData.Length != 0))
|
||||
return .Err;
|
||||
outData.Insert(outData.Length, StringView((.)outSpan.Ptr, outSpan.Length));
|
||||
Compression_Free(outSpan.Ptr);
|
||||
return .Ok;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue