1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_LOCAL_H 17 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_LOCAL_H 18 #include <string> 19 #include <variant> 20 #include <vector> 21 22 #include "serializable/serializable.h" 23 namespace OHOS::DistributedData { 24 struct API_EXPORT PolicyValue final : public Serializable { 25 uint32_t type = UINT32_MAX; 26 uint32_t index = 0; 27 uint32_t valueUint = 0; 28 API_EXPORT PolicyValue() = default; 29 API_EXPORT ~PolicyValue() = default; 30 API_EXPORT bool IsValueEffect() const; 31 API_EXPORT bool Marshal(json &node) const override; 32 API_EXPORT bool Unmarshal(const json &node) override; 33 }; 34 struct API_EXPORT StoreMetaDataLocal final : public Serializable { 35 bool isAutoSync = false; 36 bool isBackup = false; 37 bool isDirty = false; 38 bool isEncrypt = false; 39 bool isPublic = false; 40 std::string dataDir = ""; 41 std::string schema = ""; 42 std::vector<PolicyValue> policies {}; 43 44 API_EXPORT StoreMetaDataLocal(); 45 API_EXPORT ~StoreMetaDataLocal(); 46 API_EXPORT bool operator==(const StoreMetaDataLocal &metaData) const; 47 API_EXPORT bool operator!=(const StoreMetaDataLocal &metaData) const; 48 API_EXPORT bool HasPolicy(uint32_t type); 49 API_EXPORT PolicyValue GetPolicy(uint32_t type); 50 API_EXPORT bool Marshal(json &node) const override; 51 API_EXPORT bool Unmarshal(const json &node) override; 52 API_EXPORT static std::string GetKey(const std::initializer_list<std::string> &fields); 53 API_EXPORT static std::string GetPrefix(const std::initializer_list<std::string> &fields); 54 55 private: 56 static constexpr const char *KEY_PREFIX = "KvStoreMetaDataLocal"; 57 }; 58 } // namespace OHOS::DistributedData 59 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_LOCAL_H 60