Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davemarco committed Nov 7, 2024
1 parent 8e3b660 commit c32dea4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
31 changes: 16 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.
* A CLP deserializer class that reads from a `clp::ReaderInterface`, which in turn reads from a
* `clp::Array`.
* @tparam deserializer_t Type of deserializer.
*/
template <typename encoded_variable_t>
template <typename deserializer_t>
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_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
Expand All @@ -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<encoded_variable_t>& {
return m_deserializer;
}
[[nodiscard]] auto get_deserializer() -> deserializer_t& { 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_t m_deserializer;
};
} // namespace clp_ffi_js::ir

Expand Down
8 changes: 4 additions & 4 deletions src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ auto UnstructuredIrStreamReader::create(
clp::Array<char> data_array
) -> UnstructuredIrStreamReader {
auto result{
clp::ir::LogEventDeserializer<four_byte_encoded_variable_t>::create(*zstd_decompressor)
UnstructuredIrDeserializer::create(*zstd_decompressor)
};
if (result.has_error()) {
auto const error_code{result.error()};
Expand All @@ -55,7 +55,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 +218,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 c32dea4

Please sign in to comment.