Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/core/src/clp/WriterInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class WriterInterface {
char const* what() const noexcept override { return "WriterInterface operation failed"; }
};

// Destructor
virtual ~WriterInterface() = default;

// Methods
/**
* Writes the given data to the underlying medium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Compressor : public WriterInterface {
Compressor() = default;

// Destructor
virtual ~Compressor() = default;
~Compressor() override = default;

// Delete copy constructor and assignment operator
Compressor(Compressor const&) = delete;
Expand Down
25 changes: 16 additions & 9 deletions components/core/src/clp/streaming_compression/Decompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Decompressor : public ReaderInterface {
: TraceableException(error_code, filename, line_number) {}

// Methods
char const* what() const noexcept override {
[[nodiscard]] auto what() const noexcept -> char const* override {
return "streaming_compression::Decompressor operation failed";
}
};
Expand All @@ -27,35 +27,42 @@ class Decompressor : public ReaderInterface {
explicit Decompressor(CompressorType type) : m_compression_type(type) {}

// Destructor
~Decompressor() = default;
~Decompressor() override = default;

// Explicitly disable copy and move constructor/assignment
// Delete copy constructor and assignment operator
Decompressor(Decompressor const&) = delete;
Decompressor& operator=(Decompressor const&) = delete;
auto operator=(Decompressor const&) -> Decompressor& = delete;

// Default move constructor and assignment operator
Decompressor(Decompressor&&) noexcept = default;
auto operator=(Decompressor&&) noexcept -> Decompressor& = default;

// Methods
/**
* Initialize streaming decompressor to decompress from the specified compressed data buffer
* @param compressed_data_buffer
* @param compressed_data_buffer_size
*/
virtual void open(char const* compressed_data_buffer, size_t compressed_data_buffer_size) = 0;
virtual auto open(char const* compressed_data_buffer, size_t compressed_data_buffer_size)
-> void
= 0;
/**
* Initializes the decompressor to decompress from a reader interface
* @param reader
* @param read_buffer_capacity The maximum amount of data to read from a reader at a time
*/
virtual void open(ReaderInterface& reader, size_t read_buffer_capacity) = 0;
virtual auto open(ReaderInterface& reader, size_t read_buffer_capacity) -> void = 0;
/**
* Closes decompression stream
*/
virtual void close() = 0;
virtual auto close() -> void = 0;

virtual ErrorCode get_decompressed_stream_region(
[[nodiscard]] virtual auto get_decompressed_stream_region(
size_t decompressed_stream_pos,
char* extraction_buf,
size_t extraction_len
) = 0;
) -> ErrorCode
= 0;

protected:
// Variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <cstring>

namespace clp::streaming_compression::passthrough {
ErrorCode Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) {
auto Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read)
-> ErrorCode {
if (InputType::NotInitialized == m_input_type) {
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
}
Expand Down Expand Up @@ -38,7 +39,7 @@ ErrorCode Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& nu
return ErrorCode_Success;
}

