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 "long_serializer.h"
17 #include <string_ex.h>
18
19 namespace OHOS {
20 namespace EDM {
Deserialize(const std::string & jsonString,int64_t & dataObj)21 bool LongSerializer::Deserialize(const std::string &jsonString, int64_t &dataObj)
22 {
23 dataObj = stoi(jsonString);
24 return true;
25 }
26
Serialize(const int64_t & dataObj,std::string & jsonString)27 bool LongSerializer::Serialize(const int64_t &dataObj, std::string &jsonString)
28 {
29 jsonString = std::to_string(dataObj);
30 return true;
31 }
32
GetPolicy(MessageParcel & data,int64_t & result)33 bool LongSerializer::GetPolicy(MessageParcel &data, int64_t &result)
34 {
35 result = data.ReadInt64();
36 return true;
37 }
38
WritePolicy(MessageParcel & reply,int64_t & result)39 bool LongSerializer::WritePolicy(MessageParcel &reply, int64_t &result)
40 {
41 return reply.WriteInt64(result);
42 }
43
MergePolicy(std::vector<int64_t> & data,int64_t & result)44 bool LongSerializer::MergePolicy(std::vector<int64_t> &data, int64_t &result)
45 {
46 for (auto iter = data.rbegin(); iter != data.rend(); ++iter) {
47 result = *iter;
48 return true;
49 }
50 return true;
51 }
52 } // namespace EDM
53 } // namespace OHOS