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 "int_serializer.h"
17
18 #include <string_ex.h>
19 #include "edm_constants.h"
20
21 namespace OHOS {
22 namespace EDM {
23
Deserialize(const std::string & jsonString,int32_t & dataObj)24 bool IntSerializer::Deserialize(const std::string &jsonString, int32_t &dataObj)
25 {
26 dataObj = strtol(jsonString.c_str(), nullptr, EdmConstants::DECIMAL);
27 return true;
28 }
29
Serialize(const int32_t & dataObj,std::string & jsonString)30 bool IntSerializer::Serialize(const int32_t &dataObj, std::string &jsonString)
31 {
32 jsonString = std::to_string(dataObj);
33 return true;
34 }
35
GetPolicy(MessageParcel & data,int32_t & result)36 bool IntSerializer::GetPolicy(MessageParcel &data, int32_t &result)
37 {
38 result = data.ReadInt32();
39 return true;
40 }
41
WritePolicy(MessageParcel & reply,int32_t & result)42 bool IntSerializer::WritePolicy(MessageParcel &reply, int32_t &result)
43 {
44 return reply.WriteInt32(result);
45 }
46
MergePolicy(std::vector<int32_t> & data,int32_t & result)47 bool IntSerializer::MergePolicy(std::vector<int32_t> &data, int32_t &result)
48 {
49 if (!data.empty()) {
50 result = *(data.rbegin());
51 }
52 return true;
53 }
54 } // namespace EDM
55 } // namespace OHOS