ErrorCode Decompressor::try_seek_from_begin(size_t pos) {
auto Decompressor::try_seek_from_begin(size_t pos) -> ErrorCode {
if (InputType::NotInitialized == m_input_type) {
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
}
Expand All @@ -64,7 +65,7 @@ ErrorCode Decompressor::try_seek_from_begin(size_t pos) {
return ErrorCode_Success;
}

ErrorCode Decompressor::try_get_pos(size_t& pos) {
auto Decompressor::try_get_pos(size_t& pos) -> ErrorCode {
if (InputType::NotInitialized == m_input_type) {
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
}
Expand All @@ -74,7 +75,7 @@ ErrorCode Decompressor::try_get_pos(size_t& pos) {
return ErrorCode_Success;
}

void Decompressor::open(char const* compressed_data_buf, size_t compressed_data_buf_size) {
auto Decompressor::open(char const* compressed_data_buf, size_t compressed_data_buf_size) -> void {
if (InputType::NotInitialized != m_input_type) {
throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__);
}
Expand All @@ -85,7 +86,8 @@ void Decompressor::open(char const* compressed_data_buf, size_t compressed_data_
m_input_type = InputType::CompressedDataBuf;
}

void Decompressor::open(ReaderInterface& reader, size_t read_buffer_capacity) {
auto Decompressor::open(ReaderInterface& reader, [[maybe_unused]] size_t read_buffer_capacity)
-> void {
if (InputType::NotInitialized != m_input_type) {
throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__);
}
Expand All @@ -95,7 +97,7 @@ void Decompressor::open(ReaderInterface& reader, size_t read_buffer_capacity) {
m_input_type = InputType::ReaderInterface;
}

void Decompressor::close() {
auto Decompressor::close() -> void {
switch (m_input_type) {
case InputType::CompressedDataBuf:
m_compressed_data_buf = nullptr;
Expand All @@ -113,11 +115,11 @@ void Decompressor::close() {
m_input_type = InputType::NotInitialized;
}

ErrorCode Decompressor::get_decompressed_stream_region(
auto Decompressor::get_decompressed_stream_region(
size_t decompressed_stream_pos,
char* extraction_buf,
size_t extraction_len
) {
) -> ErrorCode {
auto error_code = try_seek_from_begin(decompressed_stream_pos);
if (ErrorCode_Success != error_code) {
return error_code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
: TraceableException(error_code, filename, line_number) {}

// Methods
char const* what() const noexcept override {
[[nodiscard]] auto what() const noexcept -> char const* override {
return "streaming_compression::passthrough::Decompressor operation failed";
}
};
Expand All @@ -33,11 +33,15 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
m_decompressed_stream_pos(0) {}

// Destructor
~Decompressor() = default;
~Decompressor() override = default;

// Explicitly disable copy and move constructor/assignment
// Delete copy constructor and assignment operator
Decompressor(Decompressor const&) = delete;
Decompressor& operator=(Decompressor const&) = delete;
auto operator=(Decompressor const&) -> Decompressor& = delete;

// Default move constructor and assignment operator
Decompressor(Decompressor&&) noexcept = default;
auto operator=(Decompressor&&) noexcept -> Decompressor& = default;

// Methods implementing the ReaderInterface
/**
Expand All @@ -50,27 +54,28 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
* @return ErrorCode_EndOfFile on EOF
* @return ErrorCode_Success on success
*/
ErrorCode try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) override;
[[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_NotInit if the decompressor is not open
* @return ErrorCode_Truncated if the position is past the last byte in the file
* @return ErrorCode_Success on success
*/
ErrorCode try_seek_from_begin(size_t pos) override;
[[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
* @return ErrorCode_NotInit if the decompressor is not open
* @return ErrorCode_Success on success
*/
ErrorCode try_get_pos(size_t& pos) override;
[[nodiscard]] auto try_get_pos(size_t& pos) -> ErrorCode override;

// Methods implementing the Decompressor interface
void open(char const* compressed_data_buf, size_t compressed_data_buf_size) override;
void open(ReaderInterface& reader, size_t read_buffer_capacity) override;
void close() override;
auto open(char const* compressed_data_buf, size_t compressed_data_buf_size) -> void override;
auto open(ReaderInterface& reader, size_t read_buffer_capacity) -> void override;
auto close() -> void override;
/**
* Decompresses and copies the range of uncompressed data described by
* decompressed_stream_pos and extraction_len into extraction_buf
Expand All @@ -80,11 +85,11 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
* @return Same as streaming_compression::passthrough::Decompressor::try_seek_from_begin
* @return Same as ReaderInterface::try_read_exact_length
*/
ErrorCode get_decompressed_stream_region(
[[nodiscard]] auto get_decompressed_stream_region(
size_t decompressed_stream_pos,
char* extraction_buf,
size_t extraction_len
) override;
) -> ErrorCode override;

private:
enum class InputType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Decompressor::~Decompressor() {
ZSTD_freeDStream(m_decompression_stream);
}

ErrorCode Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) {
auto Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read)
-> ErrorCode {
if (InputType::NotInitialized == m_input_type) {
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
}
Expand Down Expand Up @@ -103,7 +104,7 @@ ErrorCode Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& nu
return ErrorCode_Success;
}

ErrorCode Decompressor::try_seek_from_begin(size_t pos) {
auto Decompressor::try_seek_from_begin(size_t pos) -> ErrorCode {
if (InputType::NotInitialized == m_input_type) {
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
}
Expand Down Expand Up @@ -134,7 +135,7 @@ ErrorCode Decompressor::try_seek_from_begin(size_t pos) {
return ErrorCode_Success;
}

ErrorCode Decompressor::try_get_pos(size_t& pos) {
auto Decompressor::try_get_pos(size_t& pos) -> ErrorCode {
if (InputType::NotInitialized == m_input_type) {
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
}
Expand All @@ -143,7 +144,7 @@ ErrorCode Decompressor::try_get_pos(size_t& pos) {
return ErrorCode_Success;
}

void Decompressor::open(char const* compressed_data_buf, size_t compressed_data_buf_size) {
auto Decompressor::open(char const* compressed_data_buf, size_t compressed_data_buf_size) -> void {
if (InputType::NotInitialized != m_input_type) {
throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__);
}
Expand All @@ -154,7 +155,7 @@ void Decompressor::open(char const* compressed_data_buf, size_t compressed_data_
reset_stream();
}

void Decompressor::open(ReaderInterface& reader, size_t read_buffer_capacity) {
auto Decompressor::open(ReaderInterface& reader, size_t read_buffer_capacity) -> void {
if (InputType::NotInitialized != m_input_type) {
throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__);
}
Expand All @@ -175,7 +176,7 @@ void Decompressor::open(ReaderInterface& reader, size_t read_buffer_capacity) {
reset_stream();
}

void Decompressor::close() {
auto Decompressor::close() -> void {
switch (m_input_type) {
case InputType::MemoryMappedCompressedFile:
m_memory_mapped_file.reset();
Expand All @@ -195,7 +196,7 @@ void Decompressor::close() {
m_input_type = InputType::NotInitialized;
}

ErrorCode Decompressor::open(std::string const& compressed_file_path) {
auto Decompressor::open(std::string const& compressed_file_path) -> ErrorCode {
if (InputType::NotInitialized != m_input_type) {
throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__);
}
Expand All @@ -213,11 +214,11 @@ ErrorCode Decompressor::open(std::string const& compressed_file_path) {
return ErrorCode_Success;
}

ErrorCode Decompressor::get_decompressed_stream_region(
auto Decompressor::get_decompressed_stream_region(
size_t decompressed_stream_pos,
char* extraction_buf,
size_t extraction_len
) {
) -> ErrorCode {
auto error_code = try_seek_from_begin(decompressed_stream_pos);
if (ErrorCode_Success != error_code) {
return error_code;
Expand All @@ -227,7 +228,7 @@ ErrorCode Decompressor::get_decompressed_stream_region(
return error_code;
}

void Decompressor::reset_stream() {
auto Decompressor::reset_stream() -> void {
if (InputType::ReaderInterface == m_input_type) {
if (auto const rc = m_reader->try_seek_from_begin(m_reader_initial_pos);
false == (ErrorCode_Success == rc || ErrorCode_EndOfFile == rc))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
: TraceableException(error_code, filename, line_number) {}

// Methods
char const* what() const noexcept override {
[[nodiscard]] auto what() const noexcept -> char const* override {
return "streaming_compression::zstd::Decompressor operation failed";
}
};
Expand All @@ -37,11 +37,15 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
Decompressor();

// Destructor
~Decompressor();
~Decompressor() override;

// Explicitly disable copy and move constructor/assignment
// Delete copy constructor and assignment operator
Decompressor(Decompressor const&) = delete;
Decompressor& operator=(Decompressor const&) = delete;
auto operator=(Decompressor const&) -> Decompressor& = delete;

// Default move constructor and assignment operator
Decompressor(Decompressor&&) noexcept = default;
auto operator=(Decompressor&&) noexcept -> Decompressor& = default;

// Methods implementing the ReaderInterface
/**
Expand All @@ -56,27 +60,28 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
* @return ErrorCode_Failure on decompression failure
* @return ErrorCode_Success on success
*/
ErrorCode try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) override;
[[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_NotInit if the decompressor is not open
* @return Same as ReaderInterface::try_read_exact_length
* @return ErrorCode_Success on success
*/
ErrorCode try_seek_from_begin(size_t pos) override;
[[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
* @return ErrorCode_NotInit if the decompressor is not open
* @return ErrorCode_Success on success
*/
ErrorCode try_get_pos(size_t& pos) override;
[[nodiscard]] auto try_get_pos(size_t& pos) -> ErrorCode override;

// Methods implementing the Decompressor interface
void open(char const* compressed_data_buf, size_t compressed_data_buf_size) override;
void open(ReaderInterface& reader, size_t read_buffer_capacity) override;
void close() override;
auto open(char const* compressed_data_buf, size_t compressed_data_buf_size) -> void override;
auto open(ReaderInterface& reader, size_t read_buffer_capacity) -> void override;
auto close() -> void override;
/**
* Decompresses and copies the range of uncompressed data described by
* decompressed_stream_pos and extraction_len into extraction_buf
Expand All @@ -86,11 +91,11 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
* @return Same as streaming_compression::zstd::Decompressor::try_seek_from_begin
* @return Same as ReaderInterface::try_read_exact_length
*/
ErrorCode get_decompressed_stream_region(
[[nodiscard]] auto get_decompressed_stream_region(
size_t decompressed_stream_pos,
char* extraction_buf,
size_t extraction_len
) override;
) -> ErrorCode override;

// Methods
/***
Expand All @@ -101,7 +106,7 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
* @return ErrorCode_Failure if the provided path cannot be memory mapped
* @return ErrorCode_Success on success
*/
ErrorCode open(std::string const& compressed_file_path);
[[nodiscard]] auto open(std::string const& compressed_file_path) -> ErrorCode;

private:
// Enum class
Expand Down