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 #define LOG_TAG "DataShareTypesUtil"
16 #include "data_share_types_util.h"
17
18 #include "log_print.h"
19 namespace OHOS::ITypesUtil {
20 using namespace OHOS::DataShare;
21 template<>
Unmarshalling(Predicates & predicates,MessageParcel & parcel)22 bool Unmarshalling(Predicates &predicates, MessageParcel &parcel)
23 {
24 ZLOGD("Unmarshalling DataSharePredicates Start");
25 std::vector<Operation> operations {};
26 std::string whereClause = "";
27 std::vector<std::string> whereArgs;
28 std::string order = "";
29 int16_t mode = DataShare::INVALID_MODE;
30 if (!ITypesUtil::Unmarshal(parcel, operations, whereClause, whereArgs, order, mode)) {
31 ZLOGE("predicate read whereClause failed");
32 return false;
33 }
34 DataShare::DataSharePredicates tmpPredicates(operations);
35 tmpPredicates.SetWhereClause(whereClause);
36 tmpPredicates.SetWhereArgs(whereArgs);
37 tmpPredicates.SetOrder(order);
38 tmpPredicates.SetSettingMode(mode);
39 predicates = tmpPredicates;
40 return true;
41 }
42
43 template<>
Unmarshalling(Operation & operation,MessageParcel & parcel)44 bool Unmarshalling(Operation &operation, MessageParcel &parcel)
45 {
46 return ITypesUtil::Unmarshal(parcel, operation.operation, operation.singleParams, operation.multiParams);
47 }
48
49 template<>
Unmarshalling(PublishedDataItem & dataItem,MessageParcel & parcel)50 bool Unmarshalling(PublishedDataItem &dataItem, MessageParcel &parcel)
51 {
52 return ITypesUtil::Unmarshal(parcel, dataItem.key_, dataItem.subscriberId_, dataItem.value_);
53 }
54
55 template<>
Marshalling(const PublishedDataItem & dataItem,MessageParcel & parcel)56 bool Marshalling(const PublishedDataItem &dataItem, MessageParcel &parcel)
57 {
58 return ITypesUtil::Marshal(parcel, dataItem.key_, dataItem.subscriberId_, dataItem.value_);
59 }
60
61 template<>
Unmarshalling(Data & data,MessageParcel & parcel)62 bool Unmarshalling(Data &data, MessageParcel &parcel)
63 {
64 return ITypesUtil::Unmarshal(parcel, data.datas_, data.version_);
65 }
66
67 template<>
Unmarshalling(TemplateId & templateId,MessageParcel & parcel)68 bool Unmarshalling(TemplateId &templateId, MessageParcel &parcel)
69 {
70 return ITypesUtil::Unmarshal(parcel, templateId.subscriberId_, templateId.bundleName_);
71 }
72
73 template<>
Marshalling(const TemplateId & templateId,MessageParcel & parcel)74 bool Marshalling(const TemplateId &templateId, MessageParcel &parcel)
75 {
76 return ITypesUtil::Marshal(parcel, templateId.subscriberId_, templateId.bundleName_);
77 }
78
79 template<>
Unmarshalling(PredicateTemplateNode & predicateTemplateNode,MessageParcel & parcel)80 bool Unmarshalling(PredicateTemplateNode &predicateTemplateNode, MessageParcel &parcel)
81 {
82 return ITypesUtil::Unmarshal(parcel, predicateTemplateNode.key_, predicateTemplateNode.selectSql_);
83 }
84
85 template<>
Marshalling(const RdbChangeNode & changeNode,MessageParcel & parcel)86 bool Marshalling(const RdbChangeNode &changeNode, MessageParcel &parcel)
87 {
88 return ITypesUtil::Marshal(parcel, changeNode.uri_, changeNode.templateId_, changeNode.data_);
89 }
90
91 template<>
Marshalling(const PublishedDataChangeNode & changeNode,MessageParcel & parcel)92 bool Marshalling(const PublishedDataChangeNode &changeNode, MessageParcel &parcel)
93 {
94 return ITypesUtil::Marshal(parcel, changeNode.ownerBundleName_, changeNode.datas_);
95 }
96
97 template<>
Marshalling(const OperationResult & operationResult,MessageParcel & parcel)98 bool Marshalling(const OperationResult &operationResult, MessageParcel &parcel)
99 {
100 return ITypesUtil::Marshal(parcel, operationResult.key_, operationResult.errCode_);
101 }
102
103 template<>
Unmarshalling(AshmemNode & node,MessageParcel & parcel)104 bool Unmarshalling(AshmemNode &node, MessageParcel &parcel)
105 {
106 node.isManaged = true;
107 node.ashmem = parcel.ReadAshmem();
108 return true;
109 }
110
111 template<>
Marshalling(const AshmemNode & node,MessageParcel & parcel)112 bool Marshalling(const AshmemNode &node, MessageParcel &parcel)
113 {
114 return parcel.WriteAshmem(node.ashmem);
115 }
116 }