diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index edbd719..42eba92 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -83,7 +83,7 @@ "moduleExtensions": { "//cpp:deps.bzl%clp_ffi_go_ext_deps": { "general": { - "bzlTransitiveDigest": "B9oCb6w6eVxTzje85vfRMCZ78QDtBXi/nyYZj34KAMM=", + "bzlTransitiveDigest": "h8TTHnwoy4Iw1MWyVqE6iKhr4HCMF5EWUuAbhqgLydc=", "usagesDigest": "D7z6fAnG/fRPs4uUPHy4GqCSlDUekEARjYSWg2XD2fc=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -112,7 +112,7 @@ ], "strip_prefix": "clp-3c1f0ad1c44b53d6c17fd7c1d578ec61616b5661", "add_prefix": "clp", - "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" + "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/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/ReaderInterface.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/src/ffi_go/ir/deserializer.cpp b/cpp/src/ffi_go/ir/deserializer.cpp index 1634f40..6f9acbb 100644 --- a/cpp/src/ffi_go/ir/deserializer.cpp +++ b/cpp/src/ffi_go/ir/deserializer.cpp @@ -27,16 +27,9 @@ namespace ffi_go::ir { using clp::BufferReader; -using clp::ffi::ir_stream::cProtocol::Eof; -using clp::ffi::ir_stream::cProtocol::Payload::UtcOffsetChange; -using clp::ffi::ir_stream::deserialize_preamble; -using clp::ffi::ir_stream::deserialize_tag; -using clp::ffi::ir_stream::encoded_tag_t; -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; -using clp::UtcOffset; namespace { /** @@ -64,22 +57,6 @@ template size_t* matching_query ) -> int; -/** - * Deserializes all the UTC offset change packets from the given IR stream. - * @param ir_buf - * @param tag Outputs the tag after deserializing UTC offset changes. - * @param utc_offset Outputs the last successfully deserialized UTC offset. - * updated by the last deserialized UTC offset on success. - * @return IRErrorCode::IRErrorCode_Success on success. - * @return IRErrorCode::IRErrorCode_Incomplete_IR if the reader doesn't contain enough data to - * deserialize. - */ -[[nodiscard]] auto deserialize_all_utc_offset_change_packets( - BufferReader& ir_buf, - encoded_tag_t& tag, - clp::UtcOffset& utc_offset -) -> IRErrorCode; - /** * Deserializes packets from the given IR buffer until a new log event is fully deserialized. * @tparam encoded_variable_t @@ -215,23 +192,6 @@ auto deserialize_wildcard_match( } } -auto deserialize_all_utc_offset_change_packets( - BufferReader& ir_buf, - encoded_tag_t& tag, - clp::UtcOffset& utc_offset -) -> IRErrorCode { - while (UtcOffsetChange == tag) { - if (auto const err{clp::ffi::ir_stream::deserialize_utc_offset_change(ir_buf, utc_offset)}) - { - return err; - } - if (auto const err{deserialize_tag(ir_buf, tag)}) { - return err; - } - } - return IRErrorCode::IRErrorCode_Success; -} - template auto deserialize_to_next_log_event(BufferReader& ir_buf, Deserializer* deserializer) -> IRErrorCode { @@ -240,18 +200,23 @@ auto deserialize_to_next_log_event(BufferReader& ir_buf, Deserializer* deseriali || std::is_same_v) ); - encoded_tag_t tag{}; - epoch_time_ms_t timestamp{}; - IRErrorCode err{}; + clp::ffi::ir_stream::encoded_tag_t tag{}; std::optional utc_offset; - if (err = deserialize_tag(ir_buf, tag); IRErrorCode::IRErrorCode_Success != err) { - return err; - } - - if (UtcOffsetChange == tag) { + while (true) { + if (IRErrorCode const err{clp::ffi::ir_stream::deserialize_tag(ir_buf, tag)}; + IRErrorCode::IRErrorCode_Success != err) + { + return err; + } + if (clp::ffi::ir_stream::cProtocol::Payload::UtcOffsetChange != tag) { + break; + } clp::UtcOffset deserialized_utc_offset{0}; - if (err = deserialize_all_utc_offset_change_packets(ir_buf, tag, deserialized_utc_offset); + if (IRErrorCode const err{clp::ffi::ir_stream::deserialize_utc_offset_change( + ir_buf, + deserialized_utc_offset + )}; IRErrorCode::IRErrorCode_Success != err) { return err; @@ -259,10 +224,12 @@ auto deserialize_to_next_log_event(BufferReader& ir_buf, Deserializer* deseriali utc_offset.emplace(deserialized_utc_offset); } - if (Eof == tag) { + if (clp::ffi::ir_stream::cProtocol::Eof == tag) { return IRErrorCode::IRErrorCode_Eof; } + IRErrorCode err{}; + epoch_time_ms_t timestamp{}; if constexpr (std::is_same_v) { err = clp::ffi::ir_stream::eight_byte_encoding::deserialize_log_event( ir_buf, @@ -270,7 +237,7 @@ auto deserialize_to_next_log_event(BufferReader& ir_buf, Deserializer* deseriali deserializer->m_log_event.m_log_message, timestamp ); - } else { + } else if constexpr (std::is_same_v) { epoch_time_ms_t timestamp_delta{}; err = clp::ffi::ir_stream::four_byte_encoding::deserialize_log_event( ir_buf, @@ -279,6 +246,8 @@ auto deserialize_to_next_log_event(BufferReader& ir_buf, Deserializer* deseriali timestamp_delta ); timestamp = deserializer->m_timestamp + timestamp_delta; + } else { + static_assert(cAlwaysFalse, "Invalid/unhandled encoding type"); } if (IRErrorCode::IRErrorCode_Success != err) { @@ -317,16 +286,19 @@ CLP_FFI_GO_METHOD auto ir_deserializer_new_deserializer_with_preamble( 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)}; + if (IRErrorCode const err{clp::ffi::ir_stream::get_encoding_type(ir_buf, four_byte_encoding)}; IRErrorCode::IRErrorCode_Success != err) { return static_cast(err); } *ir_encoding = four_byte_encoding ? 1 : 0; - if (IRErrorCode const err{ - deserialize_preamble(ir_buf, *metadata_type, *metadata_pos, *metadata_size) - }; + if (IRErrorCode const err{clp::ffi::ir_stream::deserialize_preamble( + ir_buf, + *metadata_type, + *metadata_pos, + *metadata_size + )}; IRErrorCode::IRErrorCode_Success != err) { return static_cast(err); diff --git a/lib/libclp_ffi_linux_amd64.a b/lib/libclp_ffi_linux_amd64.a index db1cf84..d437e26 100644 Binary files a/lib/libclp_ffi_linux_amd64.a and b/lib/libclp_ffi_linux_amd64.a differ