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 #include "rdb_types_util.h"
17 namespace OHOS::ITypesUtil {
18 template<>
Marshalling(const SyncerParam & input,MessageParcel & data)19 bool Marshalling(const SyncerParam &input, MessageParcel &data)
20 {
21     return ITypesUtil::Marshal(data, input.bundleName_, input.hapName_, input.storeName_, input.area_,
22         input.level_, input.type_, input.isEncrypt_, input.password_, input.customDir_, input.isAutoClean_,
23         input.isSearchable_, input.haMode_, input.infos_);
24 }
25 template<>
Unmarshalling(SyncerParam & output,MessageParcel & data)26 bool Unmarshalling(SyncerParam &output, MessageParcel &data)
27 {
28     return ITypesUtil::Unmarshal(data, output.bundleName_, output.hapName_, output.storeName_, output.area_,
29         output.level_, output.type_, output.isEncrypt_, output.password_, output.customDir_, output.isAutoClean_,
30         output.isSearchable_, output.haMode_, output.infos_);
31 }
32 
33 template<>
Marshalling(const NotifyConfig & input,MessageParcel & data)34 bool Marshalling(const NotifyConfig &input, MessageParcel &data)
35 {
36     return ITypesUtil::Marshal(data, input.delay_, input.isFull_);
37 }
38 template<>
Unmarshalling(NotifyConfig & output,MessageParcel & data)39 bool Unmarshalling(NotifyConfig &output, MessageParcel &data)
40 {
41     return ITypesUtil::Unmarshal(data, output.delay_, output.isFull_);
42 }
43 
44 template<>
Marshalling(const Option & input,MessageParcel & data)45 bool Marshalling(const Option &input, MessageParcel &data)
46 {
47     return ITypesUtil::Marshal(data, input.mode, input.seqNum, input.isAsync, input.isAutoSync, input.isCompensation);
48 }
49 
50 template<>
Unmarshalling(Option & output,MessageParcel & data)51 bool Unmarshalling(Option &output, MessageParcel &data)
52 {
53     return ITypesUtil::Unmarshal(
54         data, output.mode, output.seqNum, output.isAsync, output.isAutoSync, output.isCompensation);
55 }
56 
57 template<>
Marshalling(const RdbPredicates & input,MessageParcel & data)58 bool Marshalling(const RdbPredicates &input, MessageParcel &data)
59 {
60     return ITypesUtil::Marshal(data, input.tables_, input.devices_, input.operations_);
61 }
62 template<>
Unmarshalling(RdbPredicates & output,MessageParcel & data)63 bool Unmarshalling(RdbPredicates &output, MessageParcel &data)
64 {
65     return ITypesUtil::Unmarshal(data, output.tables_, output.devices_, output.operations_);
66 }
67 
68 template<>
Marshalling(const RdbOperation & input,MessageParcel & data)69 bool Marshalling(const RdbOperation &input, MessageParcel &data)
70 {
71     return ITypesUtil::Marshal(data, static_cast<int32_t>(input.operator_), input.field_, input.values_);
72 }
73 
74 template<>
Unmarshalling(RdbOperation & output,MessageParcel & data)75 bool Unmarshalling(RdbOperation &output, MessageParcel &data)
76 {
77     int32_t option;
78     auto ret = ITypesUtil::Unmarshal(data, option, output.field_, output.values_);
79     output.operator_ = static_cast<decltype(output.operator_)>(option);
80     return ret;
81 }
82 
83 template<>
Marshalling(const SubOption & input,MessageParcel & data)84 bool Marshalling(const SubOption &input, MessageParcel &data)
85 {
86     return ITypesUtil::Marshal(data, static_cast<int32_t>(input.mode));
87 }
88 
89 template<>
Unmarshalling(SubOption & output,MessageParcel & data)90 bool Unmarshalling(SubOption &output, MessageParcel &data)
91 {
92     int32_t mode = static_cast<int32_t>(output.mode);
93     auto ret = ITypesUtil::Unmarshal(data, mode);
94     output.mode = static_cast<decltype(output.mode)>(mode);
95     return ret;
96 }
97 template<>
Marshalling(const ValueObject & input,MessageParcel & data)98 bool Marshalling(const ValueObject &input, MessageParcel &data)
99 {
100     return Marshal(data, input.value);
101 }
102 template<>
Unmarshalling(ValueObject & output,MessageParcel & data)103 bool Unmarshalling(ValueObject &output, MessageParcel &data)
104 {
105     return Unmarshal(data, output.value);
106 }
107 
108 template<>
Marshalling(const ValuesBucket & input,MessageParcel & data)109 bool Marshalling(const ValuesBucket &input, MessageParcel &data)
110 {
111     return Marshal(data, input.values_);
112 }
113 template<>
Unmarshalling(ValuesBucket & output,MessageParcel & data)114 bool Unmarshalling(ValuesBucket &output, MessageParcel &data)
115 {
116     return Unmarshal(data, output.values_);
117 }
118 
119 template<>
Marshalling(const Asset & input,MessageParcel & data)120 bool Marshalling(const Asset &input, MessageParcel &data)
121 {
122     return Marshal(data, input.version, input.name, input.size, input.modifyTime, input.uri);
123 }
124 template<>
Unmarshalling(Asset & output,MessageParcel & data)125 bool Unmarshalling(Asset &output, MessageParcel &data)
126 {
127     return Unmarshal(data, output.version, output.name, output.size, output.modifyTime, output.uri);
128 }
129 template<>
Marshalling(const ProgressDetail & input,MessageParcel & data)130 bool Marshalling(const ProgressDetail &input, MessageParcel &data)
131 {
132     return Marshal(data, input.progress, input.code, input.details);
133 }
134 template<>
Unmarshalling(ProgressDetail & output,MessageParcel & data)135 bool Unmarshalling(ProgressDetail &output, MessageParcel &data)
136 {
137     return Unmarshal(data, output.progress, output.code, output.details);
138 }
139 template<>
Marshalling(const TableDetail & input,MessageParcel & data)140 bool Marshalling(const TableDetail &input, MessageParcel &data)
141 {
142     return Marshal(data, input.upload, input.download);
143 }
144 template<>
Unmarshalling(TableDetail & output,MessageParcel & data)145 bool Unmarshalling(TableDetail &output, MessageParcel &data)
146 {
147     return Unmarshal(data, output.upload, output.download);
148 }
149 template<>
Marshalling(const Statistic & input,MessageParcel & data)150 bool Marshalling(const Statistic &input, MessageParcel &data)
151 {
152     return Marshal(data, input.total, input.success, input.failed, input.untreated);
153 }
154 template<>
Unmarshalling(Statistic & output,MessageParcel & data)155 bool Unmarshalling(Statistic &output, MessageParcel &data)
156 {
157     return Unmarshal(data, output.total, output.success, output.failed, output.untreated);
158 }
159 
160 template<>
Marshalling(const PrimaryKeys & input,MessageParcel & data)161 bool Marshalling(const PrimaryKeys &input, MessageParcel &data)
162 {
163     return Marshal(data, input[Observer::CHG_TYPE_INSERT], input[Observer::CHG_TYPE_UPDATE],
164         input[Observer::CHG_TYPE_DELETE]);
165 }
166 template<>
Unmarshalling(PrimaryKeys & output,MessageParcel & data)167 bool Unmarshalling(PrimaryKeys &output, MessageParcel &data)
168 {
169     return Unmarshal(data, output[Observer::CHG_TYPE_INSERT], output[Observer::CHG_TYPE_UPDATE],
170         output[Observer::CHG_TYPE_DELETE]);
171 }
172 
173 template<>
Marshalling(const Origin & input,MessageParcel & data)174 bool Marshalling(const Origin &input, MessageParcel &data)
175 {
176     return Marshal(data, input.origin, input.dataType, input.id, input.store);
177 }
178 template<>
Unmarshalling(Origin & output,MessageParcel & data)179 bool Unmarshalling(Origin &output, MessageParcel &data)
180 {
181     return Unmarshal(data, output.origin, output.dataType, output.id, output.store);
182 }
183 
184 template<>
Marshalling(const RdbChangedData & input,MessageParcel & data)185 bool Marshalling(const RdbChangedData &input, MessageParcel &data)
186 {
187     return Marshal(data, input.tableData);
188 }
189 template<>
Unmarshalling(RdbChangedData & output,MessageParcel & data)190 bool Unmarshalling(RdbChangedData &output, MessageParcel &data)
191 {
192     return Unmarshal(data, output.tableData);
193 }
194 
195 template<>
Marshalling(const RdbProperties & input,MessageParcel & data)196 bool Marshalling(const RdbProperties &input, MessageParcel &data)
197 {
198     return Marshal(data, input.isTrackedDataChange);
199 }
200 template<>
Unmarshalling(RdbProperties & output,MessageParcel & data)201 bool Unmarshalling(RdbProperties &output, MessageParcel &data)
202 {
203     return Unmarshal(data, output.isTrackedDataChange);
204 }
205 
206 template<>
Marshalling(const Reference & input,MessageParcel & data)207 bool Marshalling(const Reference &input, MessageParcel &data)
208 {
209     return Marshal(data, input.sourceTable, input.targetTable, input.refFields);
210 }
211 template<>
Unmarshalling(Reference & output,MessageParcel & data)212 bool Unmarshalling(Reference &output, MessageParcel &data)
213 {
214     return Unmarshal(data, output.sourceTable, output.targetTable, output.refFields);
215 }
216 
217 template<>
Marshalling(const BigInt & input,MessageParcel & data)218 bool Marshalling(const BigInt& input, MessageParcel& data)
219 {
220     return Marshal(data, input.Sign(), input.Value());
221 }
222 
223 template<>
Unmarshalling(BigInt & output,MessageParcel & data)224 bool Unmarshalling(BigInt& output, MessageParcel& data)
225 {
226     int32_t sign = 0;
227     std::vector<uint64_t> value;
228     if (!Unmarshal(data, sign, value)) {
229         return false;
230     }
231     output = BigInt(sign, std::move(value));
232     return true;
233 }
234 template<>
Marshalling(const DebugInfo & input,MessageParcel & data)235 bool Marshalling(const DebugInfo &input, MessageParcel &data)
236 {
237     return Marshal(data, input.inode_, input.mode_, input.uid_, input.gid_);
238 }
239 template<>
Unmarshalling(DebugInfo & output,MessageParcel & data)240 bool Unmarshalling(DebugInfo &output, MessageParcel &data)
241 {
242     return Unmarshal(data, output.inode_, output.mode_, output.uid_, output.gid_);
243 }
244 }