mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-30 05:15:59 +02:00
Compression interface change
This commit is contained in:
parent
b0aa27c82c
commit
e29a785fee
2 changed files with 28 additions and 22 deletions
|
@ -6,44 +6,48 @@ namespace utils
|
|||
class Compression
|
||||
{
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
extern static Span<uint8> Compression_Compress(void* ptr, int size);
|
||||
extern static bool Compression_Compress(void* ptr, int size, void** outPtr, int* outSize);
|
||||
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
extern static Span<uint8> Compression_Decompress(void* ptr, int size);
|
||||
extern static bool Compression_Decompress(void* ptr, int size, void** outPtr, int* outSize);
|
||||
|
||||
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))
|
||||
void* outPtr = null;
|
||||
int outSize = 0;
|
||||
if (!Compression_Compress(inData.Ptr, inData.Length, &outPtr, &outSize))
|
||||
return .Err;
|
||||
outData.AddRange(outSpan);
|
||||
outData.AddRange(.((.)outPtr, outSize));
|
||||
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))
|
||||
void* outPtr = null;
|
||||
int outSize = 0;
|
||||
if (!Compression_Compress(inData.Ptr, inData.Length, &outPtr, &outSize))
|
||||
return .Err;
|
||||
outData.Insert(outData.Length, StringView((.)outSpan.Ptr, outSpan.Length));
|
||||
outData.Insert(outData.Length, StringView((.)outPtr, outSize));
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
public static Result<void> Decompress(Span<uint8> inData, List<uint8> outData)
|
||||
{
|
||||
var outSpan = Compression_Decompress(inData.Ptr, inData.Length);
|
||||
if (outSpan == default)
|
||||
void* outPtr = null;
|
||||
int outSize = 0;
|
||||
if (!Compression_Decompress(inData.Ptr, inData.Length, &outPtr, &outSize))
|
||||
return .Err;
|
||||
outData.AddRange(outSpan);
|
||||
outData.AddRange(.((.)outPtr, outSize));
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
public static Result<void> Decompress(Span<uint8> inData, String outData)
|
||||
{
|
||||
var outSpan = Compression_Decompress(inData.Ptr, inData.Length);
|
||||
if (outSpan == default)
|
||||
void* outPtr = null;
|
||||
int outSize = 0;
|
||||
if (!Compression_Decompress(inData.Ptr, inData.Length, &outPtr, &outSize))
|
||||
return .Err;
|
||||
outData.Insert(outData.Length, StringView((.)outSpan.Ptr, outSpan.Length));
|
||||
outData.Insert(outData.Length, StringView((.)outPtr, outSize));
|
||||
return .Ok;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue