From eac140e94693d32a14d241029d74ae97c20456a5 Mon Sep 17 00:00:00 2001 From: Julia Dark Date: Mon, 1 Aug 2022 21:45:37 -0400 Subject: [PATCH] Updates group serial/deserial to use sizeof only on types (#3399) --- tiledb/sm/group/group.cc | 2 +- tiledb/sm/group/group_member.cc | 2 +- tiledb/sm/group/group_member_v1.cc | 36 +++++++++++++++--------------- tiledb/sm/group/group_v1.cc | 9 ++++---- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/tiledb/sm/group/group.cc b/tiledb/sm/group/group.cc index d00f6900385..cdbd3ff1393 100644 --- a/tiledb/sm/group/group.cc +++ b/tiledb/sm/group/group.cc @@ -660,7 +660,7 @@ Status Group::apply_and_serialize(Buffer* buff) { std::tuple>> Group::deserialize( ConstBuffer* buff, const URI& group_uri, StorageManager* storage_manager) { uint32_t version = 0; - RETURN_NOT_OK_TUPLE(buff->read(&version, sizeof(version)), std::nullopt); + RETURN_NOT_OK_TUPLE(buff->read(&version, sizeof(uint32_t)), std::nullopt); if (version == 1) { return GroupV1::deserialize(buff, group_uri, storage_manager); } diff --git a/tiledb/sm/group/group_member.cc b/tiledb/sm/group/group_member.cc index 3f9a3de27c6..eaf78f73cae 100644 --- a/tiledb/sm/group/group_member.cc +++ b/tiledb/sm/group/group_member.cc @@ -73,7 +73,7 @@ Status GroupMember::serialize(Buffer*) { std::tuple>> GroupMember::deserialize(ConstBuffer* buff) { uint32_t version = 0; - RETURN_NOT_OK_TUPLE(buff->read(&version, sizeof(version)), std::nullopt); + RETURN_NOT_OK_TUPLE(buff->read(&version, sizeof(uint32_t)), std::nullopt); if (version == 1) { return GroupMemberV1::deserialize(buff); } diff --git a/tiledb/sm/group/group_member_v1.cc b/tiledb/sm/group/group_member_v1.cc index 32d7dbfd684..1d664a53827 100644 --- a/tiledb/sm/group/group_member_v1.cc +++ b/tiledb/sm/group/group_member_v1.cc @@ -48,18 +48,17 @@ GroupMemberV1::GroupMemberV1( // format_version (uint32_t) // type (uint8_t) // relative (uint8_t) -// uri_size (uint32_t) +// uri_size (uint64_t) // uri (string) Status GroupMemberV1::serialize(Buffer* buff) { - RETURN_NOT_OK(buff->write( - &GroupMemberV1::format_version_, sizeof(GroupMemberV1::format_version_))); + RETURN_NOT_OK(buff->write(&GroupMemberV1::format_version_, sizeof(uint32_t))); // Write type uint8_t type = static_cast(type_); - RETURN_NOT_OK(buff->write(&type, sizeof(type))); + RETURN_NOT_OK(buff->write(&type, sizeof(uint8_t))); // Write relative - RETURN_NOT_OK(buff->write(&relative_, sizeof(relative_))); + RETURN_NOT_OK(buff->write(&relative_, sizeof(uint8_t))); // Write uri uint64_t uri_size = uri_.to_string().size(); @@ -67,11 +66,11 @@ Status GroupMemberV1::serialize(Buffer* buff) { RETURN_NOT_OK(buff->write(uri_.c_str(), uri_size)); // Write name - bool name_set = name_.has_value(); - RETURN_NOT_OK(buff->write(&name_set, sizeof(bool))); - if (name_set) { + auto name_set = static_cast(name_.has_value()); + RETURN_NOT_OK(buff->write(&name_set, sizeof(uint8_t))); + if (name_.has_value()) { uint64_t name_size = name_->size(); - RETURN_NOT_OK(buff->write(&name_size, sizeof(name_size))); + RETURN_NOT_OK(buff->write(&name_size, sizeof(uint64_t))); RETURN_NOT_OK(buff->write(name_->data(), name_size)); } @@ -82,26 +81,27 @@ std::tuple>> GroupMemberV1::deserialize(ConstBuffer* buff) { uint8_t type_placeholder; RETURN_NOT_OK_TUPLE( - buff->read(&type_placeholder, sizeof(type_placeholder)), std::nullopt); + buff->read(&type_placeholder, sizeof(uint8_t)), std::nullopt); ObjectType type = static_cast(type_placeholder); - bool relative; - RETURN_NOT_OK_TUPLE(buff->read(&relative, sizeof(relative)), std::nullopt); + uint8_t relative_int; + RETURN_NOT_OK_TUPLE(buff->read(&relative_int, sizeof(uint8_t)), std::nullopt); + auto relative = static_cast(relative_int); uint64_t uri_size = 0; - RETURN_NOT_OK_TUPLE(buff->read(&uri_size, sizeof(uri_size)), std::nullopt); + RETURN_NOT_OK_TUPLE(buff->read(&uri_size, sizeof(uint64_t)), std::nullopt); std::string uri_string; uri_string.resize(uri_size); RETURN_NOT_OK_TUPLE(buff->read(&uri_string[0], uri_size), std::nullopt); - bool name_set; + uint8_t name_set_int; std::optional name; - RETURN_NOT_OK_TUPLE(buff->read(&name_set, sizeof(name_set)), std::nullopt); + RETURN_NOT_OK_TUPLE(buff->read(&name_set_int, sizeof(uint8_t)), std::nullopt); + auto name_set = static_cast(name_set_int); if (name_set) { uint64_t name_size = 0; - RETURN_NOT_OK_TUPLE( - buff->read(&name_size, sizeof(name_size)), std::nullopt); + RETURN_NOT_OK_TUPLE(buff->read(&name_size, sizeof(uint64_t)), std::nullopt); std::string name_string; name_string.resize(name_size); @@ -115,4 +115,4 @@ GroupMemberV1::deserialize(ConstBuffer* buff) { } } // namespace sm -} // namespace tiledb \ No newline at end of file +} // namespace tiledb diff --git a/tiledb/sm/group/group_v1.cc b/tiledb/sm/group/group_v1.cc index e7f2d43b7fc..7510351af9e 100644 --- a/tiledb/sm/group/group_v1.cc +++ b/tiledb/sm/group/group_v1.cc @@ -48,10 +48,9 @@ GroupV1::GroupV1(const URI& group_uri, StorageManager* storage_manager) // group_member #2 // ... Status GroupV1::serialize(Buffer* buff) { - RETURN_NOT_OK( - buff->write(&GroupV1::format_version_, sizeof(GroupV1::format_version_))); + RETURN_NOT_OK(buff->write(&GroupV1::format_version_, sizeof(uint32_t))); uint64_t group_member_num = members_.size(); - RETURN_NOT_OK(buff->write(&group_member_num, sizeof(group_member_num))); + RETURN_NOT_OK(buff->write(&group_member_num, sizeof(uint64_t))); for (auto& it : members_) { RETURN_NOT_OK(it.second->serialize(buff)); } @@ -65,7 +64,7 @@ std::tuple>> GroupV1::deserialize( uint64_t member_count = 0; RETURN_NOT_OK_TUPLE( - buff->read(&member_count, sizeof(member_count)), std::nullopt); + buff->read(&member_count, sizeof(uint64_t)), std::nullopt); for (uint64_t i = 0; i < member_count; i++) { auto&& [st, member] = GroupMember::deserialize(buff); @@ -76,4 +75,4 @@ std::tuple>> GroupV1::deserialize( return {Status::Ok(), group}; } } // namespace sm -} // namespace tiledb \ No newline at end of file +} // namespace tiledb