-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/rb 143 compression pack network #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c79d539
NITWORK: Add compression and decompression without cmakeLists.txt for…
romainpanno b2c9c76
NITWORK: Fix compil zstd
Saverio976 7673130
NITWORK: Add compression and uncompression packets
romainpanno 027bad8
FORMAT-AUTO: automatic format on pull request #115
github-actions[bot] 9d6b9fc
NITWORK: Fix codeRabbit requests
romainpanno 0ccc214
Merge branch 'feature/RB-143-compression-pack-network' of github.com:…
romainpanno 5b4d88c
FORMAT-AUTO: automatic format on pull request #115
github-actions[bot] 69a13b0
NITWORK: Fix codeRabbit requests
romainpanno 64f2a4e
Merge branch 'feature/RB-143-compression-pack-network' of github.com:…
romainpanno 9bfe1ab
NITWORK: Fix codeRabbit requests
romainpanno f47b105
FORMAT-AUTO: automatic format on pull request #115
github-actions[bot] f9e795b
NITWORK: Fix codeRabbit request
romainpanno 22d3e79
NITWORK: Add rfc for compression in nitwork
romainpanno 9dfbece
NITWORK/RFC: Fix missing check of too big uncompressed datas and fix rfc
romainpanno ac29cf8
CICD: Add zstd to realease with action active on RB-143
romainpanno aaab9e4
CICD: Fix wrong caracters
romainpanno 920a0d9
CICD: Fix wrong branch name
romainpanno 532ee84
Merge remote-tracking branch 'origin/dev' into feature/RB-143-compres…
romainpanno 4bccb1a
NITWORK: Upgrade cmakeLists.txt for ztsd -> using release .tar
romainpanno c223425
NITWORK: Try fix zstd deps on windows and macos
Saverio976 df75593
CICD: Remove debug branch
Saverio976 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| cmake_minimum_required(VERSION 3.15) | ||
|
|
||
| include(FetchContent) | ||
|
|
||
| set(ZSTD_BUILD_STATIC ON) | ||
| set(ZSTD_BUILD_SHARED OFF) | ||
|
|
||
| FetchContent_Declare( | ||
| zstd | ||
| URL "https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz" | ||
| DOWNLOAD_EXTRACT_TIMESTAMP TRUE | ||
| SOURCE_SUBDIR build/cmake | ||
| ) | ||
|
|
||
| FetchContent_MakeAvailable(zstd) | ||
|
|
||
| target_link_libraries( | ||
| ${PROJECT_NAME_CLIENT} | ||
| PRIVATE | ||
| libzstd_static | ||
| ) | ||
|
|
||
| target_link_libraries( | ||
| ${PROJECT_NAME_SERVER} | ||
| PRIVATE | ||
| libzstd_static | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| ** EPITECH PROJECT, 2023 | ||
| ** r-type | ||
| ** File description: | ||
| ** zstd | ||
| */ | ||
|
|
||
| #include <array> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <zstd.h> | ||
|
|
||
| namespace Nitwork { | ||
| constexpr int MAX_PACKET_SIZE = 1024; | ||
| constexpr int COMPRESSION_LEVEL = 1; | ||
|
|
||
| class Zstd { | ||
| public: | ||
| template <typename T> | ||
| static std::vector<char> compress(const T &data) | ||
| { | ||
| if (!std::is_standard_layout_v<T> || !std::is_trivial_v<T>) { | ||
| throw std::runtime_error("ZSTD: Data must be POD"); | ||
| } | ||
| size_t const compressedSize = ZSTD_compressBound(sizeof(T)); | ||
| std::vector<char> compressedData(compressedSize); | ||
| size_t const result = ZSTD_compress( | ||
| compressedData.data(), | ||
| compressedSize, | ||
| reinterpret_cast<const char *>(&data), | ||
| sizeof(T), | ||
| COMPRESSION_LEVEL); | ||
|
|
||
| if (ZSTD_isError(result)) { | ||
| throw std::runtime_error( | ||
| std::string("ZSTD: Error while compressing: ") + ZSTD_getErrorName(result)); | ||
| } | ||
romainpanno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| compressedData.resize(result); | ||
| return compressedData; | ||
| } | ||
romainpanno marked this conversation as resolved.
Show resolved
Hide resolved
romainpanno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| static std::array<char, MAX_PACKET_SIZE> | ||
| decompress(const std::array<char, MAX_PACKET_SIZE> &data, size_t size) | ||
| { | ||
| std::array<char, MAX_PACKET_SIZE> decompressedArray = {0}; | ||
| size_t decompressedSize = | ||
| ZSTD_decompress(decompressedArray.data(), MAX_PACKET_SIZE, data.data(), size); | ||
|
|
||
| if (ZSTD_isError(decompressedSize) != 0U) { | ||
| throw std::runtime_error( | ||
| std::string("ZSTD: Error while decompressing: ") | ||
| + ZSTD_getErrorName(decompressedSize)); | ||
| } | ||
| return decompressedArray; | ||
romainpanno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
romainpanno marked this conversation as resolved.
Show resolved
Hide resolved
romainpanno marked this conversation as resolved.
Show resolved
Hide resolved
romainpanno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| static std::size_t getFrameContentSize(const std::array<char, MAX_PACKET_SIZE> &data) | ||
| { | ||
| std::size_t const frameContentSize = ZSTD_getFrameContentSize(data.data(), data.size()); | ||
|
|
||
| if (ZSTD_isError(frameContentSize) != 0U) { | ||
| throw std::runtime_error( | ||
| std::string("ZSTD: Error while getting frame content size: ") | ||
| + ZSTD_getErrorName(frameContentSize)); | ||
| } | ||
| return frameContentSize; | ||
romainpanno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
romainpanno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| } // namespace Nitwork | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.