-
Notifications
You must be signed in to change notification settings - Fork 80
feat(core): Add boilerplate for LZMA decompressor. #708
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
Bill-hbrhbr
merged 6 commits into
y-scope:main
from
Bill-hbrhbr:add-lzma-decompressor-interface
Feb 2, 2025
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
884ef03
Add LZMA decompressor interface
Bill-hbrhbr ddbd60f
Add periods to end sentences when appropriate
Bill-hbrhbr c179d39
Change to return value descriptions for functions that change paramet…
Bill-hbrhbr efa32f9
Remove [[nodiscard]] from source files
Bill-hbrhbr 434f989
Update variable names and docstrings to the latest version
Bill-hbrhbr 7db5541
Change var names in src files
Bill-hbrhbr 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
51 changes: 51 additions & 0 deletions
51
components/core/src/clp/streaming_compression/lzma/Decompressor.cpp
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,51 @@ | ||
#include "Decompressor.hpp" | ||
|
||
#include <cstddef> | ||
|
||
#include "../../ErrorCode.hpp" | ||
#include "../../ReaderInterface.hpp" | ||
#include "../../TraceableException.hpp" | ||
|
||
namespace clp::streaming_compression::lzma { | ||
[[nodiscard]] auto Decompressor::try_read( | ||
[[maybe_unused]] char* buf, | ||
[[maybe_unused]] size_t num_bytes_to_read, | ||
[[maybe_unused]] size_t& num_bytes_read | ||
) -> ErrorCode { | ||
return ErrorCode_Unsupported; | ||
} | ||
|
||
[[nodiscard]] auto Decompressor::try_seek_from_begin([[maybe_unused]] size_t pos) -> ErrorCode { | ||
return ErrorCode_Unsupported; | ||
} | ||
|
||
[[nodiscard]] auto Decompressor::try_get_pos([[maybe_unused]] size_t& pos) -> ErrorCode { | ||
return ErrorCode_Unsupported; | ||
} | ||
|
||
auto Decompressor::open( | ||
[[maybe_unused]] char const* compressed_data_buf, | ||
[[maybe_unused]] size_t compressed_data_buf_size | ||
) -> void { | ||
throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); | ||
} | ||
|
||
auto Decompressor::open( | ||
[[maybe_unused]] ReaderInterface& file_reader, | ||
[[maybe_unused]] size_t file_read_buffer_capacity | ||
) -> void { | ||
throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); | ||
} | ||
|
||
auto Decompressor::close() -> void { | ||
throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); | ||
} | ||
|
||
[[nodiscard]] auto Decompressor::get_decompressed_stream_region( | ||
[[maybe_unused]] size_t decompressed_stream_pos, | ||
[[maybe_unused]] char* extraction_buf, | ||
[[maybe_unused]] size_t extraction_len | ||
) -> ErrorCode { | ||
return ErrorCode_Unsupported; | ||
} | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} // namespace clp::streaming_compression::lzma |
105 changes: 105 additions & 0 deletions
105
components/core/src/clp/streaming_compression/lzma/Decompressor.hpp
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,105 @@ | ||
#ifndef CLP_STREAMING_COMPRESSION_LZMA_DECOMPRESSOR_HPP | ||
#define CLP_STREAMING_COMPRESSION_LZMA_DECOMPRESSOR_HPP | ||
|
||
#include <cstddef> | ||
|
||
#include "../../ErrorCode.hpp" | ||
#include "../../ReaderInterface.hpp" | ||
#include "../../TraceableException.hpp" | ||
#include "../Constants.hpp" | ||
#include "../Decompressor.hpp" | ||
|
||
namespace clp::streaming_compression::lzma { | ||
class Decompressor : public ::clp::streaming_compression::Decompressor { | ||
public: | ||
// Types | ||
class OperationFailed : public TraceableException { | ||
public: | ||
// Constructors | ||
OperationFailed(ErrorCode error_code, char const* const filename, int line_number) | ||
: TraceableException(error_code, filename, line_number) {} | ||
|
||
// Methods | ||
[[nodiscard]] auto what() const noexcept -> char const* override { | ||
return "streaming_compression::lzma::Decompressor operation failed"; | ||
} | ||
}; | ||
|
||
// Constructor | ||
Decompressor() : clp::streaming_compression::Decompressor(CompressorType::LZMA) {} | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Destructor | ||
~Decompressor() override = default; | ||
|
||
// Delete copy constructor and assignment operator | ||
Decompressor(Decompressor const&) = delete; | ||
auto operator=(Decompressor const&) -> Decompressor& = delete; | ||
|
||
// Delete move constructor and assignment operator | ||
// TODO: change to default when the base decompressor class has been updated | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Decompressor(Decompressor&&) noexcept = delete; | ||
auto operator=(Decompressor&&) noexcept -> Decompressor& = delete; | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Methods implementing the ReaderInterface | ||
/** | ||
* Tries to read up to a given number of bytes from the decompressor. | ||
* @param buf | ||
* @param num_bytes_to_read The number of bytes to try reading | ||
* @param num_bytes_read The actual number of bytes read | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @return ErrorCode_Unsupported | ||
*/ | ||
[[nodiscard]] auto try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) | ||
-> ErrorCode override; | ||
|
||
/** | ||
* Tries to seek from the beginning to the given position. | ||
* @param pos | ||
* @return ErrorCode_Unsupported | ||
*/ | ||
[[nodiscard]] auto try_seek_from_begin(size_t pos) -> ErrorCode override; | ||
|
||
/** | ||
* Tries to get the current position of the read head. | ||
* @param pos Position of the read head in the file | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @return ErrorCode_Unsupported | ||
*/ | ||
[[nodiscard]] auto try_get_pos(size_t& pos) -> ErrorCode override; | ||
|
||
// Methods implementing the Decompressor interface | ||
/*** | ||
* Initialize streaming decompressor to decompress from the specified compressed data buffer | ||
* @param compressed_data_buf | ||
* @param compressed_data_buf_size | ||
* @throw clp::streaming_compression::lzma::Decompressor::OperationFailed if unsupported | ||
*/ | ||
auto open(char const* compressed_data_buf, size_t compressed_data_buf_size) -> void override; | ||
|
||
/** | ||
* Initializes the decompressor to decompress from an open file | ||
* @param file_reader | ||
* @param file_read_buffer_capacity The maximum amount of data to read from a file at a time | ||
* @throw clp::streaming_compression::lzma::Decompressor::OperationFailed if unsupported | ||
*/ | ||
auto open(ReaderInterface& file_reader, size_t file_read_buffer_capacity) -> void override; | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/* | ||
* @throw clp::streaming_compression::lzma::Decompressor::OperationFailed if unsupported | ||
*/ | ||
auto close() -> void override; | ||
|
||
/** | ||
* Decompresses and copies the range of uncompressed data described by decompressed_stream_pos | ||
* and extraction_len into extraction_buf. | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param decompressed_stream_pos | ||
* @param extraction_buf | ||
* @param extraction_len | ||
* @return ErrorCode_Unsupported | ||
*/ | ||
[[nodiscard]] auto get_decompressed_stream_region( | ||
size_t decompressed_stream_pos, | ||
char* extraction_buf, | ||
size_t extraction_len | ||
) -> ErrorCode override; | ||
}; | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} // namespace clp::streaming_compression::lzma | ||
#endif // CLP_STREAMING_COMPRESSION_LZMA_DECOMPRESSOR_HPP |
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
Oops, something went wrong.
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.