summaryrefslogtreecommitdiffstats
path: root/source/core/slang-lz4-compression-system.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/core/slang-lz4-compression-system.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/core/slang-lz4-compression-system.cpp')
-rw-r--r--source/core/slang-lz4-compression-system.cpp55
1 files changed, 41 insertions, 14 deletions
diff --git a/source/core/slang-lz4-compression-system.cpp b/source/core/slang-lz4-compression-system.cpp
index 1e2ab9558..bb777fae6 100644
--- a/source/core/slang-lz4-compression-system.cpp
+++ b/source/core/slang-lz4-compression-system.cpp
@@ -1,10 +1,9 @@
#include "slang-lz4-compression-system.h"
+#include "slang-blob.h"
#include "slang-com-helper.h"
#include "slang-com-ptr.h"
-#include "slang-blob.h"
-
#include <lz4.h>
namespace Slang
@@ -12,31 +11,47 @@ namespace Slang
// Allocate static const storage for the various interface IDs that the Slang API needs to expose
-class LZ4CompressionSystemImpl : public RefObject, public ICompressionSystem
+class LZ4CompressionSystemImpl : public RefObject, public ICompressionSystem
{
public:
- // ISlangUnknown
+ // ISlangUnknown
// override ref counting, as singleton
SLANG_IUNKNOWN_QUERY_INTERFACE
SLANG_NO_THROW uint32_t SLANG_MCALL addRef() SLANG_OVERRIDE { return 1; }
SLANG_NO_THROW uint32_t SLANG_MCALL release() SLANG_OVERRIDE { return 1; }
// ICompressionSystem
- virtual SLANG_NO_THROW CompressionSystemType SLANG_MCALL getSystemType() SLANG_OVERRIDE { return CompressionSystemType::LZ4; }
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL compress(const CompressionStyle* style, const void* src, size_t srcSizeInBytes, ISlangBlob** outBlob) SLANG_OVERRIDE;
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL decompress(const void* compressed, size_t compressedSizeInBytes, size_t decompressedSizeInBytes, void* outDecompressed) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW CompressionSystemType SLANG_MCALL getSystemType() SLANG_OVERRIDE
+ {
+ return CompressionSystemType::LZ4;
+ }
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL compress(
+ const CompressionStyle* style,
+ const void* src,
+ size_t srcSizeInBytes,
+ ISlangBlob** outBlob) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL decompress(
+ const void* compressed,
+ size_t compressedSizeInBytes,
+ size_t decompressedSizeInBytes,
+ void* outDecompressed) SLANG_OVERRIDE;
protected:
-
ICompressionSystem* getInterface(const Guid& guid);
};
ICompressionSystem* LZ4CompressionSystemImpl::getInterface(const Guid& guid)
{
- return (guid == ISlangUnknown::getTypeGuid() || guid == ICompressionSystem::getTypeGuid()) ? static_cast<ICompressionSystem*>(this) : nullptr;
+ return (guid == ISlangUnknown::getTypeGuid() || guid == ICompressionSystem::getTypeGuid())
+ ? static_cast<ICompressionSystem*>(this)
+ : nullptr;
}
-SlangResult LZ4CompressionSystemImpl::compress(const CompressionStyle* style, const void* src, size_t srcSizeInBytes, ISlangBlob** outBlob)
+SlangResult LZ4CompressionSystemImpl::compress(
+ const CompressionStyle* style,
+ const void* src,
+ size_t srcSizeInBytes,
+ ISlangBlob** outBlob)
{
SLANG_UNUSED(style);
const size_t compressedBound = LZ4_compressBound(int(srcSizeInBytes));
@@ -44,7 +59,11 @@ SlangResult LZ4CompressionSystemImpl::compress(const CompressionStyle* style, co
ScopedAllocation alloc;
void* compressedData = alloc.allocate(compressedBound);
- const int compressedSize = LZ4_compress_default((const char*)src, (char*)compressedData, int(srcSizeInBytes), int(compressedBound));
+ const int compressedSize = LZ4_compress_default(
+ (const char*)src,
+ (char*)compressedData,
+ int(srcSizeInBytes),
+ int(compressedBound));
alloc.reallocate(compressedSize);
auto blob = RawBlob::moveCreate(alloc);
@@ -53,15 +72,23 @@ SlangResult LZ4CompressionSystemImpl::compress(const CompressionStyle* style, co
return SLANG_OK;
}
-SlangResult LZ4CompressionSystemImpl::decompress(const void* compressed, size_t compressedSizeInBytes, size_t decompressedSizeInBytes, void* outDecompressed)
+SlangResult LZ4CompressionSystemImpl::decompress(
+ const void* compressed,
+ size_t compressedSizeInBytes,
+ size_t decompressedSizeInBytes,
+ void* outDecompressed)
{
- const int decompressedSize = LZ4_decompress_safe((const char*)compressed, (char*)outDecompressed, int(compressedSizeInBytes), int(decompressedSizeInBytes));
+ const int decompressedSize = LZ4_decompress_safe(
+ (const char*)compressed,
+ (char*)outDecompressed,
+ int(compressedSizeInBytes),
+ int(decompressedSizeInBytes));
SLANG_UNUSED(decompressedSize);
SLANG_ASSERT(size_t(decompressedSize) == decompressedSizeInBytes);
return SLANG_OK;
}
-/* static */ICompressionSystem* LZ4CompressionSystem::getSingleton()
+/* static */ ICompressionSystem* LZ4CompressionSystem::getSingleton()
{
static LZ4CompressionSystemImpl impl;
return &impl;