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 #include "tlv_util.h"
16
17 #include "logger.h"
18
19 namespace OHOS {
20 namespace TLVUtil {
CountBufferSize(const std::nullptr_t & input,TLVObject & data)21 template <> size_t CountBufferSize(const std::nullptr_t &input, TLVObject &data)
22 {
23 return sizeof(TLVHead);
24 }
25
Writing(const std::nullptr_t & input,TLVObject & data,TAG tag)26 template <> bool Writing(const std::nullptr_t &input, TLVObject &data, TAG tag)
27 {
28 return true;
29 }
30
Reading(std::nullptr_t & output,TLVObject & data,const TLVHead & head)31 template <> bool Reading(std::nullptr_t &output, TLVObject &data, const TLVHead &head)
32 {
33 return true;
34 }
35
CountBufferSize(const std::monostate & input,TLVObject & data)36 template <> size_t CountBufferSize(const std::monostate &input, TLVObject &data)
37 {
38 return sizeof(TLVHead);
39 }
40
Writing(const std::monostate & input,TLVObject & data,TAG tag)41 template <> bool Writing(const std::monostate &input, TLVObject &data, TAG tag)
42 {
43 return true;
44 }
45
Reading(std::monostate & output,TLVObject & data,const TLVHead & head)46 template <> bool Reading(std::monostate &output, TLVObject &data, const TLVHead &head)
47 {
48 return true;
49 }
50
CountBufferSize(const std::string & input,TLVObject & data)51 template <> size_t CountBufferSize(const std::string &input, TLVObject &data)
52 {
53 return sizeof(TLVHead);
54 }
55
Writing(const std::string & input,TLVObject & data,TAG tag)56 template <> bool Writing(const std::string &input, TLVObject &data, TAG tag)
57 {
58 return true;
59 }
60
Reading(std::string & output,TLVObject & data,const TLVHead & head)61 template <> bool Reading(std::string &output, TLVObject &data, const TLVHead &head)
62 {
63 return true;
64 }
65
CountBufferSize(const std::vector<uint8_t> & input,TLVObject & data)66 template <> size_t CountBufferSize(const std::vector<uint8_t> &input, TLVObject &data)
67 {
68 return sizeof(TLVHead);
69 }
70
Writing(const std::vector<uint8_t> & input,TLVObject & data,TAG tag)71 template <> bool Writing(const std::vector<uint8_t> &input, TLVObject &data, TAG tag)
72 {
73 return true;
74 }
75
Reading(std::vector<uint8_t> & output,TLVObject & data,const TLVHead & head)76 template <> bool Reading(std::vector<uint8_t> &output, TLVObject &data, const TLVHead &head)
77 {
78 return true;
79 }
80
CountBufferSize(const UDType & input,TLVObject & data)81 template <> size_t CountBufferSize(const UDType &input, TLVObject &data)
82 {
83 return sizeof(TLVHead);
84 }
85
Writing(const UDType & input,TLVObject & data,TAG tag)86 template <> bool Writing(const UDType &input, TLVObject &data, TAG tag)
87 {
88 return true;
89 }
90
Reading(UDType & output,TLVObject & data,const TLVHead & head)91 template <> bool Reading(UDType &output, TLVObject &data, const TLVHead &head)
92 {
93 return true;
94 }
95
CountBufferSize(const DataStatus & input,TLVObject & data)96 template <> size_t CountBufferSize(const DataStatus &input, TLVObject &data)
97 {
98 return sizeof(TLVHead);
99 }
100
Writing(const DataStatus & input,TLVObject & data,TAG tag)101 template <> bool Writing(const DataStatus &input, TLVObject &data, TAG tag)
102 {
103 return true;
104 }
105
Reading(DataStatus & output,TLVObject & data,const TLVHead & head)106 template <> bool Reading(DataStatus &output, TLVObject &data, const TLVHead &head)
107 {
108 return true;
109 }
110
CountBufferSize(const Object & input,TLVObject & data)111 template <> size_t CountBufferSize(const Object &input, TLVObject &data)
112 {
113 return sizeof(TLVHead);
114 }
115
Writing(const Object & input,TLVObject & data,TAG tag)116 template <> bool Writing(const Object &input, TLVObject &data, TAG tag)
117 {
118 return true;
119 }
Reading(Object & output,TLVObject & data,const TLVHead & head)120 template <> bool Reading(Object &output, TLVObject &data, const TLVHead &head)
121 {
122 return true;
123 }
124
CountBufferSize(const UnifiedKey & input,TLVObject & data)125 template <> size_t CountBufferSize(const UnifiedKey &input, TLVObject &data)
126 {
127 return sizeof(TLVHead);
128 }
Writing(const UnifiedKey & input,TLVObject & data,TAG tag)129 template <> bool Writing(const UnifiedKey &input, TLVObject &data, TAG tag)
130 {
131 return true;
132 }
133
Reading(UnifiedKey & output,TLVObject & data,const TLVHead & head)134 template <> bool Reading(UnifiedKey &output, TLVObject &data, const TLVHead &head)
135 {
136 return true;
137 }
138
CountBufferSize(const UnifiedData & input,TLVObject & data)139 template <> size_t CountBufferSize(const UnifiedData &input, TLVObject &data)
140 {
141 return sizeof(TLVHead);
142 }
143
Writing(const UnifiedData & input,TLVObject & data,TAG tag)144 template <> bool Writing(const UnifiedData &input, TLVObject &data, TAG tag)
145 {
146 if (input.dataId_ == 0) {
147 return false;
148 }
149 return true;
150 }
151
Reading(UnifiedData & output,TLVObject & data,const TLVHead & head)152 template <> bool Reading(UnifiedData &output, TLVObject &data, const TLVHead &head)
153 {
154 return false;
155 }
156
CountBufferSize(const UnifiedRecord & input,TLVObject & data)157 template <> size_t CountBufferSize(const UnifiedRecord &input, TLVObject &data)
158 {
159 return sizeof(TLVHead);
160 }
161
Writing(const UnifiedRecord & input,TLVObject & data,TAG tag)162 template <> bool Writing(const UnifiedRecord &input, TLVObject &data, TAG tag)
163 {
164 return true;
165 }
166
Reading(UnifiedRecord & output,TLVObject & data,const TLVHead & head)167 template <> bool Reading(UnifiedRecord &output, TLVObject &data, const TLVHead &head)
168 {
169 return true;
170 }
171
CountBufferSize(const Runtime & input,TLVObject & data)172 template <> size_t CountBufferSize(const Runtime &input, TLVObject &data)
173 {
174 return sizeof(TLVHead);
175 }
176
Writing(const Runtime & input,TLVObject & data,TAG tag)177 template <> bool Writing(const Runtime &input, TLVObject &data, TAG tag)
178 {
179 return true;
180 }
181
Reading(Runtime & output,TLVObject & data,const TLVHead & head)182 template <> bool Reading(Runtime &output, TLVObject &data, const TLVHead &head)
183 {
184 return true;
185 }
186
CountBufferSize(const Privilege & input,TLVObject & data)187 template <> size_t CountBufferSize(const Privilege &input, TLVObject &data)
188 {
189 return sizeof(TLVHead);
190 }
191
Writing(const Privilege & input,TLVObject & data,TAG tag)192 template <> bool Writing(const Privilege &input, TLVObject &data, TAG tag)
193 {
194 return true;
195 }
196
Reading(Privilege & output,TLVObject & data,const TLVHead & head)197 template <> bool Reading(Privilege &output, TLVObject &data, const TLVHead &head)
198 {
199 return true;
200 }
201
CountBufferSize(const std::shared_ptr<OHOS::Media::PixelMap> & input,TLVObject & data)202 template <> size_t CountBufferSize(const std::shared_ptr<OHOS::Media::PixelMap> &input, TLVObject &data)
203 {
204 return sizeof(TLVHead);
205 }
206
Writing(const std::shared_ptr<OHOS::Media::PixelMap> & input,TLVObject & data,TAG tag)207 template <> bool Writing(const std::shared_ptr<OHOS::Media::PixelMap> &input, TLVObject &data, TAG tag)
208 {
209 return true;
210 }
211
Reading(std::shared_ptr<OHOS::Media::PixelMap> & output,TLVObject & data,const TLVHead & head)212 template <> bool Reading(std::shared_ptr<OHOS::Media::PixelMap> &output, TLVObject &data, const TLVHead &head)
213 {
214 return true;
215 }
216
CountBufferSize(const std::shared_ptr<OHOS::AAFwk::Want> & input,TLVObject & data)217 template <> size_t CountBufferSize(const std::shared_ptr<OHOS::AAFwk::Want> &input, TLVObject &data)
218 {
219 return sizeof(TLVHead);
220 }
221
Writing(const std::shared_ptr<OHOS::AAFwk::Want> & input,TLVObject & data,TAG tag)222 template <> bool Writing(const std::shared_ptr<OHOS::AAFwk::Want> &input, TLVObject &data, TAG tag)
223 {
224 return true;
225 }
226
227
Reading(std::shared_ptr<OHOS::AAFwk::Want> & output,TLVObject & data,const TLVHead & head)228 template <> bool Reading(std::shared_ptr<OHOS::AAFwk::Want> &output, TLVObject &data, const TLVHead &head)
229 {
230 return true;
231 }
232
CountBufferSize(const DataLoadInfo & input,TLVObject & data)233 template <> size_t API_EXPORT CountBufferSize(const DataLoadInfo &input, TLVObject &data)
234 {
235 return sizeof(TLVHead);
236 }
237
Writing(const DataLoadInfo & input,TLVObject & data,TAG tag)238 template <> bool API_EXPORT Writing(const DataLoadInfo &input, TLVObject &data, TAG tag)
239 {
240 return true;
241 }
242
Reading(DataLoadInfo & output,TLVObject & data,const TLVHead & head)243 template <> bool API_EXPORT Reading(DataLoadInfo &output, TLVObject &data, const TLVHead &head)
244 {
245 return true;
246 }
247 } // namespace TLVUtil
248 } // namespace OHOS
249