From 5d09598647166fc7af3f6175ba0389bee741b59a Mon Sep 17 00:00:00 2001 From: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:06:03 -0400 Subject: [PATCH] Update to the latest clp submodule commit. (#55) --- MANIFEST.in | 6 +- setup.py | 52 +++++++++------- src/clp | 2 +- src/clp_ffi_py/ExceptionFFI.hpp | 6 +- src/clp_ffi_py/Py_utils.cpp | 2 +- src/clp_ffi_py/Py_utils.hpp | 4 +- src/clp_ffi_py/ir/native/LogEvent.hpp | 10 +-- src/clp_ffi_py/ir/native/Metadata.cpp | 24 +++---- src/clp_ffi_py/ir/native/Metadata.hpp | 10 +-- src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp | 2 +- src/clp_ffi_py/ir/native/PyDecoderBuffer.hpp | 12 ++-- src/clp_ffi_py/ir/native/PyLogEvent.cpp | 10 +-- src/clp_ffi_py/ir/native/PyLogEvent.hpp | 4 +- src/clp_ffi_py/ir/native/PyMetadata.cpp | 4 +- src/clp_ffi_py/ir/native/PyMetadata.hpp | 2 +- src/clp_ffi_py/ir/native/PyQuery.cpp | 28 +++++---- src/clp_ffi_py/ir/native/PyQuery.hpp | 6 +- src/clp_ffi_py/ir/native/Query.cpp | 4 +- src/clp_ffi_py/ir/native/Query.hpp | 45 +++++++------- src/clp_ffi_py/ir/native/decoding_methods.cpp | 62 +++++++++---------- src/clp_ffi_py/ir/native/encoding_methods.cpp | 35 ++++++----- src/clp_ffi_py/utils.inc | 4 +- 22 files changed, 177 insertions(+), 157 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 88ef35e1..f3119eb6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,6 @@ -recursive-include src/clp/components/core/src *.h -recursive-include src/clp/components/core/src *.hpp -recursive-include src/clp/components/core/src *.inc +recursive-include src/clp/components/core/src/clp *.h +recursive-include src/clp/components/core/src/clp *.hpp +recursive-include src/clp/components/core/src/clp *.inc recursive-include src/clp_ffi_py *.hpp recursive-include src/clp_ffi_py *.inc recursive-include clp_ffi_py *.py diff --git a/setup.py b/setup.py index 0e2fb738..d792bcdb 100644 --- a/setup.py +++ b/setup.py @@ -6,35 +6,41 @@ from setuptools import setup, Extension from typing import List, Optional, Tuple +cpp_src_root: str = "src" +clp_src_root: str = f"{cpp_src_root}/clp/components/core/src/clp" +clp_submodule_root: str = f"{cpp_src_root}/clp/components/core/submodules" +clp_ffi_py_src_root: str = f"{cpp_src_root}/clp_ffi_py" + ir_native: Extension = Extension( name="clp_ffi_py.ir.native", language="c++", include_dirs=[ - "src", - "src/clp/components/core/submodules", + cpp_src_root, + clp_src_root, + clp_submodule_root, ], sources=[ - "src/clp/components/core/src/BufferReader.cpp", - "src/clp/components/core/src/ffi/ir_stream/decoding_methods.cpp", - "src/clp/components/core/src/ffi/ir_stream/encoding_methods.cpp", - "src/clp/components/core/src/ffi/encoding_methods.cpp", - "src/clp/components/core/src/ir/parsing.cpp", - "src/clp/components/core/src/ReaderInterface.cpp", - "src/clp/components/core/src/string_utils.cpp", - "src/clp/components/core/src/TraceableException.cpp", - "src/clp_ffi_py/ir/native/decoding_methods.cpp", - "src/clp_ffi_py/ir/native/encoding_methods.cpp", - "src/clp_ffi_py/ir/native/Metadata.cpp", - "src/clp_ffi_py/ir/native/PyDecoder.cpp", - "src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp", - "src/clp_ffi_py/ir/native/PyFourByteEncoder.cpp", - "src/clp_ffi_py/ir/native/PyLogEvent.cpp", - "src/clp_ffi_py/ir/native/PyMetadata.cpp", - "src/clp_ffi_py/ir/native/PyQuery.cpp", - "src/clp_ffi_py/ir/native/Query.cpp", - "src/clp_ffi_py/modules/ir_native.cpp", - "src/clp_ffi_py/Py_utils.cpp", - "src/clp_ffi_py/utils.cpp", + f"{clp_src_root}/BufferReader.cpp", + f"{clp_src_root}/ffi/ir_stream/decoding_methods.cpp", + f"{clp_src_root}/ffi/ir_stream/encoding_methods.cpp", + f"{clp_src_root}/ffi/encoding_methods.cpp", + f"{clp_src_root}/ir/parsing.cpp", + f"{clp_src_root}/ReaderInterface.cpp", + f"{clp_src_root}/string_utils/string_utils.cpp", + + f"{clp_ffi_py_src_root}/ir/native/decoding_methods.cpp", + f"{clp_ffi_py_src_root}/ir/native/encoding_methods.cpp", + f"{clp_ffi_py_src_root}/ir/native/Metadata.cpp", + f"{clp_ffi_py_src_root}/ir/native/PyDecoder.cpp", + f"{clp_ffi_py_src_root}/ir/native/PyDecoderBuffer.cpp", + f"{clp_ffi_py_src_root}/ir/native/PyFourByteEncoder.cpp", + f"{clp_ffi_py_src_root}/ir/native/PyLogEvent.cpp", + f"{clp_ffi_py_src_root}/ir/native/PyMetadata.cpp", + f"{clp_ffi_py_src_root}/ir/native/PyQuery.cpp", + f"{clp_ffi_py_src_root}/ir/native/Query.cpp", + f"{clp_ffi_py_src_root}/modules/ir_native.cpp", + f"{clp_ffi_py_src_root}/Py_utils.cpp", + f"{clp_ffi_py_src_root}/utils.cpp", ], extra_compile_args=[ "-std=c++20", diff --git a/src/clp b/src/clp index 2b884bd6..abf6826e 160000 --- a/src/clp +++ b/src/clp @@ -1 +1 @@ -Subproject commit 2b884bd6327c90f64cb31b1bdf98c0bcdcbb9f59 +Subproject commit abf6826e6e4e78e16c21e843d567b4588b814999 diff --git a/src/clp_ffi_py/ExceptionFFI.hpp b/src/clp_ffi_py/ExceptionFFI.hpp index 5accdda6..472ffed1 100644 --- a/src/clp_ffi_py/ExceptionFFI.hpp +++ b/src/clp_ffi_py/ExceptionFFI.hpp @@ -3,7 +3,7 @@ #include -#include +#include namespace clp_ffi_py { /** @@ -11,10 +11,10 @@ namespace clp_ffi_py { * execution. Note: for exceptions of CPython execution, please use CPython * interface to set the exception instead. */ -class ExceptionFFI : public TraceableException { +class ExceptionFFI : public clp::TraceableException { public: ExceptionFFI( - ErrorCode error_code, + clp::ErrorCode error_code, char const* const filename, int line_number, std::string message diff --git a/src/clp_ffi_py/Py_utils.cpp b/src/clp_ffi_py/Py_utils.cpp index 0a22c981..133ec9de 100644 --- a/src/clp_ffi_py/Py_utils.cpp +++ b/src/clp_ffi_py/Py_utils.cpp @@ -46,7 +46,7 @@ auto py_utils_init() -> bool { return true; } -auto py_utils_get_formatted_timestamp(ffi::epoch_time_ms_t timestamp, PyObject* timezone) +auto py_utils_get_formatted_timestamp(clp::ir::epoch_time_ms_t timestamp, PyObject* timezone) -> PyObject* { PyObjectPtr const func_args_ptr{Py_BuildValue("LO", timestamp, timezone)}; auto* func_args{func_args_ptr.get()}; diff --git a/src/clp_ffi_py/Py_utils.hpp b/src/clp_ffi_py/Py_utils.hpp index f9d11429..f9e7dfa5 100644 --- a/src/clp_ffi_py/Py_utils.hpp +++ b/src/clp_ffi_py/Py_utils.hpp @@ -3,7 +3,7 @@ #include // Must always be included before any other header files -#include +#include namespace clp_ffi_py { /** @@ -22,7 +22,7 @@ auto py_utils_init() -> bool; * timestamp. * @return nullptr on failure with the relevant Python exception and error set. */ -auto py_utils_get_formatted_timestamp(ffi::epoch_time_ms_t timestamp, PyObject* timezone) +auto py_utils_get_formatted_timestamp(clp::ir::epoch_time_ms_t timestamp, PyObject* timezone) -> PyObject*; /** diff --git a/src/clp_ffi_py/ir/native/LogEvent.hpp b/src/clp_ffi_py/ir/native/LogEvent.hpp index 942ffb2c..07132a65 100644 --- a/src/clp_ffi_py/ir/native/LogEvent.hpp +++ b/src/clp_ffi_py/ir/native/LogEvent.hpp @@ -3,7 +3,7 @@ #include -#include +#include namespace clp_ffi_py::ir::native { /** @@ -24,7 +24,7 @@ class LogEvent { */ explicit LogEvent( std::string_view log_message, - ffi::epoch_time_ms_t timestamp, + clp::ir::epoch_time_ms_t timestamp, size_t index, std::optional formatted_timestamp = std::nullopt ) @@ -42,7 +42,7 @@ class LogEvent { return std::string_view{m_log_message}; } - [[nodiscard]] auto get_timestamp() const -> ffi::epoch_time_ms_t { return m_timestamp; } + [[nodiscard]] auto get_timestamp() const -> clp::ir::epoch_time_ms_t { return m_timestamp; } [[nodiscard]] auto get_formatted_timestamp() const -> std::string { return m_formatted_timestamp; @@ -59,7 +59,7 @@ class LogEvent { auto set_log_message(std::string_view log_message) -> void { m_log_message = log_message; } - auto set_timestamp(ffi::epoch_time_ms_t timestamp) -> void { m_timestamp = timestamp; } + auto set_timestamp(clp::ir::epoch_time_ms_t timestamp) -> void { m_timestamp = timestamp; } auto set_formatted_timestamp(std::string const& formatted_timestamp) -> void { m_formatted_timestamp = formatted_timestamp; @@ -69,7 +69,7 @@ class LogEvent { private: std::string m_log_message; - ffi::epoch_time_ms_t m_timestamp; + clp::ir::epoch_time_ms_t m_timestamp; size_t m_index; std::string m_formatted_timestamp; }; diff --git a/src/clp_ffi_py/ir/native/Metadata.cpp b/src/clp_ffi_py/ir/native/Metadata.cpp index 837947ec..bf082546 100644 --- a/src/clp_ffi_py/ir/native/Metadata.cpp +++ b/src/clp_ffi_py/ir/native/Metadata.cpp @@ -1,6 +1,6 @@ #include "Metadata.hpp" -#include +#include #include #include @@ -22,7 +22,7 @@ auto is_valid_json_string_data(nlohmann::json const& json_data, char const* key) Metadata::Metadata(nlohmann::json const& metadata, bool is_four_byte_encoding) { if (false == is_four_byte_encoding) { throw ExceptionFFI( - ErrorCode_Unsupported, + clp::ErrorCode_Unsupported, __FILE__, __LINE__, "Eight Byte Preamble is not yet supported." @@ -30,12 +30,12 @@ Metadata::Metadata(nlohmann::json const& metadata, bool is_four_byte_encoding) { } m_is_four_byte_encoding = is_four_byte_encoding; - auto const* ref_timestamp_key{ - static_cast(ffi::ir_stream::cProtocol::Metadata::ReferenceTimestampKey) - }; + auto const* ref_timestamp_key{static_cast( + clp::ffi::ir_stream::cProtocol::Metadata::ReferenceTimestampKey + )}; if (false == is_valid_json_string_data(metadata, ref_timestamp_key)) { throw ExceptionFFI( - ErrorCode_MetadataCorrupted, + clp::ErrorCode_MetadataCorrupted, __FILE__, __LINE__, "Valid Reference Timestamp cannot be found in the metadata." @@ -43,17 +43,17 @@ Metadata::Metadata(nlohmann::json const& metadata, bool is_four_byte_encoding) { } try { std::string const ref_timestamp_str{metadata[ref_timestamp_key]}; - m_ref_timestamp = static_cast(std::stoull(ref_timestamp_str)); + m_ref_timestamp = static_cast(std::stoull(ref_timestamp_str)); } catch (std::exception const& ex) { - throw ExceptionFFI(ErrorCode_Unsupported, __FILE__, __LINE__, ex.what()); + throw ExceptionFFI(clp::ErrorCode_Unsupported, __FILE__, __LINE__, ex.what()); } auto const* timestamp_format_key{ - static_cast(ffi::ir_stream::cProtocol::Metadata::TimestampPatternKey) + static_cast(clp::ffi::ir_stream::cProtocol::Metadata::TimestampPatternKey) }; if (false == is_valid_json_string_data(metadata, timestamp_format_key)) { throw ExceptionFFI( - ErrorCode_MetadataCorrupted, + clp::ErrorCode_MetadataCorrupted, __FILE__, __LINE__, "Valid Timestamp Format cannot be found in the metadata." @@ -62,11 +62,11 @@ Metadata::Metadata(nlohmann::json const& metadata, bool is_four_byte_encoding) { m_timestamp_format = metadata[timestamp_format_key]; auto const* timezone_id_key{ - static_cast(ffi::ir_stream::cProtocol::Metadata::TimeZoneIdKey) + static_cast(clp::ffi::ir_stream::cProtocol::Metadata::TimeZoneIdKey) }; if (false == is_valid_json_string_data(metadata, timezone_id_key)) { throw ExceptionFFI( - ErrorCode_MetadataCorrupted, + clp::ErrorCode_MetadataCorrupted, __FILE__, __LINE__, "Valid Timezone ID cannot be found in the metadata." diff --git a/src/clp_ffi_py/ir/native/Metadata.hpp b/src/clp_ffi_py/ir/native/Metadata.hpp index 1fb4cdc0..b3419b20 100644 --- a/src/clp_ffi_py/ir/native/Metadata.hpp +++ b/src/clp_ffi_py/ir/native/Metadata.hpp @@ -3,7 +3,7 @@ #include -#include +#include #include namespace clp_ffi_py::ir::native { @@ -34,7 +34,7 @@ class Metadata { * timestamp from Unix epoch time. */ explicit Metadata( - ffi::epoch_time_ms_t ref_timestamp, + clp::ir::epoch_time_ms_t ref_timestamp, std::string timestamp_format, std::string timezone ) @@ -47,7 +47,9 @@ class Metadata { return m_is_four_byte_encoding; } - [[nodiscard]] auto get_ref_timestamp() const -> ffi::epoch_time_ms_t { return m_ref_timestamp; } + [[nodiscard]] auto get_ref_timestamp() const -> clp::ir::epoch_time_ms_t { + return m_ref_timestamp; + } [[nodiscard]] auto get_timestamp_format() const -> std::string const& { return m_timestamp_format; @@ -57,7 +59,7 @@ class Metadata { private: bool m_is_four_byte_encoding; - ffi::epoch_time_ms_t m_ref_timestamp; + clp::ir::epoch_time_ms_t m_ref_timestamp; std::string m_timestamp_format; std::string m_timezone_id; }; diff --git a/src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp b/src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp index 6741d820..a2ca646d 100644 --- a/src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp +++ b/src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp @@ -359,7 +359,7 @@ auto PyDecoderBuffer::test_streaming(uint32_t seed) -> PyObject* { commit_read_buffer_consumption(num_bytes_to_read); } return PyByteArray_FromStringAndSize( - size_checked_pointer_cast(read_bytes.data()), + clp::size_checked_pointer_cast(read_bytes.data()), static_cast(read_bytes.size()) ); } diff --git a/src/clp_ffi_py/ir/native/PyDecoderBuffer.hpp b/src/clp_ffi_py/ir/native/PyDecoderBuffer.hpp index 55996825..5081cfa3 100644 --- a/src/clp_ffi_py/ir/native/PyDecoderBuffer.hpp +++ b/src/clp_ffi_py/ir/native/PyDecoderBuffer.hpp @@ -5,7 +5,7 @@ #include -#include +#include #include #include @@ -90,9 +90,13 @@ class PyDecoderBuffer { return current_num_decoded_message; } - [[nodiscard]] auto get_ref_timestamp() const -> ffi::epoch_time_ms_t { return m_ref_timestamp; } + [[nodiscard]] auto get_ref_timestamp() const -> clp::ir::epoch_time_ms_t { + return m_ref_timestamp; + } - auto set_ref_timestamp(ffi::epoch_time_ms_t timestamp) -> void { m_ref_timestamp = timestamp; } + auto set_ref_timestamp(clp::ir::epoch_time_ms_t timestamp) -> void { + m_ref_timestamp = timestamp; + } /** * @return Number of unconsumed bytes stored in the current read buffer. @@ -217,7 +221,7 @@ class PyDecoderBuffer { PyMetadata* m_metadata; int8_t* m_read_buffer_mem_owner; std::span m_read_buffer; - ffi::epoch_time_ms_t m_ref_timestamp; + clp::ir::epoch_time_ms_t m_ref_timestamp; Py_ssize_t m_buffer_size; Py_ssize_t m_num_current_bytes_consumed; size_t m_num_decoded_message; diff --git a/src/clp_ffi_py/ir/native/PyLogEvent.cpp b/src/clp_ffi_py/ir/native/PyLogEvent.cpp index e21e9efb..5a22f891 100644 --- a/src/clp_ffi_py/ir/native/PyLogEvent.cpp +++ b/src/clp_ffi_py/ir/native/PyLogEvent.cpp @@ -43,7 +43,7 @@ auto PyLogEvent_init(PyLogEvent* self, PyObject* args, PyObject* keywords) -> in self->default_init(); char const* log_message{nullptr}; - ffi::epoch_time_ms_t timestamp{0}; + clp::ir::epoch_time_ms_t timestamp{0}; size_t index{0}; PyObject* metadata{Py_None}; if (false @@ -209,8 +209,8 @@ auto PyLogEvent_setstate(PyLogEvent* self, PyObject* state) -> PyObject* { PyErr_Format(PyExc_KeyError, clp_ffi_py::cSetstateKeyErrorTemplate, cStateTimestamp); return nullptr; } - ffi::epoch_time_ms_t timestamp{0}; - if (false == clp_ffi_py::parse_py_int(timestamp_obj, timestamp)) { + clp::ir::epoch_time_ms_t timestamp{0}; + if (false == clp_ffi_py::parse_py_int(timestamp_obj, timestamp)) { return nullptr; } @@ -471,7 +471,7 @@ auto PyLogEvent::get_formatted_message(PyObject* timezone) -> PyObject* { auto PyLogEvent::init( std::string_view log_message, - ffi::epoch_time_ms_t timestamp, + clp::ir::epoch_time_ms_t timestamp, size_t index, PyMetadata* metadata, std::optional formatted_timestamp @@ -504,7 +504,7 @@ auto PyLogEvent::module_level_init(PyObject* py_module) -> bool { auto PyLogEvent::create_new_log_event( std::string_view log_message, - ffi::epoch_time_ms_t timestamp, + clp::ir::epoch_time_ms_t timestamp, size_t index, PyMetadata* metadata ) -> PyLogEvent* { diff --git a/src/clp_ffi_py/ir/native/PyLogEvent.hpp b/src/clp_ffi_py/ir/native/PyLogEvent.hpp index 14576a02..08cd761e 100644 --- a/src/clp_ffi_py/ir/native/PyLogEvent.hpp +++ b/src/clp_ffi_py/ir/native/PyLogEvent.hpp @@ -39,7 +39,7 @@ class PyLogEvent { */ [[nodiscard]] auto init( std::string_view log_message, - ffi::epoch_time_ms_t timestamp, + clp::ir::epoch_time_ms_t timestamp, size_t index, PyMetadata* metadata, std::optional formatted_timestamp = std::nullopt @@ -134,7 +134,7 @@ class PyLogEvent { */ [[nodiscard]] static auto create_new_log_event( std::string_view log_message, - ffi::epoch_time_ms_t timestamp, + clp::ir::epoch_time_ms_t timestamp, size_t index, PyMetadata* metadata ) -> PyLogEvent*; diff --git a/src/clp_ffi_py/ir/native/PyMetadata.cpp b/src/clp_ffi_py/ir/native/PyMetadata.cpp index 1d4b5ea8..b7875662 100644 --- a/src/clp_ffi_py/ir/native/PyMetadata.cpp +++ b/src/clp_ffi_py/ir/native/PyMetadata.cpp @@ -35,7 +35,7 @@ auto PyMetadata_init(PyMetadata* self, PyObject* args, PyObject* keywords) -> in nullptr }; - ffi::epoch_time_ms_t ref_timestamp{0}; + clp::ir::epoch_time_ms_t ref_timestamp{0}; char const* input_timestamp_format{nullptr}; char const* input_timezone{nullptr}; @@ -220,7 +220,7 @@ PyType_Spec PyMetadata_type_spec{ } // namespace auto PyMetadata::init( - ffi::epoch_time_ms_t ref_timestamp, + clp::ir::epoch_time_ms_t ref_timestamp, char const* input_timestamp_format, char const* input_timezone ) -> bool { diff --git a/src/clp_ffi_py/ir/native/PyMetadata.hpp b/src/clp_ffi_py/ir/native/PyMetadata.hpp index 010b9462..ed0753ae 100644 --- a/src/clp_ffi_py/ir/native/PyMetadata.hpp +++ b/src/clp_ffi_py/ir/native/PyMetadata.hpp @@ -32,7 +32,7 @@ class PyMetadata { * set. */ [[nodiscard]] auto init( - ffi::epoch_time_ms_t ref_timestamp, + clp::ir::epoch_time_ms_t ref_timestamp, char const* input_timestamp_format, char const* input_timezone ) -> bool; diff --git a/src/clp_ffi_py/ir/native/PyQuery.cpp b/src/clp_ffi_py/ir/native/PyQuery.cpp index 35863d28..0830f404 100644 --- a/src/clp_ffi_py/ir/native/PyQuery.cpp +++ b/src/clp_ffi_py/ir/native/PyQuery.cpp @@ -3,7 +3,7 @@ #include "PyQuery.hpp" -#include +#include #include #include @@ -67,7 +67,7 @@ auto deserialize_wildcard_queries( return false; } wildcard_queries.emplace_back( - clean_up_wildcard_search_string(wildcard_query_view), + clp::string_utils::clean_up_wildcard_search_string(wildcard_query_view), static_cast(is_case_sensitive) ); } @@ -294,9 +294,12 @@ auto PyQuery_setstate(PyQuery* self, PyObject* state) -> PyObject* { ); return nullptr; } - ffi::epoch_time_ms_t search_time_lower_bound{0}; + clp::ir::epoch_time_ms_t search_time_lower_bound{0}; if (false - == parse_py_int(search_time_lower_bound_obj, search_time_lower_bound)) + == parse_py_int( + search_time_lower_bound_obj, + search_time_lower_bound + )) { return nullptr; } @@ -310,9 +313,12 @@ auto PyQuery_setstate(PyQuery* self, PyObject* state) -> PyObject* { ); return nullptr; } - ffi::epoch_time_ms_t search_time_upper_bound{0}; + clp::ir::epoch_time_ms_t search_time_upper_bound{0}; if (false - == parse_py_int(search_time_upper_bound_obj, search_time_upper_bound)) + == parse_py_int( + search_time_upper_bound_obj, + search_time_upper_bound + )) { return nullptr; } @@ -338,9 +344,9 @@ auto PyQuery_setstate(PyQuery* self, PyObject* state) -> PyObject* { ); return nullptr; } - ffi::epoch_time_ms_t search_time_termination_margin{0}; + clp::ir::epoch_time_ms_t search_time_termination_margin{0}; if (false - == parse_py_int( + == parse_py_int( search_time_termination_margin_obj, search_time_termination_margin )) @@ -607,10 +613,10 @@ PyType_Spec PyQuery_type_spec{ } // namespace auto PyQuery::init( - ffi::epoch_time_ms_t search_time_lower_bound, - ffi::epoch_time_ms_t search_time_upper_bound, + clp::ir::epoch_time_ms_t search_time_lower_bound, + clp::ir::epoch_time_ms_t search_time_upper_bound, std::vector const& wildcard_queries, - ffi::epoch_time_ms_t search_time_termination_margin + clp::ir::epoch_time_ms_t search_time_termination_margin ) -> bool { try { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) diff --git a/src/clp_ffi_py/ir/native/PyQuery.hpp b/src/clp_ffi_py/ir/native/PyQuery.hpp index 58ebf274..8679429a 100644 --- a/src/clp_ffi_py/ir/native/PyQuery.hpp +++ b/src/clp_ffi_py/ir/native/PyQuery.hpp @@ -33,10 +33,10 @@ class PyQuery { * set. */ [[nodiscard]] auto init( - ffi::epoch_time_ms_t search_time_lower_bound, - ffi::epoch_time_ms_t search_time_upper_bound, + clp::ir::epoch_time_ms_t search_time_lower_bound, + clp::ir::epoch_time_ms_t search_time_upper_bound, std::vector const& wildcard_queries, - ffi::epoch_time_ms_t search_time_termination_margin + clp::ir::epoch_time_ms_t search_time_termination_margin ) -> bool; /** diff --git a/src/clp_ffi_py/ir/native/Query.cpp b/src/clp_ffi_py/ir/native/Query.cpp index 332073ca..5585f9eb 100644 --- a/src/clp_ffi_py/ir/native/Query.cpp +++ b/src/clp_ffi_py/ir/native/Query.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include namespace clp_ffi_py::ir::native { auto Query::matches_wildcard_queries(std::string_view log_message) const -> bool { @@ -14,7 +14,7 @@ auto Query::matches_wildcard_queries(std::string_view log_message) const -> bool m_wildcard_queries.begin(), m_wildcard_queries.end(), [&](auto const& wildcard_query) { - return wildcard_match_unsafe( + return clp::string_utils::wildcard_match_unsafe( log_message, wildcard_query.get_wildcard_query(), wildcard_query.is_case_sensitive() diff --git a/src/clp_ffi_py/ir/native/Query.hpp b/src/clp_ffi_py/ir/native/Query.hpp index 8e8da60a..e2d6fc2a 100644 --- a/src/clp_ffi_py/ir/native/Query.hpp +++ b/src/clp_ffi_py/ir/native/Query.hpp @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -56,12 +56,12 @@ class WildcardQuery { */ class Query { public: - static constexpr ffi::epoch_time_ms_t const cTimestampMin{0}; - static constexpr ffi::epoch_time_ms_t const cTimestampMax{ - std::numeric_limits::max() + static constexpr clp::ir::epoch_time_ms_t const cTimestampMin{0}; + static constexpr clp::ir::epoch_time_ms_t const cTimestampMax{ + std::numeric_limits::max() }; - static constexpr ffi::epoch_time_ms_t const cDefaultSearchTimeTerminationMargin{ - static_cast(60 * 1000) + static constexpr clp::ir::epoch_time_ms_t const cDefaultSearchTimeTerminationMargin{ + static_cast(60 * 1000) }; /** @@ -83,9 +83,9 @@ class Query { * search termination timestamp (see note in the class' docstring). */ explicit Query( - ffi::epoch_time_ms_t search_time_lower_bound, - ffi::epoch_time_ms_t search_time_upper_bound, - ffi::epoch_time_ms_t search_time_termination_margin + clp::ir::epoch_time_ms_t search_time_lower_bound, + clp::ir::epoch_time_ms_t search_time_upper_bound, + clp::ir::epoch_time_ms_t search_time_termination_margin = cDefaultSearchTimeTerminationMargin ) : m_lower_bound_ts{search_time_lower_bound}, @@ -108,10 +108,11 @@ class Query { * @param search_time_termination_margin The margin used to determine the * search termination timestamp (see note in the class' docstring). */ - Query(ffi::epoch_time_ms_t search_time_lower_bound, - ffi::epoch_time_ms_t search_time_upper_bound, + Query(clp::ir::epoch_time_ms_t search_time_lower_bound, + clp::ir::epoch_time_ms_t search_time_upper_bound, std::vector wildcard_queries, - ffi::epoch_time_ms_t search_time_termination_margin = cDefaultSearchTimeTerminationMargin) + clp::ir::epoch_time_ms_t search_time_termination_margin + = cDefaultSearchTimeTerminationMargin) : m_lower_bound_ts{search_time_lower_bound}, m_upper_bound_ts{search_time_upper_bound}, m_search_termination_ts{ @@ -123,11 +124,11 @@ class Query { throw_if_ts_range_invalid(); } - [[nodiscard]] auto get_lower_bound_ts() const -> ffi::epoch_time_ms_t { + [[nodiscard]] auto get_lower_bound_ts() const -> clp::ir::epoch_time_ms_t { return m_lower_bound_ts; } - [[nodiscard]] auto get_upper_bound_ts() const -> ffi::epoch_time_ms_t { + [[nodiscard]] auto get_upper_bound_ts() const -> clp::ir::epoch_time_ms_t { return m_upper_bound_ts; } @@ -139,7 +140,7 @@ class Query { * @return The search time termination margin by calculating the difference * between m_search_termination_ts and m_upper_bound_ts. */ - [[nodiscard]] auto get_search_time_termination_margin() const -> ffi::epoch_time_ms_t { + [[nodiscard]] auto get_search_time_termination_margin() const -> clp::ir::epoch_time_ms_t { return m_search_termination_ts - m_upper_bound_ts; } @@ -148,7 +149,7 @@ class Query { * @return true if the given timestamp is in the search time range bounded * by the lower bound and the upper bound timestamp (inclusive). */ - [[nodiscard]] auto matches_time_range(ffi::epoch_time_ms_t ts) const -> bool { + [[nodiscard]] auto matches_time_range(clp::ir::epoch_time_ms_t ts) const -> bool { return m_lower_bound_ts <= ts && ts <= m_upper_bound_ts; } @@ -157,7 +158,7 @@ class Query { * @return Whether the given timestamp is safely outside this query's time * range (see note in the class' docstring). */ - [[nodiscard]] auto ts_safely_outside_time_range(ffi::epoch_time_ms_t ts) const -> bool { + [[nodiscard]] auto ts_safely_outside_time_range(clp::ir::epoch_time_ms_t ts) const -> bool { return m_search_termination_ts < ts; } @@ -190,7 +191,7 @@ class Query { auto throw_if_ts_range_invalid() const -> void { if (m_lower_bound_ts > m_upper_bound_ts) { throw ExceptionFFI( - ErrorCode_Unsupported, + clp::ErrorCode_Unsupported, __FILE__, __LINE__, "Search query lower bound timestamp exceeds the upper bound timestamp." @@ -198,9 +199,9 @@ class Query { } } - ffi::epoch_time_ms_t m_lower_bound_ts; - ffi::epoch_time_ms_t m_upper_bound_ts; - ffi::epoch_time_ms_t m_search_termination_ts; + clp::ir::epoch_time_ms_t m_lower_bound_ts; + clp::ir::epoch_time_ms_t m_upper_bound_ts; + clp::ir::epoch_time_ms_t m_search_termination_ts; std::vector m_wildcard_queries; }; } // namespace clp_ffi_py::ir::native diff --git a/src/clp_ffi_py/ir/native/decoding_methods.cpp b/src/clp_ffi_py/ir/native/decoding_methods.cpp index 47883c06..6e1b5ee9 100644 --- a/src/clp_ffi_py/ir/native/decoding_methods.cpp +++ b/src/clp_ffi_py/ir/native/decoding_methods.cpp @@ -4,10 +4,10 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -35,7 +35,7 @@ namespace { template concept TerminateHandlerSignature = requires(TerminateHandler handler) { { - handler(std::declval(), + handler(std::declval(), std::declval(), std::declval(), std::declval()) @@ -63,23 +63,23 @@ auto generic_decode_log_events( TerminateHandler terminate_handler ) -> PyObject* { std::string decoded_message; - ffi::epoch_time_ms_t timestamp_delta{0}; + clp::ir::epoch_time_ms_t timestamp_delta{0}; auto timestamp{decoder_buffer->get_ref_timestamp()}; size_t current_log_event_idx{0}; PyObject* return_value{nullptr}; while (true) { auto const unconsumed_bytes{decoder_buffer->get_unconsumed_bytes()}; - BufferReader ir_buffer{ - size_checked_pointer_cast(unconsumed_bytes.data()), + clp::BufferReader ir_buffer{ + clp::size_checked_pointer_cast(unconsumed_bytes.data()), unconsumed_bytes.size() }; - auto const err{ffi::ir_stream::four_byte_encoding::decode_next_message( + auto const err{clp::ffi::ir_stream::four_byte_encoding::deserialize_log_event( ir_buffer, decoded_message, timestamp_delta )}; - if (ffi::ir_stream::IRErrorCode_Incomplete_IR == err) { + if (clp::ffi::ir_stream::IRErrorCode_Incomplete_IR == err) { if (decoder_buffer->try_read()) { continue; } @@ -93,10 +93,10 @@ auto generic_decode_log_events( } return nullptr; } - if (ffi::ir_stream::IRErrorCode_Eof == err) { + if (clp::ffi::ir_stream::IRErrorCode_Eof == err) { Py_RETURN_NONE; } - if (ffi::ir_stream::IRErrorCode_Success != err) { + if (clp::ffi::ir_stream::IRErrorCode_Success != err) { PyErr_Format(PyExc_RuntimeError, cDecoderErrorCodeFormatStr, err); return nullptr; } @@ -138,16 +138,16 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) -> size_t ir_buffer_cursor_pos{0}; while (true) { auto const unconsumed_bytes{decoder_buffer->get_unconsumed_bytes()}; - BufferReader ir_buffer{ - size_checked_pointer_cast(unconsumed_bytes.data()), + clp::BufferReader ir_buffer{ + clp::size_checked_pointer_cast(unconsumed_bytes.data()), unconsumed_bytes.size() }; - auto const err{ffi::ir_stream::get_encoding_type(ir_buffer, is_four_byte_encoding)}; - if (ffi::ir_stream::IRErrorCode_Success == err) { + auto const err{clp::ffi::ir_stream::get_encoding_type(ir_buffer, is_four_byte_encoding)}; + if (clp::ffi::ir_stream::IRErrorCode_Success == err) { ir_buffer_cursor_pos = ir_buffer.get_pos(); break; } - if (ffi::ir_stream::IRErrorCode_Incomplete_IR != err) { + if (clp::ffi::ir_stream::IRErrorCode_Incomplete_IR != err) { PyErr_Format(PyExc_RuntimeError, cDecoderErrorCodeFormatStr, err); return nullptr; } @@ -161,26 +161,26 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) -> return nullptr; } - ffi::ir_stream::encoded_tag_t metadata_type_tag{0}; + clp::ffi::ir_stream::encoded_tag_t metadata_type_tag{0}; size_t metadata_pos{0}; uint16_t metadata_size{0}; while (true) { auto const unconsumed_bytes = decoder_buffer->get_unconsumed_bytes(); - BufferReader ir_buffer{ - size_checked_pointer_cast(unconsumed_bytes.data()), + clp::BufferReader ir_buffer{ + clp::size_checked_pointer_cast(unconsumed_bytes.data()), unconsumed_bytes.size() }; - auto const err{ffi::ir_stream::decode_preamble( + auto const err{clp::ffi::ir_stream::deserialize_preamble( ir_buffer, metadata_type_tag, metadata_pos, metadata_size )}; - if (ffi::ir_stream::IRErrorCode_Success == err) { + if (clp::ffi::ir_stream::IRErrorCode_Success == err) { ir_buffer_cursor_pos = ir_buffer.get_pos(); break; } - if (ffi::ir_stream::IRErrorCode_Incomplete_IR != err) { + if (clp::ffi::ir_stream::IRErrorCode_Incomplete_IR != err) { PyErr_Format(PyExc_RuntimeError, cDecoderErrorCodeFormatStr, err); return nullptr; } @@ -202,18 +202,18 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) -> nlohmann::json::parse(metadata_buffer.begin(), metadata_buffer.end()) ); std::string const version{metadata_json.at( - static_cast(ffi::ir_stream::cProtocol::Metadata::VersionKey) + static_cast(clp::ffi::ir_stream::cProtocol::Metadata::VersionKey) )}; - auto const error_code{ffi::ir_stream::validate_protocol_version(version)}; - if (ffi::ir_stream::IRProtocolErrorCode_Supported != error_code) { + auto const error_code{clp::ffi::ir_stream::validate_protocol_version(version)}; + if (clp::ffi::ir_stream::IRProtocolErrorCode_Supported != error_code) { switch (error_code) { - case ffi::ir_stream::IRProtocolErrorCode_Invalid: + case clp::ffi::ir_stream::IRProtocolErrorCode_Invalid: PyErr_Format(PyExc_RuntimeError, "Invalid version number: %s", version.c_str()); break; - case ffi::ir_stream::IRProtocolErrorCode_Too_New: + case clp::ffi::ir_stream::IRProtocolErrorCode_Too_New: PyErr_Format(PyExc_RuntimeError, "Version too new: %s", version.c_str()); break; - case ffi::ir_stream::IRProtocolErrorCode_Too_Old: + case clp::ffi::ir_stream::IRProtocolErrorCode_Too_Old: PyErr_Format(PyExc_RuntimeError, "Version too old: %s", version.c_str()); break; default: @@ -289,7 +289,7 @@ auto decode_next_log_event(PyObject* Py_UNUSED(self), PyObject* args, PyObject* if (false == is_query_given) { auto terminate_handler{ [metadata]( - ffi::epoch_time_ms_t timestamp, + clp::ir::epoch_time_ms_t timestamp, std::string_view log_message, size_t log_event_idx, PyObject*& return_value @@ -314,7 +314,7 @@ auto decode_next_log_event(PyObject* Py_UNUSED(self), PyObject* args, PyObject* auto const* query{py_query->get_query()}; auto query_terminate_handler{ [query, metadata]( - ffi::epoch_time_ms_t timestamp, + clp::ir::epoch_time_ms_t timestamp, std::string_view log_message, size_t log_event_idx, PyObject*& return_value diff --git a/src/clp_ffi_py/ir/native/encoding_methods.cpp b/src/clp_ffi_py/ir/native/encoding_methods.cpp index d3b816f5..5f0a6678 100644 --- a/src/clp_ffi_py/ir/native/encoding_methods.cpp +++ b/src/clp_ffi_py/ir/native/encoding_methods.cpp @@ -2,16 +2,16 @@ #include "encoding_methods.hpp" -#include -#include -#include -#include +#include +#include +#include +#include #include namespace clp_ffi_py::ir::native { auto encode_four_byte_preamble(PyObject* Py_UNUSED(self), PyObject* args) -> PyObject* { - ffi::epoch_time_ms_t ref_timestamp{}; + clp::ir::epoch_time_ms_t ref_timestamp{}; char const* input_timestamp_format{}; char const* input_timezone{}; Py_ssize_t input_timestamp_format_size{}; @@ -39,7 +39,7 @@ auto encode_four_byte_preamble(PyObject* Py_UNUSED(self), PyObject* args) -> PyO std::vector ir_buf; if (false - == ffi::ir_stream::four_byte_encoding::encode_preamble( + == clp::ffi::ir_stream::four_byte_encoding::serialize_preamble( timestamp_format, {}, timezone, @@ -52,14 +52,14 @@ auto encode_four_byte_preamble(PyObject* Py_UNUSED(self), PyObject* args) -> PyO } return PyByteArray_FromStringAndSize( - size_checked_pointer_cast(ir_buf.data()), + clp::size_checked_pointer_cast(ir_buf.data()), static_cast(ir_buf.size()) ); } auto encode_four_byte_message_and_timestamp_delta(PyObject* Py_UNUSED(self), PyObject* args) -> PyObject* { - ffi::epoch_time_ms_t delta{}; + clp::ir::epoch_time_ms_t delta{}; char const* input_buffer{}; Py_ssize_t input_buffer_size{}; if (0 == PyArg_ParseTuple(args, "Ly#", &delta, &input_buffer, &input_buffer_size)) { @@ -74,18 +74,18 @@ auto encode_four_byte_message_and_timestamp_delta(PyObject* Py_UNUSED(self), PyO // allocate sufficient space in advance ir_buf.reserve(input_buffer_size * 2); - if (false == ffi::ir_stream::four_byte_encoding::encode_message(msg, logtype, ir_buf)) { + if (false == clp::ffi::ir_stream::four_byte_encoding::serialize_message(msg, logtype, ir_buf)) { PyErr_SetString(PyExc_NotImplementedError, clp_ffi_py::ir::native::cEncodeMessageError); return nullptr; } - if (false == ffi::ir_stream::four_byte_encoding::encode_timestamp(delta, ir_buf)) { + if (false == clp::ffi::ir_stream::four_byte_encoding::serialize_timestamp(delta, ir_buf)) { PyErr_SetString(PyExc_NotImplementedError, clp_ffi_py::ir::native::cEncodeTimestampError); return nullptr; } return PyByteArray_FromStringAndSize( - size_checked_pointer_cast(ir_buf.data()), + clp::size_checked_pointer_cast(ir_buf.data()), static_cast(ir_buf.size()) ); } @@ -104,37 +104,38 @@ auto encode_four_byte_message(PyObject* Py_UNUSED(self), PyObject* args) -> PyOb // To avoid frequent resize of ir_buf, allocate sufficient space in advance ir_buf.reserve(input_buffer_size * 2); - if (false == ffi::ir_stream::four_byte_encoding::encode_message(msg, log_type, ir_buf)) { + if (false == clp::ffi::ir_stream::four_byte_encoding::serialize_message(msg, log_type, ir_buf)) + { PyErr_SetString(PyExc_NotImplementedError, clp_ffi_py::ir::native::cEncodeMessageError); return nullptr; } return PyByteArray_FromStringAndSize( - size_checked_pointer_cast(ir_buf.data()), + clp::size_checked_pointer_cast(ir_buf.data()), static_cast(ir_buf.size()) ); } auto encode_four_byte_timestamp_delta(PyObject* Py_UNUSED(self), PyObject* args) -> PyObject* { - ffi::epoch_time_ms_t delta{}; + clp::ir::epoch_time_ms_t delta{}; if (0 == PyArg_ParseTuple(args, "L", &delta)) { return nullptr; } std::vector ir_buf; - if (false == ffi::ir_stream::four_byte_encoding::encode_timestamp(delta, ir_buf)) { + if (false == clp::ffi::ir_stream::four_byte_encoding::serialize_timestamp(delta, ir_buf)) { PyErr_SetString(PyExc_NotImplementedError, clp_ffi_py::ir::native::cEncodeTimestampError); return nullptr; } return PyByteArray_FromStringAndSize( - size_checked_pointer_cast(ir_buf.data()), + clp::size_checked_pointer_cast(ir_buf.data()), static_cast(ir_buf.size()) ); } auto encode_end_of_ir(PyObject* Py_UNUSED(self)) -> PyObject* { - static constexpr char cEof{ffi::ir_stream::cProtocol::Eof}; + static constexpr char cEof{clp::ffi::ir_stream::cProtocol::Eof}; return PyByteArray_FromStringAndSize(&cEof, sizeof(cEof)); } } // namespace clp_ffi_py::ir::native diff --git a/src/clp_ffi_py/utils.inc b/src/clp_ffi_py/utils.inc index 5e09fb3f..da673e57 100644 --- a/src/clp_ffi_py/utils.inc +++ b/src/clp_ffi_py/utils.inc @@ -5,7 +5,7 @@ #include -#include +#include namespace clp_ffi_py { namespace { @@ -22,7 +22,7 @@ auto parse_py_int(PyObject* py_int, int_type& val) -> bool { if constexpr (std::is_same_v) { val = PyLong_AsSize_t(py_int); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { val = PyLong_AsLongLong(py_int); } else if constexpr (std::is_same_v) { val = PyLong_AsSsize_t(py_int);