From 402f88d739f211d8d900691239c778f8916f9bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E5=AD=90=E6=9D=8E?= Date: Fri, 14 Mar 2025 14:47:20 +0800 Subject: [PATCH] service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 木子李 --- .../service/udmf/preprocess/data_handler.cpp | 30 +++++++++++++++++++ .../service/udmf/preprocess/data_handler.h | 3 ++ 2 files changed, 33 insertions(+) diff --git a/services/distributeddataservice/service/udmf/preprocess/data_handler.cpp b/services/distributeddataservice/service/udmf/preprocess/data_handler.cpp index 94d6ad7f1..e284636f3 100644 --- a/services/distributeddataservice/service/udmf/preprocess/data_handler.cpp +++ b/services/distributeddataservice/service/udmf/preprocess/data_handler.cpp @@ -21,6 +21,7 @@ namespace OHOS::UDMF { constexpr const char *UD_KEY_SEPARATOR = "/"; constexpr const char *UD_KEY_ENTRY_SEPARATOR = "#"; +constexpr const char *UD_KEY_PROPERTIES_SEPARATOR = "#properties"; Status DataHandler::MarshalToEntries(const UnifiedData &unifiedData, std::vector &entries) { @@ -34,6 +35,17 @@ Status DataHandler::MarshalToEntries(const UnifiedData &unifiedData, std::vector std::vector udKeyBytes = { unifiedKey.begin(), unifiedKey.end() }; Entry entry = { udKeyBytes, runtimeBytes }; entries.emplace_back(entry); + + std::string propsKey = unifiedKey + UD_KEY_PROPERTIES_SEPARATOR; + std::vector propsBytes; + auto propsTlv = TLVObject(propsBytes); + if (!TLVUtil::Writing(*unifiedData.GetProperties(), propsTlv, TAG::TAG_UNIFIED_PROPERTIES)) { + ZLOGE("Properties info marshalling failed:%{public}s", propsKey.c_str()); + return E_WRITE_PARCEL_ERROR; + } + std::vector propsKeyBytes = { propsKey.begin(), propsKey.end() }; + Entry propsEntry = { propsKeyBytes, propsBytes }; + entries.emplace_back(propsEntry); return BuildEntries(unifiedData.GetRecords(), unifiedKey, entries); } @@ -98,6 +110,10 @@ Status DataHandler::UnmarshalEntryItem(UnifiedData &unifiedData, const std::vect } innerEntries.emplace(keyStr, std::move(*entryRead)); } + if (UnmarshalEntryProps(unifiedData, data, keyStr, isStartWithKey) != E_OK) { + ZLOGE("Unmarshall unified properties info failed."); + return E_READ_PARCEL_ERROR; + } } return E_OK; } @@ -136,4 +152,18 @@ Status DataHandler::BuildEntries(const std::vector properties; + if (!TLVUtil::ReadTlv(properties, data, TAG::TAG_UNIFIED_PROPERTIES)) { + ZLOGE("Unmarshall unified properties failed."); + return E_READ_PARCEL_ERROR; + } + unifiedData.SetProperties(std::move(properties)); + } + return E_OK; +} } // namespace UDMF::OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/preprocess/data_handler.h b/services/distributeddataservice/service/udmf/preprocess/data_handler.h index 3be27dfa3..4ce9051dc 100644 --- a/services/distributeddataservice/service/udmf/preprocess/data_handler.h +++ b/services/distributeddataservice/service/udmf/preprocess/data_handler.h @@ -16,6 +16,7 @@ #define DATA_HANDLER_H #include "unified_data.h" +#include "tlv_object.h" #include "types_export.h" namespace OHOS::UDMF { @@ -33,6 +34,8 @@ private: static Status UnmarshalEntryItem(UnifiedData &unifiedData, const std::vector &entries, const std::string &key, std::map> &records, std::map> &innerEntries); + static Status UnmarshalEntryProps(UnifiedData &unifiedData, TLVObject &data, + const std::string &keyStr, bool isStartWithKey); }; } // namespace UDMF::OHOS #endif // DATA_HANDLER_H \ No newline at end of file -- Gitee