diff --git a/services/distributeddataservice/service/udmf/preprocess/data_handler.cpp b/services/distributeddataservice/service/udmf/preprocess/data_handler.cpp index 94d6ad7f15bed33d5727bdd5c8548d85a272f0ac..e284636f384736444f69df7d20ce977134586ddd 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 3be27dfa34bab235852fc67e59bee7a5fea3ec92..4ce9051dcaa76a957afb030fbf8612486bc76f25 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