• 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 
16 #include "itypes_util.h"
17 
18 #include "global.h"
19 #include "iremote_object.h"
20 
21 namespace OHOS {
22 namespace MiscServices {
Marshal(MessageParcel & data)23 bool ITypesUtil::Marshal(MessageParcel &data)
24 {
25     return true;
26 }
27 
Unmarshal(MessageParcel & data)28 bool ITypesUtil::Unmarshal(MessageParcel &data)
29 {
30     return true;
31 }
32 
Marshalling(bool input,MessageParcel & data)33 bool ITypesUtil::Marshalling(bool input, MessageParcel &data)
34 {
35     return data.WriteBool(input);
36 }
37 
Unmarshalling(bool & output,MessageParcel & data)38 bool ITypesUtil::Unmarshalling(bool &output, MessageParcel &data)
39 {
40     return data.ReadBool(output);
41 }
42 
Marshalling(uint32_t input,MessageParcel & data)43 bool ITypesUtil::Marshalling(uint32_t input, MessageParcel &data)
44 {
45     return data.WriteUint32(input);
46 }
47 
Unmarshalling(uint32_t & output,MessageParcel & data)48 bool ITypesUtil::Unmarshalling(uint32_t &output, MessageParcel &data)
49 {
50     return data.ReadUint32(output);
51 }
52 
Marshalling(int32_t input,MessageParcel & data)53 bool ITypesUtil::Marshalling(int32_t input, MessageParcel &data)
54 {
55     return data.WriteInt32(input);
56 }
57 
Unmarshalling(int32_t & output,MessageParcel & data)58 bool ITypesUtil::Unmarshalling(int32_t &output, MessageParcel &data)
59 {
60     return data.ReadInt32(output);
61 }
62 
Marshalling(uint64_t input,MessageParcel & data)63 bool ITypesUtil::Marshalling(uint64_t input, MessageParcel &data)
64 {
65     return data.WriteUint64(input);
66 }
67 
Unmarshalling(uint64_t & output,MessageParcel & data)68 bool ITypesUtil::Unmarshalling(uint64_t &output, MessageParcel &data)
69 {
70     return data.ReadUint64(output);
71 }
72 
Marshalling(const std::string & input,MessageParcel & data)73 bool ITypesUtil::Marshalling(const std::string &input, MessageParcel &data)
74 {
75     return data.WriteString(input);
76 }
77 
Unmarshalling(std::string & output,MessageParcel & data)78 bool ITypesUtil::Unmarshalling(std::string &output, MessageParcel &data)
79 {
80     return data.ReadString(output);
81 }
82 
Marshalling(const std::u16string & input,MessageParcel & data)83 bool ITypesUtil::Marshalling(const std::u16string &input, MessageParcel &data)
84 {
85     return data.WriteString16(input);
86 }
87 
Unmarshalling(std::u16string & output,MessageParcel & data)88 bool ITypesUtil::Unmarshalling(std::u16string &output, MessageParcel &data)
89 {
90     return data.ReadString16(output);
91 }
92 
Marshalling(const std::vector<uint8_t> & input,MessageParcel & data)93 bool ITypesUtil::Marshalling(const std::vector<uint8_t> &input, MessageParcel &data)
94 {
95     return data.WriteUInt8Vector(input);
96 }
97 
Unmarshalling(std::vector<uint8_t> & output,MessageParcel & data)98 bool ITypesUtil::Unmarshalling(std::vector<uint8_t> &output, MessageParcel &data)
99 {
100     return data.ReadUInt8Vector(&output);
101 }
102 
Marshalling(const sptr<IRemoteObject> & input,MessageParcel & data)103 bool ITypesUtil::Marshalling(const sptr<IRemoteObject> &input, MessageParcel &data)
104 {
105     return data.WriteRemoteObject(input);
106 }
107 
Unmarshalling(sptr<IRemoteObject> & output,MessageParcel & data)108 bool ITypesUtil::Unmarshalling(sptr<IRemoteObject> &output, MessageParcel &data)
109 {
110     output = data.ReadRemoteObject();
111     return true;
112 }
Marshalling(const Property & input,MessageParcel & data)113 bool ITypesUtil::Marshalling(const Property &input, MessageParcel &data)
114 {
115     if (!Marshal(data, input.name, input.id, input.label, input.icon, input.iconId)) {
116         IMSA_HILOGE("ITypesUtil::write Property to message parcel failed");
117         return false;
118     }
119     return true;
120 }
121 
Unmarshalling(Property & output,MessageParcel & data)122 bool ITypesUtil::Unmarshalling(Property &output, MessageParcel &data)
123 {
124     if (!Unmarshal(data, output.name, output.id, output.label, output.icon, output.iconId)) {
125         IMSA_HILOGE("ITypesUtil::read Property from message parcel failed");
126         return false;
127     }
128     return true;
129 }
130 
Marshalling(const SubProperty & input,MessageParcel & data)131 bool ITypesUtil::Marshalling(const SubProperty &input, MessageParcel &data)
132 {
133     if (!Marshal(data, input.label, input.name, input.id, input.mode, input.locale, input.language, input.icon,
134             input.iconId)) {
135         IMSA_HILOGE("ITypesUtil::write SubProperty to message parcel failed");
136         return false;
137     }
138     return true;
139 }
140 
Unmarshalling(SubProperty & output,MessageParcel & data)141 bool ITypesUtil::Unmarshalling(SubProperty &output, MessageParcel &data)
142 {
143     if (!Unmarshal(data, output.label, output.name, output.id, output.mode, output.locale, output.language,
144             output.icon, output.iconId)) {
145         IMSA_HILOGE("ITypesUtil::read SubProperty from message parcel failed");
146         return false;
147     }
148     return true;
149 }
150 } // namespace MiscServices
151 } // namespace OHOS