• 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 "string_serializer.h"
17 #include <string_ex.h>
18 
19 namespace OHOS {
20 namespace EDM {
Deserialize(const std::string & jsonString,std::string & dataObj)21 bool StringSerializer::Deserialize(const std::string &jsonString, std::string &dataObj)
22 {
23     if (!jsonString.empty()) {
24         std::string jsonStr = jsonString;
25         jsonStr.erase(remove(jsonStr.begin(), jsonStr.end(), '\"'), jsonStr.end());
26         dataObj = jsonStr;
27     } else {
28         dataObj = jsonString;
29     }
30     return true;
31 }
32 
Serialize(const std::string & dataObj,std::string & jsonString)33 bool StringSerializer::Serialize(const std::string &dataObj, std::string &jsonString)
34 {
35     jsonString = dataObj;
36     return true;
37 }
38 
GetPolicy(MessageParcel & data,std::string & result)39 bool StringSerializer::GetPolicy(MessageParcel &data, std::string &result)
40 {
41     result = data.ReadString();
42     return true;
43 }
44 
WritePolicy(MessageParcel & reply,std::string & result)45 bool StringSerializer::WritePolicy(MessageParcel &reply, std::string &result)
46 {
47     return reply.WriteString(result);
48 }
49 
MergePolicy(std::vector<std::string> & data,std::string & result)50 bool StringSerializer::MergePolicy(std::vector<std::string> &data, std::string &result)
51 {
52     if (!data.empty()) {
53         result = *(data.rbegin());
54     }
55     return true;
56 }
57 } // namespace EDM
58 } // namespace OHOS