From e355fb76edb59d6286058dd4623eda0ca222a9e2 Mon Sep 17 00:00:00 2001 From: guochao Date: Thu, 12 Jun 2025 22:46:42 +0800 Subject: [PATCH 1/3] code format Signed-off-by: guochao --- .../route_head_handler_impl.cpp | 63 ++++++++-------- .../include/serializable/serializable.h | 75 ++++++++----------- .../framework/serializable/serializable.cpp | 49 ++++++------ 3 files changed, 89 insertions(+), 98 deletions(-) diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp index 9437ee8ac..ab2a03cbc 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp @@ -12,15 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#define LOG_TAG "RouteHeadHandler" #include "route_head_handler_impl.h" -#define LOG_TAG "RouteHeadHandler" #include #include -#include "account/account_delegate.h" -#include "auth_delegate.h" + #include "access_check/app_access_check_config_manager.h" +#include "account/account_delegate.h" #include "app_id_mapping/app_id_mapping_config_manager.h" +#include "auth_delegate.h" +#include "bootstrap.h" #include "device_manager_adapter.h" #include "kvstore_meta_manager.h" #include "log_print.h" @@ -28,7 +30,6 @@ #include "metadata/store_meta_data.h" #include "securec.h" #include "upgrade_manager.h" -#include "bootstrap.h" #include "utils/anonymous.h" #include "utils/endian_converter.h" @@ -73,13 +74,13 @@ void RouteHeadHandlerImpl::Init() userId_ = DEFAULT_USERID; } } - SessionPoint localPoint { DmAdapter::GetInstance().GetLocalDevice().uuid, + SessionPoint localPoint{ DmAdapter::GetInstance().GetLocalDevice().uuid, static_cast(atoi(userId_.c_str())), appId_, storeId_, AccountDelegate::GetInstance()->GetCurrentAccountId() }; session_ = SessionManager::GetInstance().GetSession(localPoint, deviceId_); ZLOGD("valid session:appId:%{public}s, srcDevId:%{public}s, srcUser:%{public}u, trgDevId:%{public}s,", - session_.appId.c_str(), Anonymous::Change(session_.sourceDeviceId).c_str(), - session_.sourceUserId, Anonymous::Change(session_.targetDeviceId).c_str()); + session_.appId.c_str(), Anonymous::Change(session_.sourceDeviceId).c_str(), session_.sourceUserId, + Anonymous::Change(session_.targetDeviceId).c_str()); } std::string RouteHeadHandlerImpl::GetTargetUserId() @@ -100,9 +101,8 @@ DistributedDB::DBStatus RouteHeadHandlerImpl::GetHeadDataSize(uint32_t &headSize ZLOGI("meta data permitted"); return DistributedDB::OK; } - if(!DmAdapter::GetInstance().IsOHOSType(session_.targetDeviceId)) { - ZLOGD("devicdId:%{public}s is not oh type", - Anonymous::Change(session_.targetDeviceId).c_str()); + if (!DmAdapter::GetInstance().IsOHOSType(session_.targetDeviceId)) { + ZLOGD("devicdId:%{public}s is not oh type", Anonymous::Change(session_.targetDeviceId).c_str()); if (appId_.empty()) { return DistributedDB::DB_ERROR; } @@ -127,14 +127,14 @@ DistributedDB::DBStatus RouteHeadHandlerImpl::GetHeadDataSize(uint32_t &headSize ZLOGI("no valid session to peer device"); return DistributedDB::DB_ERROR; } - size_t expectSize = sizeof(RouteHead) + sizeof(SessionDevicePair) + sizeof(SessionUserPair) + - session_.targetUserIds.size() * sizeof(int) + sizeof(SessionAppId) + session_.appId.size() + - sizeof(SessionStoreId) + session_.storeId.size() + sizeof(SessionAccountId) + session_.accountId.size(); + size_t expectSize = sizeof(RouteHead) + sizeof(SessionDevicePair) + sizeof(SessionUserPair) + + session_.targetUserIds.size() * sizeof(int) + sizeof(SessionAppId) + session_.appId.size() + + sizeof(SessionStoreId) + session_.storeId.size() + sizeof(SessionAccountId) + + session_.accountId.size(); // align message uint width headSize = GET_ALIGNED_SIZE(expectSize, ALIGN_WIDTH); - auto time = - static_cast(duration_cast(system_clock::now().time_since_epoch()).count()); + auto time = static_cast(duration_cast(system_clock::now().time_since_epoch()).count()); ZLOGI("packed size:%{public}u times %{public}" PRIu64 ".", headSize, time); headSize_ = headSize; return DistributedDB::OK; @@ -159,8 +159,7 @@ DistributedDB::DBStatus RouteHeadHandlerImpl::FillHeadData(uint8_t *data, uint32 bool RouteHeadHandlerImpl::PackData(uint8_t *data, uint32_t totalLen) { if (headSize_ > totalLen) { - ZLOGE("the buffer size is not enough, headSize:%{public}d, tatalLen:%{public}d", - headSize_, totalLen); + ZLOGE("the buffer size is not enough, headSize:%{public}d, tatalLen:%{public}d", headSize_, totalLen); return false; } @@ -224,8 +223,8 @@ bool RouteHeadHandlerImpl::PackAppId(uint8_t **data, const uint8_t *end) *data += sizeof(SessionAppId); auto ret = memcpy_s(appPair->appId, end - *data, session_.appId.c_str(), appIdSize); if (ret != EOK) { - ZLOGE("memcpy for app id failed, ret is %{public}d, leftSize is %{public}u, appIdSize is %{public}u", - ret, static_cast(end - *data), appIdSize); + ZLOGE("memcpy for app id failed, ret is %{public}d, leftSize is %{public}u, appIdSize is %{public}u", ret, + static_cast(end - *data), appIdSize); return false; } *data += appIdSize; @@ -240,8 +239,8 @@ bool RouteHeadHandlerImpl::PackStoreId(uint8_t **data, const uint8_t *end) *data += sizeof(SessionStoreId); auto ret = memcpy_s(storePair->storeId, end - *data, session_.storeId.data(), storeIdSize); if (ret != EOK) { - ZLOGE("memcpy for store id failed, ret is %{public}d, leftSize is %{public}u, storeIdSize is %{public}u", - ret, static_cast(end - *data), storeIdSize); + ZLOGE("memcpy for store id failed, ret is %{public}d, leftSize is %{public}u, storeIdSize is %{public}u", ret, + static_cast(end - *data), storeIdSize); return false; } *data += storeIdSize; @@ -263,8 +262,8 @@ bool RouteHeadHandlerImpl::PackAccountId(uint8_t **data, const uint8_t *end) return true; } -bool RouteHeadHandlerImpl::ParseHeadDataLen(const uint8_t *data, uint32_t totalLen, uint32_t &headSize, - const std::string &device) +bool RouteHeadHandlerImpl::ParseHeadDataLen( + const uint8_t *data, uint32_t totalLen, uint32_t &headSize, const std::string &device) { if (data == nullptr) { ZLOGE("invalid input data, totalLen:%{public}d", totalLen); @@ -301,8 +300,8 @@ std::string RouteHeadHandlerImpl::ParseStoreId(const std::string &deviceId, cons return ""; } -bool RouteHeadHandlerImpl::ParseHeadDataUser(const uint8_t *data, uint32_t totalLen, const std::string &label, - std::vector &userInfos) +bool RouteHeadHandlerImpl::ParseHeadDataUser( + const uint8_t *data, uint32_t totalLen, const std::string &label, std::vector &userInfos) { uint32_t headSize = 0; auto ret = UnPackData(data, totalLen, headSize); @@ -331,12 +330,14 @@ bool RouteHeadHandlerImpl::ParseHeadDataUser(const uint8_t *data, uint32_t total } // flip the local and peer ends - SessionPoint local { .deviceId = session_.targetDeviceId, .appId = session_.appId }; - SessionPoint peer { .deviceId = session_.sourceDeviceId, .userId = session_.sourceUserId, .appId = session_.appId, + SessionPoint local{ .deviceId = session_.targetDeviceId, .appId = session_.appId }; + SessionPoint peer{ .deviceId = session_.sourceDeviceId, + .userId = session_.sourceUserId, + .appId = session_.appId, .accountId = session_.accountId }; ZLOGD("valid session:appId:%{public}s, srcDevId:%{public}s, srcUser:%{public}u, trgDevId:%{public}s,", - session_.appId.c_str(), Anonymous::Change(session_.sourceDeviceId).c_str(), - session_.sourceUserId, Anonymous::Change(session_.targetDeviceId).c_str()); + session_.appId.c_str(), Anonymous::Change(session_.sourceDeviceId).c_str(), session_.sourceUserId, + Anonymous::Change(session_.targetDeviceId).c_str()); bool flag = false; auto peerCap = UpgradeManager::GetInstance().GetCapability(session_.sourceDeviceId, flag); if (!flag) { @@ -439,8 +440,8 @@ bool RouteHeadHandlerImpl::UnPackDataBody(const uint8_t *data, uint32_t totalLen ZLOGE("get peer cap failed, peer deviceId:%{public}s", Anonymous::Change(session_.sourceDeviceId).c_str()); return false; } - if (peerCap.version >= CapMetaData::ACCOUNT_VERSION && - (!UnPackStoreId(&ptr, leftSize) || !UnPackAccountId(&ptr, leftSize))) { + if (peerCap.version >= CapMetaData::ACCOUNT_VERSION + && (!UnPackStoreId(&ptr, leftSize) || !UnPackAccountId(&ptr, leftSize))) { return false; } return true; diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index 2fb72495a..2e8ed440e 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -15,10 +15,11 @@ #ifndef OHOS_DISTRIBUTED_DATA_FRAMEWORKS_COMMON_SERIALIZABLE_H #define OHOS_DISTRIBUTED_DATA_FRAMEWORKS_COMMON_SERIALIZABLE_H +#include #include #include #include -#include + #include "visibility.h" #ifndef JSON_NOEXCEPTION #define JSON_NOEXCEPTION @@ -33,7 +34,7 @@ namespace DistributedData { struct Serializable { public: class iterator; - class JSONWrapper final{ + class JSONWrapper final { public: friend iterator; enum class Type : uint8_t { @@ -44,11 +45,11 @@ public: API_EXPORT JSONWrapper(cJSON *json, cJSON *root, const std::string &key = ""); API_EXPORT JSONWrapper(const std::string &jsonStr); API_EXPORT JSONWrapper(JSONWrapper &&jsonWrapper); - + API_EXPORT operator std::string() const; API_EXPORT bool operator==(int32_t value) const; API_EXPORT bool operator==(const std::string &value) const; - + API_EXPORT JSONWrapper &operator=(JSONWrapper &&jsonWrapper); API_EXPORT JSONWrapper &operator=(JSONWrapper::Type type); API_EXPORT JSONWrapper &operator=(bool value); @@ -95,17 +96,18 @@ public: API_EXPORT static JSONWrapper array(); API_EXPORT void push_back(const JSONWrapper &value); API_EXPORT static std::string to_string(const JSONWrapper &jsonWrapper); - API_EXPORT bool operator==(const std::map& value) const; - API_EXPORT bool operator==(const std::map& value) const; - API_EXPORT bool operator==(const std::vector& value) const; + API_EXPORT bool operator==(const std::map &value) const; + API_EXPORT bool operator==(const std::map &value) const; + API_EXPORT bool operator==(const std::vector &value) const; API_EXPORT bool empty() const; - API_EXPORT JSONWrapper& operator=(const std::map& value); - API_EXPORT JSONWrapper &operator=(const std::map& value); - API_EXPORT bool erase(const std::string& key); + API_EXPORT JSONWrapper &operator=(const std::map &value); + API_EXPORT JSONWrapper &operator=(const std::map &value); + API_EXPORT bool erase(const std::string &key); API_EXPORT bool erase(int index); + private: void AddToRoot(); - JSONWrapper(const JSONWrapper& jsonWrapper) = delete; + JSONWrapper(const JSONWrapper &jsonWrapper) = delete; JSONWrapper &operator=(const JSONWrapper &jsonWrapper) = delete; bool ReplaceNode(cJSON *node); void SyncChildren() const; @@ -131,8 +133,7 @@ public: using json = JSONWrapper; API_EXPORT json Marshall() const; - template - static std::string Marshall(T &values) + template static std::string Marshall(T &values) { json root; SetValue(root, values); @@ -140,8 +141,7 @@ public: } API_EXPORT bool Unmarshall(const std::string &jsonStr); - template - static bool Unmarshall(const std::string &body, T &values) + template static bool Unmarshall(const std::string &body, T &values) { return GetValue(ToJson(body), "", values); } @@ -177,31 +177,26 @@ public: API_EXPORT static bool SetValue(json &node, const std::vector &value); API_EXPORT static bool SetValue(json &node, const Serializable &value); - template - API_EXPORT static bool SetValue(json &node, const std::variant<_Types...> &input); + template API_EXPORT static bool SetValue(json &node, const std::variant<_Types...> &input); template API_EXPORT static bool GetValue(const json &node, const std::string &name, std::variant<_Types...> &value); + protected: API_EXPORT ~Serializable() = default; - template - static bool GetValue(const json &node, const std::string &name, std::vector &values); + template static bool GetValue(const json &node, const std::string &name, std::vector &values); - template - static bool SetValue(json &node, const std::vector &values); + template static bool SetValue(json &node, const std::vector &values); template static bool GetValue(const json &node, const std::string &name, std::map &values); - template - static bool SetValue(json &node, const std::map &values); + template static bool SetValue(json &node, const std::map &values); - template - static bool GetValue(const json &node, const std::string &name, T *&value); + template static bool GetValue(const json &node, const std::string &name, T *&value); - template - static bool SetValue(json &node, const T *value); + template static bool SetValue(json &node, const T *value); template static bool ReadVariant(const json &node, const std::string &name, uint32_t step, uint32_t index, _OutTp &output); @@ -209,16 +204,14 @@ protected: template static bool ReadVariant(const json &node, const std::string &name, uint32_t step, uint32_t index, _OutTp &output); - template - static bool WriteVariant(json &node, uint32_t step, const _InTp &input); + template static bool WriteVariant(json &node, uint32_t step, const _InTp &input); template static bool WriteVariant(json &node, uint32_t step, const _InTp &input); API_EXPORT static const json &GetSubNode(const json &node, const std::string &name); }; -template -bool Serializable::GetValue(const json &node, const std::string &name, std::vector &values) +template bool Serializable::GetValue(const json &node, const std::string &name, std::vector &values) { auto &subNode = GetSubNode(node, name); if (subNode.is_null() || !subNode.is_array()) { @@ -233,8 +226,7 @@ bool Serializable::GetValue(const json &node, const std::string &name, std::vect return result; } -template -bool Serializable::SetValue(json &node, const std::vector &values) +template bool Serializable::SetValue(json &node, const std::vector &values) { bool result = true; size_t i = 0; @@ -260,8 +252,7 @@ bool Serializable::GetValue(const json &node, const std::string &name, std::map< return result; } -template -bool Serializable::SetValue(json &node, const std::map &values) +template bool Serializable::SetValue(json &node, const std::map &values) { bool result = true; node = JSONWrapper::Type::OBJECT; @@ -271,14 +262,13 @@ bool Serializable::SetValue(json &node, const std::map &values) return result; } -template -bool Serializable::GetValue(const json &node, const std::string &name, T *&value) +template bool Serializable::GetValue(const json &node, const std::string &name, T *&value) { auto &subNode = GetSubNode(node, name); if (subNode.is_null()) { return false; } - value = new(std::nothrow) T(); + value = new (std::nothrow) T(); if (value == nullptr) { return false; } @@ -290,8 +280,7 @@ bool Serializable::GetValue(const json &node, const std::string &name, T *&value return result; } -template -bool Serializable::SetValue(json &node, const T *value) +template bool Serializable::SetValue(json &node, const T *value) { if (value == nullptr) { return false; @@ -299,8 +288,7 @@ bool Serializable::SetValue(json &node, const T *value) return SetValue(node, *value); } -template -bool Serializable::SetValue(json &node, const std::variant<_Types...> &input) +template bool Serializable::SetValue(json &node, const std::variant<_Types...> &input) { bool ret = SetValue(node[GET_NAME(type)], input.index()); if (!ret) { @@ -325,8 +313,7 @@ bool Serializable::GetValue(const json &node, const std::string &name, std::vari return Serializable::ReadVariant(subNode, GET_NAME(value), 0, index, value); } -template -bool Serializable::WriteVariant(json &node, uint32_t step, const _InTp &input) +template bool Serializable::WriteVariant(json &node, uint32_t step, const _InTp &input) { return false; } diff --git a/services/distributeddataservice/framework/serializable/serializable.cpp b/services/distributeddataservice/framework/serializable/serializable.cpp index 5cb4c9265..ffa0bf487 100644 --- a/services/distributeddataservice/framework/serializable/serializable.cpp +++ b/services/distributeddataservice/framework/serializable/serializable.cpp @@ -14,10 +14,11 @@ */ #define LOG_TAG "serializable" -#include "log_print.h" #include "serializable/serializable.h" #include + +#include "log_print.h" namespace OHOS { namespace DistributedData { Serializable::json Serializable::Marshall() const @@ -291,7 +292,7 @@ Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(JSONWrapper &&js jsonWrapper.root_ = nullptr; key_ = std::move(jsonWrapper.key_); children_ = std::move(jsonWrapper.children_); - needDel_ = jsonWrapper.needDel_; + needDel_ = jsonWrapper.needDel_; return *this; } @@ -496,7 +497,7 @@ Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(const std::vecto auto node = cJSON_CreateNumber(value[i]); if (!node || !cJSON_AddItemToArray(json_, node)) { cJSON_Delete(json_); - cJSON_Delete(node); + cJSON_Delete(node); json_ = nullptr; children_.clear(); return *this; @@ -517,17 +518,17 @@ bool Serializable::JSONWrapper::ReplaceNode(cJSON *node) json_ = node; return true; } - + bool success = false; if (key_.empty()) { success = cJSON_ReplaceItemViaPointer(root_, json_, node); } else { success = cJSON_ReplaceItemInObject(root_, key_.c_str(), node); } - + if (success) { json_ = node; - children_.clear(); + children_.clear(); } return success; } @@ -837,7 +838,7 @@ void Serializable::JSONWrapper::SyncChildren() const children_.clear(); for (int i = 0; i < size; i++) { auto item = cJSON_GetArrayItem(json_, i); - children_.push_back(std::make_shared(item, json_, is_object() ? item->string:"")); + children_.push_back(std::make_shared(item, json_, is_object() ? item->string : "")); } } } @@ -883,7 +884,9 @@ void Serializable::JSONWrapper::AddToRoot() } } -Serializable::iterator::iterator(std::vector>::iterator it) : node_(it) {} +Serializable::iterator::iterator(std::vector>::iterator it) : node_(it) +{ +} Serializable::iterator &Serializable::iterator::operator++() { @@ -918,7 +921,7 @@ const Serializable::JSONWrapper &Serializable::iterator::value() const Serializable::JSONWrapper Serializable::JSONWrapper::array() { - cJSON* json = cJSON_CreateArray(); + cJSON *json = cJSON_CreateArray(); return Serializable::JSONWrapper(json, nullptr, ""); } @@ -927,7 +930,7 @@ void Serializable::JSONWrapper::push_back(const JSONWrapper &value) if (is_array()) { cJSON *newJson = cJSON_Duplicate(value.json_, 1); cJSON_AddItemToArray(json_, newJson); - children_.push_back(std::make_shared(newJson, json_)); + children_.push_back(std::make_shared(newJson, json_)); } } @@ -936,7 +939,7 @@ std::string Serializable::JSONWrapper::to_string(const JSONWrapper &jsonWrapper) return jsonWrapper.dump(); } -bool Serializable::JSONWrapper::operator==(const std::map& value) const +bool Serializable::JSONWrapper::operator==(const std::map &value) const { if (!is_object()) { return false; @@ -944,7 +947,7 @@ bool Serializable::JSONWrapper::operator==(const std::map& value) const +bool Serializable::JSONWrapper::operator==(const std::map &value) const { if (!is_object()) { return false; @@ -961,7 +964,7 @@ bool Serializable::JSONWrapper::operator==(const std::map if (cJSON_GetArraySize(json_) != value.size()) { return false; } - for (const auto& pair : value) { + for (const auto &pair : value) { auto item = cJSON_GetObjectItem(json_, pair.first.c_str()); if (item == nullptr || cJSON_GetNumberValue(item) != pair.second) { return false; @@ -970,7 +973,7 @@ bool Serializable::JSONWrapper::operator==(const std::map return true; } -bool Serializable::JSONWrapper::operator==(const std::vector& value) const +bool Serializable::JSONWrapper::operator==(const std::vector &value) const { if (!is_array()) { return false; @@ -987,15 +990,15 @@ bool Serializable::JSONWrapper::operator==(const std::vector& value return true; } -Serializable::JSONWrapper& Serializable::JSONWrapper::operator=(const std::map& value) +Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(const std::map &value) { if (json_) { cJSON_Delete(json_); json_ = nullptr; } json_ = cJSON_CreateObject(); - for (const auto& pair : value) { - cJSON* num = cJSON_CreateNumber(pair.second); + for (const auto &pair : value) { + cJSON *num = cJSON_CreateNumber(pair.second); if (!cJSON_AddItemToObject(json_, pair.first.c_str(), num)) { cJSON_Delete(num); } @@ -1004,15 +1007,15 @@ Serializable::JSONWrapper& Serializable::JSONWrapper::operator=(const std::map& value) +Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(const std::map &value) { if (json_) { cJSON_Delete(json_); json_ = nullptr; } json_ = cJSON_CreateObject(); - for (const auto& pair : value) { - cJSON* str = cJSON_CreateString(pair.second.c_str()); + for (const auto &pair : value) { + cJSON *str = cJSON_CreateString(pair.second.c_str()); if (!cJSON_AddItemToObject(json_, pair.first.c_str(), str)) { cJSON_Delete(str); } @@ -1021,7 +1024,7 @@ Serializable::JSONWrapper& Serializable::JSONWrapper::operator=(const std::map Date: Sat, 14 Jun 2025 14:12:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E7=B1=BB=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E4=BF=AE=E6=94=B9=20Signed-off-by:=20guochao=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/serializable/serializable.h | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index 2e8ed440e..8ba6373ac 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -133,7 +133,8 @@ public: using json = JSONWrapper; API_EXPORT json Marshall() const; - template static std::string Marshall(T &values) + template + static std::string Marshall(T &values) { json root; SetValue(root, values); @@ -141,7 +142,8 @@ public: } API_EXPORT bool Unmarshall(const std::string &jsonStr); - template static bool Unmarshall(const std::string &body, T &values) + template + static bool Unmarshall(const std::string &body, T &values) { return GetValue(ToJson(body), "", values); } @@ -177,7 +179,8 @@ public: API_EXPORT static bool SetValue(json &node, const std::vector &value); API_EXPORT static bool SetValue(json &node, const Serializable &value); - template API_EXPORT static bool SetValue(json &node, const std::variant<_Types...> &input); + template + API_EXPORT static bool SetValue(json &node, const std::variant<_Types...> &input); template API_EXPORT static bool GetValue(const json &node, const std::string &name, std::variant<_Types...> &value); @@ -185,18 +188,23 @@ public: protected: API_EXPORT ~Serializable() = default; - template static bool GetValue(const json &node, const std::string &name, std::vector &values); + template + static bool GetValue(const json &node, const std::string &name, std::vector &values); - template static bool SetValue(json &node, const std::vector &values); + template + static bool SetValue(json &node, const std::vector &values); template static bool GetValue(const json &node, const std::string &name, std::map &values); - template static bool SetValue(json &node, const std::map &values); + template + static bool SetValue(json &node, const std::map &values); - template static bool GetValue(const json &node, const std::string &name, T *&value); + template + static bool GetValue(const json &node, const std::string &name, T *&value); - template static bool SetValue(json &node, const T *value); + template + static bool SetValue(json &node, const T *value); template static bool ReadVariant(const json &node, const std::string &name, uint32_t step, uint32_t index, _OutTp &output); @@ -211,7 +219,8 @@ protected: API_EXPORT static const json &GetSubNode(const json &node, const std::string &name); }; -template bool Serializable::GetValue(const json &node, const std::string &name, std::vector &values) +template +bool Serializable::GetValue(const json &node, const std::string &name, std::vector &values) { auto &subNode = GetSubNode(node, name); if (subNode.is_null() || !subNode.is_array()) { @@ -226,7 +235,8 @@ template bool Serializable::GetValue(const json &node, const std::st return result; } -template bool Serializable::SetValue(json &node, const std::vector &values) +template +bool Serializable::SetValue(json &node, const std::vector &values) { bool result = true; size_t i = 0; @@ -252,7 +262,8 @@ bool Serializable::GetValue(const json &node, const std::string &name, std::map< return result; } -template bool Serializable::SetValue(json &node, const std::map &values) +template +bool Serializable::SetValue(json &node, const std::map &values) { bool result = true; node = JSONWrapper::Type::OBJECT; @@ -262,7 +273,8 @@ template bool Serializable::SetValue(json &node, const std::map bool Serializable::GetValue(const json &node, const std::string &name, T *&value) +template +bool Serializable::GetValue(const json &node, const std::string &name, T *&value) { auto &subNode = GetSubNode(node, name); if (subNode.is_null()) { @@ -280,7 +292,8 @@ template bool Serializable::GetValue(const json &node, const std::st return result; } -template bool Serializable::SetValue(json &node, const T *value) +template +bool Serializable::SetValue(json &node, const T *value) { if (value == nullptr) { return false; @@ -288,7 +301,8 @@ template bool Serializable::SetValue(json &node, const T *value) return SetValue(node, *value); } -template bool Serializable::SetValue(json &node, const std::variant<_Types...> &input) +template +bool Serializable::SetValue(json &node, const std::variant<_Types...> &input) { bool ret = SetValue(node[GET_NAME(type)], input.index()); if (!ret) { @@ -313,7 +327,8 @@ bool Serializable::GetValue(const json &node, const std::string &name, std::vari return Serializable::ReadVariant(subNode, GET_NAME(value), 0, index, value); } -template bool Serializable::WriteVariant(json &node, uint32_t step, const _InTp &input) +template +bool Serializable::WriteVariant(json &node, uint32_t step, const _InTp &input) { return false; } -- Gitee From 8cdc3cf60d916f6f3599075b66a5af7c69d4d1d4 Mon Sep 17 00:00:00 2001 From: guochao Date: Sat, 14 Jun 2025 14:17:06 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E7=B1=BB=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E4=BF=AE=E6=94=B9=20Signed-off-by:=20guochao=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/include/serializable/serializable.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index 8ba6373ac..b12b29c9d 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -212,7 +212,8 @@ protected: template static bool ReadVariant(const json &node, const std::string &name, uint32_t step, uint32_t index, _OutTp &output); - template static bool WriteVariant(json &node, uint32_t step, const _InTp &input); + template + static bool WriteVariant(json &node, uint32_t step, const _InTp &input); template static bool WriteVariant(json &node, uint32_t step, const _InTp &input); -- Gitee