Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: kirkrodrigues <[email protected]>
  • Loading branch information
LinZhihao-723 and kirkrodrigues authored Jul 8, 2024
1 parent 317f07a commit a942d8c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions components/core/src/clp/ffi/ir_stream/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ auto get_schema_tree_node_type_from_msgpack_val(msgpack::object const& val
ret_val.emplace(SchemaTreeNode::Type::Int);
break;
case msgpack::type::FLOAT32:
case msgpack::type::FLOAT:
case msgpack::type::FLOAT64:
ret_val.emplace(SchemaTreeNode::Type::Float);
break;
case msgpack::type::STR:
Expand Down Expand Up @@ -286,14 +286,15 @@ auto Serializer<encoded_variable_t>::serialize_msgpack_map(msgpack::object const
working_stack.pop_back();
continue;
}

auto const& [key, val]{curr.get_next_child()};
auto const opt_schema_tree_node_type{get_schema_tree_node_type_from_msgpack_val(val)};
if (false == opt_schema_tree_node_type.has_value()) {
failure = true;
break;
}

auto const schema_tree_node_type{opt_schema_tree_node_type.value()};

SchemaTree::NodeLocator const locator{
curr.get_parent_id(),
key.as<string_view>(),
Expand Down Expand Up @@ -377,6 +378,7 @@ auto Serializer<encoded_variable_t>::serialize_schema_tree_node(
// Unknown type
return false;
}

auto const parent_id{locator.get_parent_id()};
if (parent_id <= UINT8_MAX) {
m_schema_tree_node_buf.push_back(cProtocol::Payload::SchemaTreeNodeParentIdUByte);
Expand All @@ -388,14 +390,15 @@ auto Serializer<encoded_variable_t>::serialize_schema_tree_node(
// Out of range
return false;
}

return serialize_string_packet(locator.get_key_name(), m_schema_tree_node_buf);
}

template <typename encoded_variable_t>
auto Serializer<encoded_variable_t>::serialize_key(SchemaTreeNode::id_t id) -> bool {
if (id <= UINT8_MAX) {
m_key_group_buf.push_back(cProtocol::Payload::KeyIdUByte);
m_key_group_buf.push_back(static_cast<int8_t>(static_cast<uint8_t>(id)));
m_key_group_buf.push_back(bit_cast<int8_t>(static_cast<uint8_t>(id)));
} else if (id <= UINT16_MAX) {
m_key_group_buf.push_back(cProtocol::Payload::KeyIdUShort);
serialize_int(static_cast<uint16_t>(id), m_key_group_buf);
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/clp/ffi/ir_stream/encoding_methods.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool serialize_log_event(
* @param message
* @param logtype
* @param ir_buf
* @return true on success, false otherwise
* @return Whether the message was serialized successfully.
*/
bool serialize_message(std::string_view message, std::string& logtype, std::vector<int8_t>& ir_buf);
} // namespace eight_byte_encoding
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/clp/ffi/ir_stream/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ auto serialize_string_packet(std::string_view str, std::vector<int8_t>& buf) ->
auto const length{str.length()};
if (length <= UINT8_MAX) {
buf.push_back(cProtocol::Payload::StrPacketLenUByte);
buf.push_back(static_cast<int8_t>(static_cast<uint8_t>(length)));
buf.push_back(bit_cast<int8_t>(static_cast<uint8_t>(length)));
} else if (length <= UINT16_MAX) {
buf.push_back(cProtocol::Payload::StrPacketLenUShort);
serialize_int(static_cast<uint16_t>(length), buf);
Expand Down

0 comments on commit a942d8c

Please sign in to comment.