FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_compressorLZ4.hpp
1/*
2 * Copyright 2025 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_COMPRESSORLZ4_HPP_INCLUDED
18#define _FGE_C_COMPRESSORLZ4_HPP_INCLUDED
19
20#include "fge_extern.hpp"
21#include "FastEngine/C_compressor.hpp"
22#include <limits>
23
24/*
25 * This file is using the library :
26 * LZ4 - Fast LZ compression algorithm
27 * Copyright (C) 2011-present, Yann Collet.
28 * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
29 */
30
31#define FGE_COMPRESSOR_LZ4_EXTRA_BYTES 10
32#define FGE_COMPRESSOR_LZ4_DEFAULT_MAX_SIZE std::numeric_limits<uint16_t>::max()
33#define FGE_COMPRESSOR_LZ4HC_DEFAULT_MAX_SIZE std::numeric_limits<uint16_t>::max()
34#define FGE_COMPRESSOR_LZ4HC_DEFAULT_COMPRESSION_LEVEL 9
35#define FGE_COMPRESSOR_LZ4_VERSION "1.10.0"
36
37namespace fge
38{
39
40class FGE_API CompressorLZ4 : public Compressor
41{
42public:
43 using Compressor::Compressor;
44
45 [[nodiscard]] std::optional<ErrorString> compress(std::span<uint8_t const> const& rawData) override;
46 [[nodiscard]] std::optional<ErrorString> uncompress(std::span<uint8_t const> const& data) override;
47
48 void setMaxUncompressedSize(uint32_t value);
49 [[nodiscard]] uint32_t getMaxUncompressedSize() const;
50
51private:
52 uint32_t g_maxUncompressedSize{FGE_COMPRESSOR_LZ4_DEFAULT_MAX_SIZE};
53};
54
55class FGE_API CompressorLZ4HC : public Compressor
56{
57public:
58 using Compressor::Compressor;
59
60 [[nodiscard]] std::optional<ErrorString> compress(std::span<uint8_t const> const& rawData) override;
61 [[nodiscard]] std::optional<ErrorString> uncompress(std::span<uint8_t const> const& data) override;
62
63 void setMaxUncompressedSize(uint32_t value);
64 [[nodiscard]] uint32_t getMaxUncompressedSize() const;
65
66 void setCompressionLevel(int value);
67 [[nodiscard]] int getCompressionLevel() const;
68
69private:
70 uint32_t g_maxUncompressedSize{FGE_COMPRESSOR_LZ4HC_DEFAULT_MAX_SIZE};
71 int g_compressionLevel{FGE_COMPRESSOR_LZ4HC_DEFAULT_COMPRESSION_LEVEL};
72};
73
74} // namespace fge
75
76#endif // _FGE_C_COMPRESSORLZ4_HPP_INCLUDED
Definition C_compressorLZ4.hpp:56
Definition C_compressorLZ4.hpp:41