Skip to content

Commit

Permalink
take a map directly
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZhihao-723 committed Jul 8, 2024
1 parent 156ae44 commit bf4cbc4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
20 changes: 9 additions & 11 deletions components/core/src/clp/ffi/ir_stream/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,9 @@ auto Serializer<encoded_variable_t>::change_utc_offset(UtcOffset utc_offset) ->
}

template <typename encoded_variable_t>
auto Serializer<encoded_variable_t>::serialize_msgpack_map(msgpack::object const& msgpack_map
auto Serializer<encoded_variable_t>::serialize_msgpack_map(msgpack::object_map const& msgpack_map
) -> bool {
if (msgpack::type::MAP != msgpack_map.type) {
return false;
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
auto const& map{msgpack_map.via.map};
if (0 == map.size) {
if (0 == msgpack_map.size) {
serialize_empty_object(m_ir_buf);
return true;
}
Expand All @@ -280,7 +274,11 @@ auto Serializer<encoded_variable_t>::serialize_msgpack_map(msgpack::object const
// Traverse the map from the root using DFS iteratively.
bool failure{false};
vector<MsgpackMapIterator> working_stack;
working_stack.emplace_back(SchemaTree::cRootId, map.ptr, static_cast<size_t>(map.size));
working_stack.emplace_back(
SchemaTree::cRootId,
msgpack_map.ptr,
static_cast<size_t>(msgpack_map.size)
);
while (false == working_stack.empty()) {
auto& curr{working_stack.back()};
if (false == curr.has_next_child()) {
Expand Down Expand Up @@ -479,10 +477,10 @@ template auto Serializer<eight_byte_encoded_variable_t>::change_utc_offset(UtcOf
template auto Serializer<four_byte_encoded_variable_t>::change_utc_offset(UtcOffset utc_offset
) -> void;
template auto Serializer<four_byte_encoded_variable_t>::serialize_msgpack_map(
msgpack::object const& msgpack_map
msgpack::object_map const& msgpack_map
) -> bool;
template auto Serializer<eight_byte_encoded_variable_t>::serialize_msgpack_map(
msgpack::object const& msgpack_map
msgpack::object_map const& msgpack_map
) -> bool;
template auto Serializer<four_byte_encoded_variable_t>::serialize_schema_tree_node(
SchemaTree::NodeLocator const& locator
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/clp/ffi/ir_stream/Serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Serializer {
* @param msgpack_map msgpack key-value pair map to serialize, representing an log event.
* @return Whether the serialization succeeded.
*/
[[nodiscard]] auto serialize_msgpack_map(msgpack::object const& msgpack_map) -> bool;
[[nodiscard]] auto serialize_msgpack_map(msgpack::object_map const& msgpack_map) -> bool;

private:
// Constructors
Expand Down
6 changes: 5 additions & 1 deletion components/core/tests/test-ir_encoding_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ auto unpack_and_serialize_msgpack_bytes(
clp::size_checked_pointer_cast<char const>(msgpack_bytes.data()),
msgpack_bytes.size()
);
return serializer.serialize_msgpack_map(msgpack_oh.get());
auto const& msgpack_obj{msgpack_oh.get()};
if (msgpack::type::MAP != msgpack_obj.type) {
return false;
}
return serializer.serialize_msgpack_map(msgpack_obj.via.map);
}
} // namespace

Expand Down

0 comments on commit bf4cbc4

Please sign in to comment.