diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index b9c86b6b..5a62ef3d 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -30,10 +30,11 @@ #include #include +namespace clp_ffi_js::ir { using namespace std::literals::string_literals; using clp::ir::four_byte_encoded_variable_t; +using clp::ir::LogEventDeserializer; -namespace clp_ffi_js::ir { auto StreamReader::create(DataArrayTsType const& data_array) -> StreamReader { auto const length{data_array["length"].as()}; SPDLOG_INFO("StreamReader::create: got buffer of length={}", length); @@ -89,11 +90,12 @@ auto StreamReader::create(DataArrayTsType const& data_array) -> StreamReader { }; } - StreamReaderDataContext stream_reader_data_context{ - std::move(data_buffer), - std::move(zstd_decompressor), - std::move(result.value()) - }; + StreamReaderDataContext> + stream_reader_data_context{ + std::move(data_buffer), + std::move(zstd_decompressor), + std::move(result.value()) + }; return StreamReader{std::move(stream_reader_data_context)}; } @@ -244,10 +246,11 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte } StreamReader::StreamReader( - StreamReaderDataContext&& stream_reader_data_context + StreamReaderDataContext>&& + stream_reader_data_context ) : m_stream_reader_data_context{std::make_unique< - StreamReaderDataContext>( + StreamReaderDataContext>>( std::move(stream_reader_data_context) )}, m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()} {} diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index dec6c360..f604d77c 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -15,6 +16,9 @@ #include namespace clp_ffi_js::ir { +using clp::ir::four_byte_encoded_variable_t; +using clp::ir::LogEventDeserializer; + EMSCRIPTEN_DECLARE_VAL_TYPE(DataArrayTsType); EMSCRIPTEN_DECLARE_VAL_TYPE(DecodedResultsTsType); EMSCRIPTEN_DECLARE_VAL_TYPE(FilteredLogEventMapTsType); @@ -97,12 +101,14 @@ class StreamReader { private: // Constructor - explicit StreamReader(StreamReaderDataContext&& - stream_reader_data_context); + explicit StreamReader( + StreamReaderDataContext>&& + stream_reader_data_context + ); // Variables - std::vector> m_encoded_log_events; - std::unique_ptr> + std::vector> m_encoded_log_events; + std::unique_ptr>> m_stream_reader_data_context; FilteredLogEventsMap m_filtered_log_event_map; clp::TimestampPattern m_ts_pattern; diff --git a/src/clp_ffi_js/ir/StreamReaderDataContext.hpp b/src/clp_ffi_js/ir/StreamReaderDataContext.hpp index 091b0b05..f672a33e 100644 --- a/src/clp_ffi_js/ir/StreamReaderDataContext.hpp +++ b/src/clp_ffi_js/ir/StreamReaderDataContext.hpp @@ -5,28 +5,26 @@ #include #include -#include -#include -#include +#include 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. + * A CLP IR deserializer class that reads from a `clp::ReaderInterface`, which in turn reads from a + * `clp::Array`. + * @tparam deserializer_t Type of IR deserializer. */ -template +template class StreamReaderDataContext { public: // Constructors StreamReaderDataContext( clp::Array&& data_buffer, - std::unique_ptr&& zstd_decompressor, - clp::ir::LogEventDeserializer deserializer + std::unique_ptr&& reader, + deserializer_t 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 @@ -41,17 +39,20 @@ class StreamReaderDataContext { ~StreamReaderDataContext() = default; // Methods + /** + * @return A reference to the reader. + */ + [[nodiscard]] auto get_reader() -> clp::ReaderInterface& { return *m_reader; } + /** * @return A reference to the deserializer. */ - [[nodiscard]] auto get_deserializer() -> clp::ir::LogEventDeserializer& { - return m_deserializer; - } + [[nodiscard]] auto get_deserializer() -> deserializer_t& { return m_deserializer; } private: clp::Array m_data_buffer; - std::unique_ptr m_zstd_decompressor; - clp::ir::LogEventDeserializer m_deserializer; + std::unique_ptr m_reader; + deserializer_t m_deserializer; }; } // namespace clp_ffi_js::ir