aboutsummaryrefslogtreecommitdiff
path: root/zencore/include
diff options
context:
space:
mode:
authorDevin Doucette <[email protected]>2021-07-22 03:05:09 -0600
committerGitHub <[email protected]>2021-07-22 11:05:09 +0200
commitc49d575726a1d62a1adaf50f6a6341e70abb733e (patch)
treee562f08b57b5d89ced3b08896d423760b60c63df /zencore/include
parentIgnore tags folder created by ctags et al. (diff)
downloadzen-c49d575726a1d62a1adaf50f6a6341e70abb733e.tar.xz
zen-c49d575726a1d62a1adaf50f6a6341e70abb733e.zip
Added Oodle to CompressedBuffer (#5)
Diffstat (limited to 'zencore/include')
-rw-r--r--zencore/include/zencore/compress.h64
1 files changed, 47 insertions, 17 deletions
diff --git a/zencore/include/zencore/compress.h b/zencore/include/zencore/compress.h
index 1ab61e1be..6a65071d3 100644
--- a/zencore/include/zencore/compress.h
+++ b/zencore/include/zencore/compress.h
@@ -9,13 +9,30 @@
namespace zen {
-/** Method used to compress the data in a compressed buffer. */
-enum class CompressionMethod : uint8_t
+enum class OodleCompressor : uint8_t
{
- /** Header is followed by one uncompressed block. */
- None = 0,
- /** Header is followed by an array of compressed block sizes then the compressed blocks. */
- LZ4 = 4,
+ NotSet = 0,
+ Selkie = 1,
+ Mermaid = 2,
+ Kraken = 3,
+ Leviathan = 4,
+};
+
+enum class OodleCompressionLevel : int8_t
+{
+ HyperFast4 = -4,
+ HyperFast3 = -3,
+ HyperFast2 = -2,
+ HyperFast1 = -1,
+ None = 0,
+ SuperFast = 1,
+ VeryFast = 2,
+ Fast = 3,
+ Normal = 4,
+ Optimal1 = 5,
+ Optimal2 = 6,
+ Optimal3 = 7,
+ Optimal4 = 8,
};
/**
@@ -28,14 +45,26 @@ class CompressedBuffer
{
public:
/**
- * Compress the buffer using the requested compression format.
+ * Compress the buffer using the specified compressor and compression level.
+ *
+ * Data that does not compress will be return uncompressed, as if with level None.
+ *
+ * @note Using a level of None will return a buffer that references owned raw data.
*
- * @param FormatName One of NAME_None, NAME_Default, NAME_LZ4.
- * @param RawData Raw data to compress. NAME_None will reference owned raw data.
+ * @param RawData The raw data to be compressed.
+ * @param Compressor The compressor to encode with. May use NotSet if level is None.
+ * @param CompressionLevel The compression level to encode with.
+ * @param BlockSize The power-of-two block size to encode raw data in. 0 is default.
* @return An owned compressed buffer, or null on error.
*/
- [[nodiscard]] ZENCORE_API static CompressedBuffer Compress(CompressionMethod Method, const CompositeBuffer& RawData);
- [[nodiscard]] ZENCORE_API static CompressedBuffer Compress(CompressionMethod Method, const SharedBuffer& RawData);
+ [[nodiscard]] ZENCORE_API static CompressedBuffer Compress(const CompositeBuffer& RawData,
+ OodleCompressor Compressor = OodleCompressor::Mermaid,
+ OodleCompressionLevel CompressionLevel = OodleCompressionLevel::VeryFast,
+ uint64_t BlockSize = 0);
+ [[nodiscard]] ZENCORE_API static CompressedBuffer Compress(const SharedBuffer& RawData,
+ OodleCompressor Compressor = OodleCompressor::Mermaid,
+ OodleCompressionLevel CompressionLevel = OodleCompressionLevel::VeryFast,
+ uint64_t BlockSize = 0);
/**
* Construct from a compressed buffer previously created by Compress().
@@ -77,15 +106,16 @@ public:
[[nodiscard]] ZENCORE_API BLAKE3 GetRawHash() const;
/**
- * Returns the name of the compression format used by this buffer.
+ * Returns the compressor and compression level used by this buffer.
*
- * The format name may differ from the format name specified when creating the compressed buffer
- * because an incompressible buffer is stored with NAME_None, and a request of NAME_Default will
- * be stored in a specific format such as NAME_LZ4.
+ * The compressor and compression level may differ from those specified when creating the buffer
+ * because an incompressible buffer is stored with no compression. Parameters cannot be accessed
+ * if this is null or uses a method other than Oodle, in which case this returns false.
*
- * @return The format name, or NAME_None if this null, or NAME_Error if the format is unknown.
+ * @return True if parameters were written, otherwise false.
*/
- [[nodiscard]] ZENCORE_API const char* GetFormatName() const;
+ [[nodiscard]] ZENCORE_API bool TryGetCompressParameters(OodleCompressor& OutCompressor,
+ OodleCompressionLevel& OutCompressionLevel) const;
/**
* Decompress into a memory view that is exactly GetRawSize() bytes.