Skip to content

Commit

Permalink
Modify StreamReaderDataContext to accept the deserializer as a temp…
Browse files Browse the repository at this point in the history
…late parameter to prepare for adding another IR stream reader. (#28)

Co-authored-by: kirkrodrigues <[email protected]>
  • Loading branch information
davemarco and kirkrodrigues authored Nov 7, 2024
1 parent 8e3b660 commit 805c392
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
26 changes: 11 additions & 15 deletions src/clp_ffi_js/ir/StreamReaderDataContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@
#include <utility>

#include <clp/Array.hpp>
#include <clp/ir/LogEventDeserializer.hpp>
#include <clp/ir/types.hpp>
#include <clp/streaming_compression/zstd/Decompressor.hpp>
#include <clp/ReaderInterface.hpp>

namespace clp_ffi_js::ir {
/**
* The data context for a `StreamReader`. It encapsulates a chain of the following resources:
* A `clp::ir::LogEventDeserializer` that reads from a
* `clp::streaming_compression::zstd::Decompressor`, which in turn reads from a `clp::Array`.
* @tparam encoded_variable_t Type of encoded variables encoded in the stream.
* An IR deserializer class that reads from a `clp::ReaderInterface`, which in turn reads from a
* `clp::Array`.
* @tparam Deserializer Type of deserializer.
*/
template <typename encoded_variable_t>
template <typename Deserializer>
class StreamReaderDataContext {
public:
// Constructors
StreamReaderDataContext(
clp::Array<char>&& data_buffer,
std::unique_ptr<clp::streaming_compression::zstd::Decompressor>&& zstd_decompressor,
clp::ir::LogEventDeserializer<clp::ir::four_byte_encoded_variable_t> deserializer
std::unique_ptr<clp::ReaderInterface>&& reader,
Deserializer deserializer
)
: m_data_buffer{std::move(data_buffer)},
m_zstd_decompressor{std::move(zstd_decompressor)},
m_reader{std::move(reader)},
m_deserializer{std::move(deserializer)} {}

// Disable copy constructor and assignment operator
Expand All @@ -44,14 +42,12 @@ class StreamReaderDataContext {
/**
* @return A reference to the deserializer.
*/
[[nodiscard]] auto get_deserializer() -> clp::ir::LogEventDeserializer<encoded_variable_t>& {
return m_deserializer;
}
[[nodiscard]] auto get_deserializer() -> Deserializer& { return m_deserializer; }

private:
clp::Array<char> m_data_buffer;
std::unique_ptr<clp::streaming_compression::zstd::Decompressor> m_zstd_decompressor;
clp::ir::LogEventDeserializer<encoded_variable_t> m_deserializer;
std::unique_ptr<clp::ReaderInterface> m_reader;
Deserializer m_deserializer;
};
} // namespace clp_ffi_js::ir

Expand Down
10 changes: 4 additions & 6 deletions src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ auto UnstructuredIrStreamReader::create(
std::unique_ptr<ZstdDecompressor>&& zstd_decompressor,
clp::Array<char> data_array
) -> UnstructuredIrStreamReader {
auto result{
clp::ir::LogEventDeserializer<four_byte_encoded_variable_t>::create(*zstd_decompressor)
};
auto result{UnstructuredIrDeserializer::create(*zstd_decompressor)};
if (result.has_error()) {
auto const error_code{result.error()};
throw ClpFfiJsException{
Expand All @@ -55,7 +53,7 @@ auto UnstructuredIrStreamReader::create(
)
};
}
auto data_context = StreamReaderDataContext<four_byte_encoded_variable_t>(
auto data_context = StreamReaderDataContext<UnstructuredIrDeserializer>(
std::move(data_array),
std::move(zstd_decompressor),
std::move(result.value())
Expand Down Expand Up @@ -218,10 +216,10 @@ auto UnstructuredIrStreamReader::decode_range(size_t begin_idx, size_t end_idx,
}

UnstructuredIrStreamReader::UnstructuredIrStreamReader(
StreamReaderDataContext<four_byte_encoded_variable_t>&& stream_reader_data_context
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context
)
: m_stream_reader_data_context{std::make_unique<
StreamReaderDataContext<four_byte_encoded_variable_t>>(
StreamReaderDataContext<UnstructuredIrDeserializer>>(
std::move(stream_reader_data_context)
)},
m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()} {}
Expand Down
6 changes: 4 additions & 2 deletions src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <optional>
#include <vector>

#include <clp/ir/LogEventDeserializer.hpp>
#include <clp/ir/types.hpp>
#include <clp/TimestampPattern.hpp>
#include <emscripten/val.h>
Expand All @@ -17,6 +18,7 @@

namespace clp_ffi_js::ir {
using clp::ir::four_byte_encoded_variable_t;
using UnstructuredIrDeserializer = clp::ir::LogEventDeserializer<four_byte_encoded_variable_t>;

/**
* Mapping between an index in the filtered log events collection to an index in the unfiltered
Expand Down Expand Up @@ -75,12 +77,12 @@ class UnstructuredIrStreamReader : public StreamReader {
private:
// Constructor
explicit UnstructuredIrStreamReader(
StreamReaderDataContext<four_byte_encoded_variable_t>&& stream_reader_data_context
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context
);

// Variables
std::vector<LogEventWithLevel<four_byte_encoded_variable_t>> m_encoded_log_events;
std::unique_ptr<StreamReaderDataContext<four_byte_encoded_variable_t>>
std::unique_ptr<StreamReaderDataContext<UnstructuredIrDeserializer>>
m_stream_reader_data_context;
FilteredLogEventsMap m_filtered_log_event_map;
clp::TimestampPattern m_ts_pattern;
Expand Down

0 comments on commit 805c392

Please sign in to comment.