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.isAutoSync_, input.isEncrypt_, input.password_);
23 }
24 template<>
Unmarshalling(SyncerParam & output,MessageParcel & data)25 bool Unmarshalling(SyncerParam &output, MessageParcel &data)
26 {
27 return ITypesUtil::Unmarshal(data, output.bundleName_, output.hapName_, output.storeName_, output.area_,
28 output.level_, output.type_, output.isAutoSync_, output.isEncrypt_, output.password_);
29 }
30
31 template<>
Marshalling(const Option & input,MessageParcel & data)32 bool Marshalling(const Option &input, MessageParcel &data)
33 {
34 return ITypesUtil::Marshal(data, input.mode, input.seqNum, input.isAsync);
35 }
36
37 template<>
Unmarshalling(Option & output,MessageParcel & data)38 bool Unmarshalling(Option &output, MessageParcel &data)
39 {
40 return ITypesUtil::Unmarshal(data, output.mode, output.seqNum, output.isAsync);
41 }
42
43 template<>
Marshalling(const RdbPredicates & input,MessageParcel & data)44 bool Marshalling(const RdbPredicates &input, MessageParcel &data)
45 {
46 return ITypesUtil::Marshal(data, input.tables_, input.devices_, input.operations_);
47 }
48 template<>
Unmarshalling(RdbPredicates & output,MessageParcel & data)49 bool Unmarshalling(RdbPredicates &output, MessageParcel &data)
50 {
51 return ITypesUtil::Unmarshal(data, output.tables_, output.devices_, output.operations_);
52 }
53
54 template<>
Marshalling(const RdbOperation & input,MessageParcel & data)55 bool Marshalling(const RdbOperation &input, MessageParcel &data)
56 {
57 return ITypesUtil::Marshal(data, static_cast<int32_t>(input.operator_), input.field_, input.values_);
58 }
59
60 template<>
Unmarshalling(RdbOperation & output,MessageParcel & data)61 bool Unmarshalling(RdbOperation &output, MessageParcel &data)
62 {
63 int32_t option;
64 auto ret = ITypesUtil::Unmarshal(data, option, output.field_, output.values_);
65 output.operator_ = static_cast<decltype(output.operator_)>(option);
66 return ret;
67 }
68
69 template<>
Marshalling(const SubOption & input,MessageParcel & data)70 bool Marshalling(const SubOption &input, MessageParcel &data)
71 {
72 return ITypesUtil::Marshal(data, static_cast<int32_t>(input.mode));
73 }
74
75 template<>
Unmarshalling(SubOption & output,MessageParcel & data)76 bool Unmarshalling(SubOption &output, MessageParcel &data)
77 {
78 int32_t mode = static_cast<int32_t>(output.mode);
79 auto ret = ITypesUtil::Unmarshal(data, mode);
80 output.mode = static_cast<decltype(output.mode)>(mode);
81 return ret;
82 }
83 template<>
Marshalling(const ValueObject & input,MessageParcel & data)84 bool Marshalling(const ValueObject &input, MessageParcel &data)
85 {
86 return Marshal(data, input.value);
87 }
88 template<>
Unmarshalling(ValueObject & output,MessageParcel & data)89 bool Unmarshalling(ValueObject &output, MessageParcel &data)
90 {
91 return Unmarshal(data, output.value);
92 }
93
94 template<>
Marshalling(const ValuesBucket & input,MessageParcel & data)95 bool Marshalling(const ValuesBucket &input, MessageParcel &data)
96 {
97 return Marshal(data, input.values_);
98 }
99 template<>
Unmarshalling(ValuesBucket & output,MessageParcel & data)100 bool Unmarshalling(ValuesBucket &output, MessageParcel &data)
101 {
102 return Unmarshal(data, output.values_);
103 }
104
105 template<>
Marshalling(const Asset & input,MessageParcel & data)106 bool Marshalling(const Asset &input, MessageParcel &data)
107 {
108 return Marshal(data, input.version, input.name, input.size, input.modifyTime, input.uri);
109 }
110 template<>
Unmarshalling(Asset & output,MessageParcel & data)111 bool Unmarshalling(Asset &output, MessageParcel &data)
112 {
113 return Unmarshal(data, output.version, output.name, output.size, output.modifyTime, output.uri);
114 }
115 template<>
Marshalling(const ProgressDetail & input,MessageParcel & data)116 bool Marshalling(const ProgressDetail &input, MessageParcel &data)
117 {
118 return Marshal(data, input.progress, input.code, input.details);
119 }
120 template<>
Unmarshalling(ProgressDetail & output,MessageParcel & data)121 bool Unmarshalling(ProgressDetail &output, MessageParcel &data)
122 {
123 return Unmarshal(data, output.progress, output.code, output.details);
124 }
125 template<>
Marshalling(const TableDetail & input,MessageParcel & data)126 bool Marshalling(const TableDetail &input, MessageParcel &data)
127 {
128 return Marshal(data, input.upload, input.download);
129 }
130 template<>
Unmarshalling(TableDetail & output,MessageParcel & data)131 bool Unmarshalling(TableDetail &output, MessageParcel &data)
132 {
133 return Unmarshal(data, output.upload, output.download);
134 }
135 template<>
Marshalling(const Statistic & input,MessageParcel & data)136 bool Marshalling(const Statistic &input, MessageParcel &data)
137 {
138 return Marshal(data, input.total, input.success, input.failed, input.untreated);
139 }
140 template<>
Unmarshalling(Statistic & output,MessageParcel & data)141 bool Unmarshalling(Statistic &output, MessageParcel &data)
142 {
143 return Unmarshal(data, output.total, output.success, output.failed, output.untreated);
144 }
145
146 template<>
Marshalling(const PrimaryKeys & input,MessageParcel & data)147 bool Marshalling(const PrimaryKeys &input, MessageParcel &data)
148 {
149 return Marshal(data, input[Observer::CHG_TYPE_INSERT], input[Observer::CHG_TYPE_UPDATE],
150 input[Observer::CHG_TYPE_DELETE]);
151 }
152 template<>
Unmarshalling(PrimaryKeys & output,MessageParcel & data)153 bool Unmarshalling(PrimaryKeys &output, MessageParcel &data)
154 {
155 return Unmarshal(data, output[Observer::CHG_TYPE_INSERT], output[Observer::CHG_TYPE_UPDATE],
156 output[Observer::CHG_TYPE_DELETE]);
157 }
158
159 template<>
Marshalling(const Origin & input,MessageParcel & data)160 bool Marshalling(const Origin &input, MessageParcel &data)
161 {
162 return Marshal(data, input.origin, input.dataType, input.id, input.store);
163 }
164 template<>
Unmarshalling(Origin & output,MessageParcel & data)165 bool Unmarshalling(Origin &output, MessageParcel &data)
166 {
167 return Unmarshal(data, output.origin, output.dataType, output.id, output.store);
168 }
169 }
170