• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "metadata/store_meta_data_local.h"
16 #include "utils/constant.h"
17 
18 namespace OHOS {
19 namespace DistributedData {
Marshal(json & node) const20 bool PolicyValue::Marshal(json &node) const
21 {
22     SetValue(node[GET_NAME(type)], type);
23     SetValue(node[GET_NAME(valueUint)], valueUint);
24     SetValue(node[GET_NAME(index)], index);
25     return true;
26 }
27 
Unmarshal(const json & node)28 bool PolicyValue::Unmarshal(const json &node)
29 {
30     GetValue(node, GET_NAME(type), type);
31     GetValue(node, GET_NAME(valueUint), valueUint);
32     GetValue(node, GET_NAME(index), index);
33     return true;
34 }
35 
IsValueEffect() const36 bool PolicyValue::IsValueEffect() const
37 {
38     return (index > 0);
39 }
40 
HasPolicy(uint32_t type)41 bool StoreMetaDataLocal::HasPolicy(uint32_t type)
42 {
43     for (auto &policy : policies) {
44         if (policy.type == type) {
45             return true;
46         }
47     }
48     return false;
49 }
50 
GetPolicy(uint32_t type)51 PolicyValue StoreMetaDataLocal::GetPolicy(uint32_t type)
52 {
53     for (auto &policy : policies) {
54         if (policy.type == type) {
55             return policy;
56         }
57     }
58     return PolicyValue();
59 }
60 
Marshal(json & node) const61 bool StoreMetaDataLocal::Marshal(json &node) const
62 {
63     SetValue(node[GET_NAME(isAutoSync)], isAutoSync);
64     SetValue(node[GET_NAME(isBackup)], isBackup);
65     SetValue(node[GET_NAME(isDirty)], isDirty);
66     SetValue(node[GET_NAME(isEncrypt)], isEncrypt);
67     SetValue(node[GET_NAME(dataDir)], dataDir);
68     SetValue(node[GET_NAME(schema)], schema);
69     SetValue(node[GET_NAME(policies)], policies);
70     return true;
71 }
72 
Unmarshal(const json & node)73 bool StoreMetaDataLocal::Unmarshal(const json &node)
74 {
75     GetValue(node, GET_NAME(isAutoSync), isAutoSync);
76     GetValue(node, GET_NAME(isBackup), isBackup);
77     GetValue(node, GET_NAME(isDirty), isDirty);
78     GetValue(node, GET_NAME(isEncrypt), isEncrypt);
79     GetValue(node, GET_NAME(dataDir), dataDir);
80     GetValue(node, GET_NAME(schema), schema);
81     GetValue(node, GET_NAME(policies), policies);
82     return true;
83 }
84 
StoreMetaDataLocal()85 StoreMetaDataLocal::StoreMetaDataLocal()
86 {
87 }
88 
~StoreMetaDataLocal()89 StoreMetaDataLocal::~StoreMetaDataLocal()
90 {
91 }
92 
operator ==(const StoreMetaDataLocal & metaData) const93 bool StoreMetaDataLocal::operator==(const StoreMetaDataLocal &metaData) const
94 {
95     if (Constant::NotEqual(isAutoSync, metaData.isAutoSync) || Constant::NotEqual(isBackup, metaData.isBackup) ||
96         Constant::NotEqual(isDirty, metaData.isDirty) || Constant::NotEqual(isEncrypt, metaData.isEncrypt)) {
97         return false;
98     }
99     return dataDir == metaData.dataDir;
100 }
101 
operator !=(const StoreMetaDataLocal & metaData) const102 bool StoreMetaDataLocal::operator!=(const StoreMetaDataLocal &metaData) const
103 {
104     return !(*this == metaData);
105 }
106 
GetKey(const std::initializer_list<std::string> & fields)107 std::string StoreMetaDataLocal::GetKey(const std::initializer_list<std::string> &fields)
108 {
109     return Constant::Join(KEY_PREFIX, Constant::KEY_SEPARATOR, fields);
110 }
111 
GetPrefix(const std::initializer_list<std::string> & fields)112 std::string StoreMetaDataLocal::GetPrefix(const std::initializer_list<std::string> &fields)
113 {
114     auto prefix = Constant::Join(KEY_PREFIX, Constant::KEY_SEPARATOR, fields);
115     prefix.append(Constant::KEY_SEPARATOR);
116     return prefix;
117 }
118 } // namespace DistributedData
119 } // namespace OHOS
120