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