diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 2be5452..edbd719 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -83,7 +83,7 @@ "moduleExtensions": { "//cpp:deps.bzl%clp_ffi_go_ext_deps": { "general": { - "bzlTransitiveDigest": "NJV2vicSED6RPr8cfyJfGpXXSwQp6UQyDPTjsPMbcV8=", + "bzlTransitiveDigest": "B9oCb6w6eVxTzje85vfRMCZ78QDtBXi/nyYZj34KAMM=", "usagesDigest": "D7z6fAnG/fRPs4uUPHy4GqCSlDUekEARjYSWg2XD2fc=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -99,20 +99,20 @@ ], "strip_prefix": "json-fec56a1a16c6e1c1b1f4e116a20e79398282626c", "add_prefix": "json", - "build_file": "@@//cpp:clp_ext_com_github_nlohmann_json.bzl" + "build_file_content": "\ncc_library(\n name = \"libjson\",\n srcs = [\"json/single_include/nlohmann/json.hpp\"],\n hdrs = [\"json/single_include/nlohmann/json.hpp\"],\n includes = [\".\"],\n visibility = [\"//visibility:public\"],\n)\n" } }, "com_github_y_scope_clp": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "sha256": "3aea613f00b8ca2e07803c5774a2faf8d7a315d983093eb4ce23a14a73414f72", + "sha256": "1daaa432357ed470eb8a2b5e7c8b4064418fa0f5d89fd075c6f1b4aef1ac6319", "urls": [ - "https://github.com/y-scope/clp/archive/084efa35b7e9a63aecc5e327b97aea2a1cef83bc.zip" + "https://github.com/y-scope/clp/archive/3c1f0ad1c44b53d6c17fd7c1d578ec61616b5661.zip" ], - "strip_prefix": "clp-084efa35b7e9a63aecc5e327b97aea2a1cef83bc", + "strip_prefix": "clp-3c1f0ad1c44b53d6c17fd7c1d578ec61616b5661", "add_prefix": "clp", - "build_file": "@@//cpp:com_github_y_scope_clp.bzl" + "build_file_content": "\ncc_library(\n name = \"libclp_ffi_core\",\n srcs = [\n \"clp/components/core/src/clp/BufferReader.cpp\",\n \"clp/components/core/src/clp/ReaderInterface.cpp\",\n \"clp/components/core/src/clp/ffi/encoding_methods.cpp\",\n \"clp/components/core/src/clp/ffi/ir_stream/encoding_methods.cpp\",\n \"clp/components/core/src/clp/ffi/ir_stream/decoding_methods.cpp\",\n \"clp/components/core/src/clp/ffi/ir_stream/utils.cpp\",\n \"clp/components/core/src/clp/ir/parsing.cpp\",\n \"clp/components/core/src/clp/string_utils/string_utils.cpp\",\n ],\n hdrs = [\n \"clp/components/core/src/clp/BufferReader.hpp\",\n \"clp/components/core/src/clp/Defs.h\",\n \"clp/components/core/src/clp/ErrorCode.hpp\",\n \"clp/components/core/src/clp/ReaderInterface.hpp\",\n \"clp/components/core/src/clp/ffi/encoding_methods.hpp\",\n \"clp/components/core/src/clp/ffi/encoding_methods.inc\",\n \"clp/components/core/src/clp/ffi/ir_stream/byteswap.hpp\",\n \"clp/components/core/src/clp/ffi/ir_stream/encoding_methods.hpp\",\n \"clp/components/core/src/clp/ffi/ir_stream/decoding_methods.hpp\",\n \"clp/components/core/src/clp/ffi/ir_stream/decoding_methods.inc\",\n \"clp/components/core/src/clp/ffi/ir_stream/protocol_constants.hpp\",\n \"clp/components/core/src/clp/ffi/ir_stream/utils.hpp\",\n \"clp/components/core/src/clp/ir/parsing.inc\",\n \"clp/components/core/src/clp/ir/parsing.hpp\",\n \"clp/components/core/src/clp/ir/types.hpp\",\n \"clp/components/core/src/clp/string_utils/string_utils.hpp\",\n \"clp/components/core/src/clp/TraceableException.hpp\",\n \"clp/components/core/src/clp/time_types.hpp\",\n \"clp/components/core/src/clp/type_utils.hpp\",\n ],\n includes = [\n \"./clp/components/core/src\",\n \"./clp/components/core/src/clp\",\n ],\n copts = [\n \"-std=c++20\",\n ] + select({\n \"@platforms//os:osx\": [\n \"-mmacosx-version-min=10.15\",\n ],\n \"//conditions:default\": [],\n }),\n deps = [\n \"@clp_ext_com_github_nlohmann_json//:libjson\",\n ],\n visibility = [\"//visibility:public\"],\n)\n" } } }, diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 8cf7a51..45cae5d 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -36,7 +36,7 @@ if (NOT EXISTS ${CLP_SRC_DIR}) FetchContent_Declare( clp-core GIT_REPOSITORY https://github.com/y-scope/clp.git - GIT_TAG 084efa35b7e9a63aecc5e327b97aea2a1cef83bc + GIT_TAG 3c1f0ad1c44b53d6c17fd7c1d578ec61616b5661 SOURCE_DIR ${CLP_SRC_DIR} ) message(STATUS "Fetching CLP from github.") @@ -70,15 +70,21 @@ target_compile_options(${LIB_NAME} $<$>:-Wall -Wextra -Wpedantic -Werror> ) +# Mark below headers as system headers so that the compiler (including clang-tidy) doesn't generate +# warnings from them. target_include_directories(${LIB_NAME} SYSTEM PRIVATE ${CLP_SRC_DIR}/components/core/submodules - ${CMAKE_CURRENT_SOURCE_DIR} + ${CLP_SRC_DIR}/components/core/src ) target_include_directories(${LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src + ${CLP_SRC_DIR}/components/core/src + # CLP source expects string_utils to be included as a library , but we + # directly bundle string_utils source files so we must add it to the include path. + ${CLP_SRC_DIR}/components/core/src/clp ) target_sources(${LIB_NAME} PUBLIC @@ -94,27 +100,33 @@ target_sources(${LIB_NAME} PUBLIC src/ffi_go/ir/serializer.h src/ffi_go/search/wildcard_query.h PRIVATE - ${CLP_SRC_DIR}/components/core/src/BufferReader.cpp - ${CLP_SRC_DIR}/components/core/src/BufferReader.hpp - ${CLP_SRC_DIR}/components/core/src/Defs.h - ${CLP_SRC_DIR}/components/core/src/ErrorCode.hpp - ${CLP_SRC_DIR}/components/core/src/ReaderInterface.cpp - ${CLP_SRC_DIR}/components/core/src/ReaderInterface.hpp - ${CLP_SRC_DIR}/components/core/src/string_utils.cpp - ${CLP_SRC_DIR}/components/core/src/string_utils.hpp - ${CLP_SRC_DIR}/components/core/src/string_utils.inc - ${CLP_SRC_DIR}/components/core/src/TraceableException.hpp - ${CLP_SRC_DIR}/components/core/src/type_utils.hpp - ${CLP_SRC_DIR}/components/core/src/ffi/encoding_methods.cpp - ${CLP_SRC_DIR}/components/core/src/ffi/encoding_methods.hpp - ${CLP_SRC_DIR}/components/core/src/ffi/encoding_methods.inc - ${CLP_SRC_DIR}/components/core/src/ffi/ir_stream/byteswap.hpp - ${CLP_SRC_DIR}/components/core/src/ffi/ir_stream/encoding_methods.cpp - ${CLP_SRC_DIR}/components/core/src/ffi/ir_stream/encoding_methods.hpp - ${CLP_SRC_DIR}/components/core/src/ffi/ir_stream/decoding_methods.cpp - ${CLP_SRC_DIR}/components/core/src/ffi/ir_stream/decoding_methods.hpp - ${CLP_SRC_DIR}/components/core/src/ffi/ir_stream/decoding_methods.inc - ${CLP_SRC_DIR}/components/core/src/ffi/ir_stream/protocol_constants.hpp + ${CLP_SRC_DIR}/components/core/src/clp/BufferReader.cpp + ${CLP_SRC_DIR}/components/core/src/clp/BufferReader.hpp + ${CLP_SRC_DIR}/components/core/src/clp/Defs.h + ${CLP_SRC_DIR}/components/core/src/clp/ErrorCode.hpp + ${CLP_SRC_DIR}/components/core/src/clp/ffi/encoding_methods.cpp + ${CLP_SRC_DIR}/components/core/src/clp/ffi/encoding_methods.hpp + ${CLP_SRC_DIR}/components/core/src/clp/ffi/encoding_methods.inc + ${CLP_SRC_DIR}/components/core/src/clp/ffi/ir_stream/byteswap.hpp + ${CLP_SRC_DIR}/components/core/src/clp/ffi/ir_stream/encoding_methods.cpp + ${CLP_SRC_DIR}/components/core/src/clp/ffi/ir_stream/encoding_methods.hpp + ${CLP_SRC_DIR}/components/core/src/clp/ffi/ir_stream/decoding_methods.cpp + ${CLP_SRC_DIR}/components/core/src/clp/ffi/ir_stream/decoding_methods.hpp + ${CLP_SRC_DIR}/components/core/src/clp/ffi/ir_stream/decoding_methods.inc + ${CLP_SRC_DIR}/components/core/src/clp/ffi/ir_stream/protocol_constants.hpp + ${CLP_SRC_DIR}/components/core/src/clp/ffi/ir_stream/utils.cpp + ${CLP_SRC_DIR}/components/core/src/clp/ffi/ir_stream/utils.hpp + ${CLP_SRC_DIR}/components/core/src/clp/ir/parsing.cpp + ${CLP_SRC_DIR}/components/core/src/clp/ir/parsing.hpp + ${CLP_SRC_DIR}/components/core/src/clp/ir/parsing.inc + ${CLP_SRC_DIR}/components/core/src/clp/ir/types.hpp + ${CLP_SRC_DIR}/components/core/src/clp/ReaderInterface.cpp + ${CLP_SRC_DIR}/components/core/src/clp/ReaderInterface.hpp + ${CLP_SRC_DIR}/components/core/src/clp/string_utils/string_utils.cpp + ${CLP_SRC_DIR}/components/core/src/clp/string_utils/string_utils.hpp + ${CLP_SRC_DIR}/components/core/src/clp/TraceableException.hpp + ${CLP_SRC_DIR}/components/core/src/clp/time_types.hpp + ${CLP_SRC_DIR}/components/core/src/clp/type_utils.hpp src/ffi_go/types.hpp src/ffi_go/ir/decoder.cpp src/ffi_go/ir/deserializer.cpp diff --git a/cpp/deps.bzl b/cpp/deps.bzl index 74a113e..5be97d8 100644 --- a/cpp/deps.bzl +++ b/cpp/deps.bzl @@ -14,31 +14,40 @@ _build_com_github_y_scope_clp = """ cc_library( name = "libclp_ffi_core", srcs = [ - "clp/components/core/src/BufferReader.cpp", - "clp/components/core/src/ReaderInterface.cpp", - "clp/components/core/src/string_utils.cpp", - "clp/components/core/src/ffi/encoding_methods.cpp", - "clp/components/core/src/ffi/ir_stream/encoding_methods.cpp", - "clp/components/core/src/ffi/ir_stream/decoding_methods.cpp", + "clp/components/core/src/clp/BufferReader.cpp", + "clp/components/core/src/clp/ffi/encoding_methods.cpp", + "clp/components/core/src/clp/ffi/ir_stream/encoding_methods.cpp", + "clp/components/core/src/clp/ffi/ir_stream/decoding_methods.cpp", + "clp/components/core/src/clp/ffi/ir_stream/utils.cpp", + "clp/components/core/src/clp/ir/parsing.cpp", + "clp/components/core/src/clp/ReaderInterface.cpp", + "clp/components/core/src/clp/string_utils/string_utils.cpp", ], hdrs = [ - "clp/components/core/src/BufferReader.hpp", - "clp/components/core/src/Defs.h", - "clp/components/core/src/ErrorCode.hpp", - "clp/components/core/src/ReaderInterface.hpp", - "clp/components/core/src/string_utils.hpp", - "clp/components/core/src/string_utils.inc", - "clp/components/core/src/TraceableException.hpp", - "clp/components/core/src/type_utils.hpp", - "clp/components/core/src/ffi/encoding_methods.hpp", - "clp/components/core/src/ffi/encoding_methods.inc", - "clp/components/core/src/ffi/ir_stream/byteswap.hpp", - "clp/components/core/src/ffi/ir_stream/encoding_methods.hpp", - "clp/components/core/src/ffi/ir_stream/decoding_methods.hpp", - "clp/components/core/src/ffi/ir_stream/decoding_methods.inc", - "clp/components/core/src/ffi/ir_stream/protocol_constants.hpp", + "clp/components/core/src/clp/BufferReader.hpp", + "clp/components/core/src/clp/Defs.h", + "clp/components/core/src/clp/ErrorCode.hpp", + "clp/components/core/src/clp/ReaderInterface.hpp", + "clp/components/core/src/clp/ffi/encoding_methods.hpp", + "clp/components/core/src/clp/ffi/encoding_methods.inc", + "clp/components/core/src/clp/ffi/ir_stream/byteswap.hpp", + "clp/components/core/src/clp/ffi/ir_stream/encoding_methods.hpp", + "clp/components/core/src/clp/ffi/ir_stream/decoding_methods.hpp", + "clp/components/core/src/clp/ffi/ir_stream/decoding_methods.inc", + "clp/components/core/src/clp/ffi/ir_stream/protocol_constants.hpp", + "clp/components/core/src/clp/ffi/ir_stream/utils.hpp", + "clp/components/core/src/clp/ir/parsing.inc", + "clp/components/core/src/clp/ir/parsing.hpp", + "clp/components/core/src/clp/ir/types.hpp", + "clp/components/core/src/clp/string_utils/string_utils.hpp", + "clp/components/core/src/clp/TraceableException.hpp", + "clp/components/core/src/clp/time_types.hpp", + "clp/components/core/src/clp/type_utils.hpp", + ], + includes = [ + "./clp/components/core/src", + "./clp/components/core/src/clp", ], - includes = ["."], copts = [ "-std=c++20", ] + select({ @@ -69,8 +78,8 @@ def _clp_ext_com_github_nlohmann_json(): def com_github_y_scope_clp(): _clp_ext_com_github_nlohmann_json() - commit = "084efa35b7e9a63aecc5e327b97aea2a1cef83bc" - commit_sha256 = "3aea613f00b8ca2e07803c5774a2faf8d7a315d983093eb4ce23a14a73414f72" + commit = "3c1f0ad1c44b53d6c17fd7c1d578ec61616b5661" + commit_sha256 = "1daaa432357ed470eb8a2b5e7c8b4064418fa0f5d89fd075c6f1b4aef1ac6319" http_archive( name = "com_github_y_scope_clp", sha256 = commit_sha256, diff --git a/cpp/src/ffi_go/ir/decoder.cpp b/cpp/src/ffi_go/ir/decoder.cpp index 62a41a2..2706dde 100644 --- a/cpp/src/ffi_go/ir/decoder.cpp +++ b/cpp/src/ffi_go/ir/decoder.cpp @@ -4,15 +4,16 @@ #include #include -#include -#include +#include +#include +#include #include "ffi_go/api_decoration.h" #include "ffi_go/defs.h" #include "ffi_go/ir/types.hpp" namespace ffi_go::ir { -using namespace ffi::ir_stream; +using clp::ffi::ir_stream::IRErrorCode; namespace { /** @@ -29,18 +30,18 @@ template ) -> int { using encoded_var_t = std::conditional_t< std::is_same_v, - ffi::eight_byte_encoded_variable_t, - ffi::four_byte_encoded_variable_t>; + clp::ir::eight_byte_encoded_variable_t, + clp::ir::four_byte_encoded_variable_t>; if (nullptr == ir_decoder || nullptr == log_msg_view) { - return static_cast(IRErrorCode_Corrupted_IR); + return static_cast(IRErrorCode::IRErrorCode_Corrupted_IR); } Decoder* decoder{static_cast(ir_decoder)}; auto& log_msg{decoder->m_log_message}; log_msg.reserve(logtype.m_size + dict_vars.m_size); - IRErrorCode err{IRErrorCode_Success}; + IRErrorCode err{IRErrorCode::IRErrorCode_Success}; try { - log_msg = ffi::decode_message( + log_msg = clp::ffi::decode_message( std::string_view(logtype.m_data, logtype.m_size), vars.m_data, vars.m_size, @@ -48,8 +49,8 @@ template dict_var_end_offsets.m_data, dict_var_end_offsets.m_size ); - } catch (ffi::EncodingException const& e) { - err = IRErrorCode_Decode_Error; + } catch (clp::ffi::EncodingException const& e) { + err = IRErrorCode::IRErrorCode_Decode_Error; } log_msg_view->m_data = log_msg.data(); diff --git a/cpp/src/ffi_go/ir/deserializer.cpp b/cpp/src/ffi_go/ir/deserializer.cpp index 06e1a94..c25145c 100644 --- a/cpp/src/ffi_go/ir/deserializer.cpp +++ b/cpp/src/ffi_go/ir/deserializer.cpp @@ -10,11 +10,12 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "ffi_go/api_decoration.h" #include "ffi_go/defs.h" @@ -23,8 +24,14 @@ #include "ffi_go/types.hpp" namespace ffi_go::ir { -using namespace ffi; -using namespace ffi::ir_stream; +using clp::BufferReader; +using clp::ffi::ir_stream::cProtocol::Eof; +using clp::ffi::ir_stream::deserialize_preamble; +using clp::ffi::ir_stream::deserialize_tag; +using clp::ffi::ir_stream::get_encoding_type; +using clp::ffi::ir_stream::IRErrorCode; +using clp::ir::eight_byte_encoded_variable_t; +using clp::ir::four_byte_encoded_variable_t; namespace { /** @@ -60,23 +67,33 @@ auto deserialize_log_event( LogEventView* log_event ) -> int { if (nullptr == ir_deserializer || nullptr == ir_pos || nullptr == log_event) { - return static_cast(IRErrorCode_Corrupted_IR); + return static_cast(IRErrorCode::IRErrorCode_Corrupted_IR); } BufferReader ir_buf{static_cast(ir_view.m_data), ir_view.m_size}; Deserializer* deserializer{static_cast(ir_deserializer)}; + clp::ffi::ir_stream::encoded_tag_t tag{}; + if (auto const err{deserialize_tag(ir_buf, tag)}; IRErrorCode::IRErrorCode_Success != err) { + return static_cast(err); + } + if (Eof == tag) { + return static_cast(IRErrorCode::IRErrorCode_Eof); + } + IRErrorCode err{}; epoch_time_ms_t timestamp{}; if constexpr (std::is_same_v) { - err = eight_byte_encoding::decode_next_message( + err = clp::ffi::ir_stream::eight_byte_encoding::deserialize_log_event( ir_buf, + tag, deserializer->m_log_event.m_log_message, timestamp ); } else if constexpr (std::is_same_v) { epoch_time_ms_t timestamp_delta{}; - err = four_byte_encoding::decode_next_message( + err = clp::ffi::ir_stream::four_byte_encoding::deserialize_log_event( ir_buf, + tag, deserializer->m_log_event.m_log_message, timestamp_delta ); @@ -84,20 +101,20 @@ auto deserialize_log_event( } else { static_assert(cAlwaysFalse, "Invalid/unhandled encoding type"); } - if (IRErrorCode_Success != err) { + if (IRErrorCode::IRErrorCode_Success != err) { return static_cast(err); } deserializer->m_timestamp = timestamp; size_t pos{0}; - if (ErrorCode_Success != ir_buf.try_get_pos(pos)) { - return static_cast(IRErrorCode_Decode_Error); + if (clp::ErrorCode_Success != ir_buf.try_get_pos(pos)) { + return static_cast(IRErrorCode::IRErrorCode_Decode_Error); } *ir_pos = pos; log_event->m_log_message.m_data = deserializer->m_log_event.m_log_message.data(); log_event->m_log_message.m_size = deserializer->m_log_event.m_log_message.size(); log_event->m_timestamp = deserializer->m_timestamp; - return static_cast(IRErrorCode_Success); + return static_cast(IRErrorCode::IRErrorCode_Success); } template @@ -113,7 +130,7 @@ auto deserialize_wildcard_match( if (nullptr == ir_deserializer || nullptr == ir_pos || nullptr == log_event || nullptr == matching_query) { - return static_cast(IRErrorCode_Corrupted_IR); + return static_cast(IRErrorCode::IRErrorCode_Corrupted_IR); } BufferReader ir_buf{static_cast(ir_view.m_data), ir_view.m_size}; Deserializer* deserializer{static_cast(ir_deserializer)}; @@ -143,7 +160,11 @@ auto deserialize_wildcard_match( queries.cbegin(), queries.cend(), [&](std::pair const& query) -> bool { - return wildcard_match_unsafe(log_message, query.first, query.second); + return clp::string_utils::wildcard_match_unsafe( + log_message, + query.first, + query.second + ); } ); return {queries.cend() != found_query, found_query - queries.cbegin()}; @@ -154,17 +175,27 @@ auto deserialize_wildcard_match( IRErrorCode err{}; while (true) { + clp::ffi::ir_stream::encoded_tag_t tag{}; + if (err = deserialize_tag(ir_buf, tag); IRErrorCode::IRErrorCode_Success != err) { + return static_cast(err); + } + if (Eof == tag) { + return static_cast(IRErrorCode::IRErrorCode_Eof); + } + epoch_time_ms_t timestamp{}; if constexpr (std::is_same_v) { - err = eight_byte_encoding::decode_next_message( + err = clp::ffi::ir_stream::eight_byte_encoding::deserialize_log_event( ir_buf, + tag, deserializer->m_log_event.m_log_message, timestamp ); } else if constexpr (std::is_same_v) { epoch_time_ms_t timestamp_delta{}; - err = four_byte_encoding::decode_next_message( + err = clp::ffi::ir_stream::four_byte_encoding::deserialize_log_event( ir_buf, + tag, deserializer->m_log_event.m_log_message, timestamp_delta ); @@ -172,7 +203,7 @@ auto deserialize_wildcard_match( } else { static_assert(cAlwaysFalse, "Invalid/unhandled encoding type"); } - if (IRErrorCode_Success != err) { + if (IRErrorCode::IRErrorCode_Success != err) { return static_cast(err); } deserializer->m_timestamp = timestamp; @@ -181,7 +212,7 @@ auto deserialize_wildcard_match( // TODO this is an extremely fragile hack until the CLP ffi ir // code is refactored and IRErrorCode includes things beyond // decoding. - return static_cast(IRErrorCode_Incomplete_IR + 1); + return static_cast(IRErrorCode::IRErrorCode_Incomplete_IR + 1); } if (time_interval.m_lower > deserializer->m_timestamp) { continue; @@ -192,16 +223,16 @@ auto deserialize_wildcard_match( if (false == has_matching_query) { continue; } - size_t pos{0}; - if (ErrorCode_Success != ir_buf.try_get_pos(pos)) { - return static_cast(IRErrorCode_Decode_Error); + size_t curr_ir_pos{0}; + if (clp::ErrorCode_Success != ir_buf.try_get_pos(curr_ir_pos)) { + return static_cast(IRErrorCode::IRErrorCode_Decode_Error); } - *ir_pos = pos; + *ir_pos = curr_ir_pos; log_event->m_log_message.m_data = deserializer->m_log_event.m_log_message.data(); log_event->m_log_message.m_size = deserializer->m_log_event.m_log_message.size(); log_event->m_timestamp = deserializer->m_timestamp; *matching_query = matching_query_idx; - return static_cast(IRErrorCode_Success); + return static_cast(IRErrorCode::IRErrorCode_Success); } } } // namespace @@ -225,34 +256,35 @@ CLP_FFI_GO_METHOD auto ir_deserializer_new_deserializer_with_preamble( || nullptr == metadata_pos || nullptr == metadata_size || nullptr == ir_deserializer_ptr || nullptr == timestamp_ptr) { - return static_cast(IRErrorCode_Corrupted_IR); + return static_cast(IRErrorCode::IRErrorCode_Corrupted_IR); } BufferReader ir_buf{static_cast(ir_view.m_data), ir_view.m_size}; bool four_byte_encoding{}; if (IRErrorCode const err{get_encoding_type(ir_buf, four_byte_encoding)}; - IRErrorCode_Success != err) + IRErrorCode::IRErrorCode_Success != err) { return static_cast(err); } *ir_encoding = four_byte_encoding ? 1 : 0; - if (IRErrorCode const err{decode_preamble(ir_buf, *metadata_type, *metadata_pos, *metadata_size) + if (IRErrorCode const err{ + deserialize_preamble(ir_buf, *metadata_type, *metadata_pos, *metadata_size) }; - IRErrorCode_Success != err) + IRErrorCode::IRErrorCode_Success != err) { return static_cast(err); } size_t pos{0}; - if (ErrorCode_Success != ir_buf.try_get_pos(pos)) { - return static_cast(IRErrorCode_Decode_Error); + if (clp::ErrorCode_Success != ir_buf.try_get_pos(pos)) { + return static_cast(IRErrorCode::IRErrorCode_Decode_Error); } *ir_pos = pos; auto* deserializer{new Deserializer()}; *ir_deserializer_ptr = deserializer; *timestamp_ptr = &deserializer->m_timestamp; - return static_cast(IRErrorCode_Success); + return static_cast(IRErrorCode::IRErrorCode_Success); } CLP_FFI_GO_METHOD auto ir_deserializer_deserialize_eight_byte_log_event( diff --git a/cpp/src/ffi_go/ir/encoder.cpp b/cpp/src/ffi_go/ir/encoder.cpp index cf3a0b5..534e60c 100644 --- a/cpp/src/ffi_go/ir/encoder.cpp +++ b/cpp/src/ffi_go/ir/encoder.cpp @@ -6,15 +6,18 @@ #include #include -#include -#include +#include +#include +#include #include "ffi_go/api_decoration.h" #include "ffi_go/defs.h" #include "ffi_go/ir/types.hpp" namespace ffi_go::ir { -using namespace ffi::ir_stream; +using clp::ffi::ir_stream::IRErrorCode; +using clp::ir::eight_byte_encoded_variable_t; +using clp::ir::four_byte_encoded_variable_t; namespace { /** @@ -31,12 +34,12 @@ auto encode_log_message( ) -> int { using encoded_var_t = std::conditional_t< std::is_same_v, - ffi::eight_byte_encoded_variable_t, - ffi::four_byte_encoded_variable_t>; + eight_byte_encoded_variable_t, + four_byte_encoded_variable_t>; if (nullptr == ir_encoder || nullptr == logtype || nullptr == vars || nullptr == dict_vars || nullptr == dict_var_end_offsets) { - return static_cast(IRErrorCode_Corrupted_IR); + return static_cast(IRErrorCode::IRErrorCode_Corrupted_IR); } Encoder* encoder{static_cast*>(ir_encoder)}; auto& ir_log_msg{encoder->m_log_message}; @@ -45,14 +48,14 @@ auto encode_log_message( std::string_view const log_msg_view{log_message.m_data, log_message.m_size}; std::vector dict_var_offsets; if (false - == ffi::encode_message( + == clp::ffi::encode_message( log_msg_view, ir_log_msg.m_logtype, ir_log_msg.m_vars, dict_var_offsets )) { - return static_cast(IRErrorCode_Corrupted_IR); + return static_cast(IRErrorCode::IRErrorCode_Corrupted_IR); } // dict_var_offsets contains begin_pos followed by end_pos of each @@ -78,28 +81,28 @@ auto encode_log_message( dict_vars->m_size = ir_log_msg.m_dict_vars.size(); dict_var_end_offsets->m_data = ir_log_msg.m_dict_var_end_offsets.data(); dict_var_end_offsets->m_size = ir_log_msg.m_dict_var_end_offsets.size(); - return static_cast(IRErrorCode_Success); + return static_cast(IRErrorCode::IRErrorCode_Success); } } // namespace CLP_FFI_GO_METHOD auto ir_encoder_eight_byte_new() -> void* { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - return new Encoder{}; + return new Encoder{}; } CLP_FFI_GO_METHOD auto ir_encoder_four_byte_new() -> void* { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - return new Encoder{}; + return new Encoder{}; } CLP_FFI_GO_METHOD auto ir_encoder_eight_byte_close(void* ir_encoder) -> void { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - delete static_cast*>(ir_encoder); + delete static_cast*>(ir_encoder); } CLP_FFI_GO_METHOD auto ir_encoder_four_byte_close(void* ir_encoder) -> void { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - delete static_cast*>(ir_encoder); + delete static_cast*>(ir_encoder); } CLP_FFI_GO_METHOD auto ir_encoder_encode_eight_byte_log_message( diff --git a/cpp/src/ffi_go/ir/serializer.cpp b/cpp/src/ffi_go/ir/serializer.cpp index 69ffe62..93f5829 100644 --- a/cpp/src/ffi_go/ir/serializer.cpp +++ b/cpp/src/ffi_go/ir/serializer.cpp @@ -3,17 +3,18 @@ #include #include -#include -#include -#include +#include +#include +#include #include "ffi_go/api_decoration.h" #include "ffi_go/defs.h" #include "ffi_go/ir/types.hpp" namespace ffi_go::ir { -using namespace ffi; -using namespace ffi::ir_stream; +using clp::ffi::ir_stream::IRErrorCode; +using clp::ir::eight_byte_encoded_variable_t; +using clp::ir::four_byte_encoded_variable_t; namespace { /** @@ -50,24 +51,24 @@ auto new_serializer_with_preamble( ByteSpan* ir_view ) -> int { if (nullptr == ir_serializer_ptr || nullptr == ir_view) { - return static_cast(IRErrorCode_Corrupted_IR); + return static_cast(IRErrorCode::IRErrorCode_Corrupted_IR); } Serializer* serializer{new Serializer{}}; if (nullptr == serializer) { - return static_cast(IRErrorCode_Corrupted_IR); + return static_cast(IRErrorCode::IRErrorCode_Corrupted_IR); } *ir_serializer_ptr = serializer; bool success{false}; if constexpr (std::is_same_v) { - success = eight_byte_encoding::encode_preamble( + success = clp::ffi::ir_stream::eight_byte_encoding::serialize_preamble( std::string_view{ts_pattern.m_data, ts_pattern.m_size}, std::string_view{ts_pattern_syntax.m_data, ts_pattern_syntax.m_size}, std::string_view{time_zone_id.m_data, time_zone_id.m_size}, serializer->m_ir_buf ); } else if constexpr (std::is_same_v) { - success = four_byte_encoding::encode_preamble( + success = clp::ffi::ir_stream::four_byte_encoding::serialize_preamble( std::string_view{ts_pattern.m_data, ts_pattern.m_size}, std::string_view{ts_pattern_syntax.m_data, ts_pattern_syntax.m_size}, std::string_view{time_zone_id.m_data, time_zone_id.m_size}, @@ -78,12 +79,12 @@ auto new_serializer_with_preamble( static_assert(cAlwaysFalse, "Invalid/unhandled encoding type"); } if (false == success) { - return static_cast(IRErrorCode_Corrupted_IR); + return static_cast(IRErrorCode::IRErrorCode_Corrupted_IR); } ir_view->m_data = serializer->m_ir_buf.data(); ir_view->m_size = serializer->m_ir_buf.size(); - return static_cast(IRErrorCode_Success); + return static_cast(IRErrorCode::IRErrorCode_Success); } template @@ -94,7 +95,7 @@ auto serialize_log_event( ByteSpan* ir_view ) -> int { if (nullptr == ir_serializer || nullptr == ir_view) { - return static_cast(IRErrorCode_Corrupted_IR); + return static_cast(IRErrorCode::IRErrorCode_Corrupted_IR); } Serializer* serializer{static_cast(ir_serializer)}; serializer->m_ir_buf.clear(); @@ -102,14 +103,14 @@ auto serialize_log_event( bool success{false}; if constexpr (std::is_same_v) { - success = eight_byte_encoding::encode_message( + success = clp::ffi::ir_stream::eight_byte_encoding::serialize_log_event( timestamp_or_delta, std::string_view{log_message.m_data, log_message.m_size}, serializer->m_logtype, serializer->m_ir_buf ); } else if constexpr (std::is_same_v) { - success = four_byte_encoding::encode_message( + success = clp::ffi::ir_stream::four_byte_encoding::serialize_log_event( timestamp_or_delta, std::string_view{log_message.m_data, log_message.m_size}, serializer->m_logtype, @@ -119,12 +120,12 @@ auto serialize_log_event( static_assert(cAlwaysFalse, "Invalid/unhandled encoding type"); } if (false == success) { - return static_cast(IRErrorCode_Corrupted_IR); + return static_cast(IRErrorCode::IRErrorCode_Corrupted_IR); } ir_view->m_data = serializer->m_ir_buf.data(); ir_view->m_size = serializer->m_ir_buf.size(); - return static_cast(IRErrorCode_Success); + return static_cast(IRErrorCode::IRErrorCode_Success); } } // namespace diff --git a/cpp/src/ffi_go/ir/types.hpp b/cpp/src/ffi_go/ir/types.hpp index 2eb3406..5f82c47 100644 --- a/cpp/src/ffi_go/ir/types.hpp +++ b/cpp/src/ffi_go/ir/types.hpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include "ffi_go/types.hpp" @@ -51,7 +51,7 @@ struct Encoder { */ struct Deserializer { ffi_go::LogEventStorage m_log_event; - ffi::epoch_time_ms_t m_timestamp{}; + clp::ir::epoch_time_ms_t m_timestamp{}; }; /** diff --git a/cpp/src/ffi_go/search/wildcard_query.cpp b/cpp/src/ffi_go/search/wildcard_query.cpp index 4f248c0..80c8281 100644 --- a/cpp/src/ffi_go/search/wildcard_query.cpp +++ b/cpp/src/ffi_go/search/wildcard_query.cpp @@ -3,16 +3,16 @@ #include #include -#include +#include #include "ffi_go/api_decoration.h" #include "ffi_go/defs.h" namespace ffi_go::search { CLP_FFI_GO_METHOD auto wildcard_query_new(StringView query, void** ptr) -> StringView { - auto* clean{new std::string{ - clean_up_wildcard_search_string(std::string_view{query.m_data, query.m_size}) - }}; + auto* clean{new std::string{clp::string_utils::clean_up_wildcard_search_string( + std::string_view{query.m_data, query.m_size} + )}}; *ptr = clean; return {clean->data(), clean->size()}; } @@ -23,7 +23,7 @@ CLP_FFI_GO_METHOD auto wildcard_query_delete(void* str) -> void { } CLP_FFI_GO_METHOD auto wildcard_query_match(StringView target, WildcardQueryView query) -> int { - return static_cast(wildcard_match_unsafe( + return static_cast(clp::string_utils::wildcard_match_unsafe( {target.m_data, target.m_size}, {query.m_query.m_data, query.m_query.m_size}, query.m_case_sensitive diff --git a/lib/libclp_ffi_darwin_arm64.a b/lib/libclp_ffi_darwin_arm64.a index 56264af..e126c21 100644 Binary files a/lib/libclp_ffi_darwin_arm64.a and b/lib/libclp_ffi_darwin_arm64.a differ diff --git a/lib/libclp_ffi_linux_amd64.a b/lib/libclp_ffi_linux_amd64.a index 87ec756..a398ba8 100644 Binary files a/lib/libclp_ffi_linux_amd64.a and b/lib/libclp_ffi_linux_amd64.a differ