1 /*
2 * Copyright (c) 2023 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 "cloud_types_util.h"
17
18 namespace OHOS::ITypesUtil {
19 template<>
Marshalling(const Participant & input,MessageParcel & data)20 bool Marshalling(const Participant &input, MessageParcel &data)
21 {
22 return ITypesUtil::Marshal(data, input.identity, input.role, input.state, input.privilege, input.attachInfo);
23 }
24
25 template<>
Unmarshalling(Participant & output,MessageParcel & data)26 bool Unmarshalling(Participant &output, MessageParcel &data)
27 {
28 return ITypesUtil::Unmarshal(data, output.identity, output.role, output.state, output.privilege, output.attachInfo);
29 }
30
31 template<>
Marshalling(const Privilege & input,MessageParcel & data)32 bool Marshalling(const Privilege &input, MessageParcel &data)
33 {
34 return ITypesUtil::Marshal(data, input.writable, input.readable, input.creatable, input.deletable, input.shareable);
35 }
36
37 template<>
Unmarshalling(Privilege & output,MessageParcel & data)38 bool Unmarshalling(Privilege &output, MessageParcel &data)
39 {
40 return ITypesUtil::Unmarshal(
41 data, output.writable, output.readable, output.creatable, output.deletable, output.shareable);
42 }
43
44 template<>
Marshalling(const Role & input,MessageParcel & data)45 bool Marshalling(const Role &input, MessageParcel &data)
46 {
47 return data.WriteInt32(static_cast<int32_t>(input));
48 }
49
50 template<>
Unmarshalling(Role & output,MessageParcel & data)51 bool Unmarshalling(Role &output, MessageParcel &data)
52 {
53 int32_t result;
54 if (!data.ReadInt32(result) || result < Role::ROLE_NIL || result >= Role::ROLE_BUTT) {
55 return false;
56 }
57 output = static_cast<Role>(result);
58 return true;
59 }
60
61 template<>
Marshalling(const Confirmation & input,MessageParcel & data)62 bool Marshalling(const Confirmation &input, MessageParcel &data)
63 {
64 return data.WriteInt32(static_cast<int32_t>(input));
65 }
66
67 template<>
Unmarshalling(Confirmation & output,MessageParcel & data)68 bool Unmarshalling(Confirmation &output, MessageParcel &data)
69 {
70 int32_t result;
71 if (!data.ReadInt32(result) || result < Confirmation::CFM_NIL || result >= Confirmation::CFM_BUTT) {
72 return false;
73 }
74 output = static_cast<Confirmation>(result);
75 return true;
76 }
77
78 template<>
Marshalling(const SharingCode & input,MessageParcel & data)79 bool Marshalling(const SharingCode &input, MessageParcel &data)
80 {
81 return data.WriteInt32(static_cast<int32_t>(input));
82 }
83
84 template<>
Unmarshalling(SharingCode & output,MessageParcel & data)85 bool Unmarshalling(SharingCode &output, MessageParcel &data)
86 {
87 int32_t result;
88 if (!data.ReadInt32(result) || result < SharingCode::SUCCESS) {
89 return false;
90 }
91 output = static_cast<SharingCode>(result);
92 return true;
93 }
94
95 template<>
Marshalling(const Asset & input,MessageParcel & data)96 bool Marshalling(const Asset &input, MessageParcel &data)
97 {
98 return Marshal(data, input.version, input.name, input.size, input.modifyTime, input.uri);
99 }
100 template<>
Unmarshalling(Asset & output,MessageParcel & data)101 bool Unmarshalling(Asset &output, MessageParcel &data)
102 {
103 return Unmarshal(data, output.version, output.name, output.size, output.modifyTime, output.uri);
104 }
105 template<>
Marshalling(const ValueObject & input,MessageParcel & data)106 bool Marshalling(const ValueObject &input, MessageParcel &data)
107 {
108 return Marshal(data, input.value);
109 }
110 template<>
Unmarshalling(ValueObject & output,MessageParcel & data)111 bool Unmarshalling(ValueObject &output, MessageParcel &data)
112 {
113 return Unmarshal(data, output.value);
114 }
115 template<>
Marshalling(const ValuesBucket & input,MessageParcel & data)116 bool Marshalling(const ValuesBucket &input, MessageParcel &data)
117 {
118 return Marshal(data, input.values_);
119 }
120 template<>
Unmarshalling(ValuesBucket & output,MessageParcel & data)121 bool Unmarshalling(ValuesBucket &output, MessageParcel &data)
122 {
123 return Unmarshal(data, output.values_);
124 }
125
126 template<>
Unmarshalling(StatisticInfo & output,MessageParcel & data)127 bool Unmarshalling(StatisticInfo &output, MessageParcel &data)
128 {
129 return ITypesUtil::Unmarshal(data, output.table, output.inserted, output.updated, output.normal);
130 }
131
132 template<>
Marshalling(const Strategy & input,MessageParcel & data)133 bool Marshalling(const Strategy &input, MessageParcel &data)
134 {
135 return data.WriteUint32(static_cast<uint32_t>(input));
136 }
137
138 template<>
Marshalling(const CommonAsset & input,MessageParcel & data)139 bool Marshalling(const CommonAsset &input, MessageParcel &data)
140 {
141 return ITypesUtil::Marshal(data, input.name, input.uri, input.path, input.createTime, input.modifyTime, input.size,
142 input.status, input.hash);
143 }
144
145 template<>
Marshalling(const CloudSyncInfo & input,MessageParcel & data)146 bool Marshalling(const CloudSyncInfo &input, MessageParcel &data)
147 {
148 return Marshal(data, input.startTime, input.finishTime, input.code, input.syncStatus);
149 }
150 template<>
Unmarshalling(CloudSyncInfo & output,MessageParcel & data)151 bool Unmarshalling(CloudSyncInfo &output, MessageParcel &data)
152 {
153 return Unmarshal(data, output.startTime, output.finishTime, output.code, output.syncStatus);
154 }
155
156 template<>
Marshalling(const Option & input,MessageParcel & data)157 bool Marshalling(const Option &input, MessageParcel &data)
158 {
159 return Marshal(data, input.syncMode, input.seqNum);
160 }
161 template<>
Unmarshalling(Option & output,MessageParcel & data)162 bool Unmarshalling(Option &output, MessageParcel &data)
163 {
164 return Unmarshal(data, output.syncMode, output.seqNum);
165 }
166 } // namespace OHOS::ITypesUtil