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