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 #include "cloud/cloud_extra_data.h"
16
17 #include "cloud/cloud_config_manager.h"
18
19 namespace OHOS::DistributedData {
Marshal(Serializable::json &node) const20 bool Context::Marshal(Serializable::json &node) const
21 {
22 SetValue(node[GET_NAME(traceId)], traceId);
23 SetValue(node[GET_NAME(prepareTraceId)], prepareTraceId);
24 return true;
25 }
26
Unmarshal(const Serializable::json &node)27 bool Context::Unmarshal(const Serializable::json &node)
28 {
29 GetValue(node, GET_NAME(traceId), traceId);
30 GetValue(node, GET_NAME(prepareTraceId), prepareTraceId);
31 return true;
32 }
33
Marshal(Serializable::json &node) const34 bool ExtensionInfo::Marshal(Serializable::json &node) const
35 {
36 SetValue(node[GET_NAME(accountId)], accountId);
37 SetValue(node[GET_NAME(bundleName)], bundleName);
38 SetValue(node[GET_NAME(containerName)], containerName);
39 SetValue(node[GET_NAME(databaseScopes)], databaseScopes);
40 SetValue(node[GET_NAME(recordTypes)], recordTypes);
41 return true;
42 }
43
Unmarshal(const Serializable::json &node)44 bool ExtensionInfo::Unmarshal(const Serializable::json &node)
45 {
46 GetValue(node, GET_NAME(accountId), accountId);
47 GetValue(node, GET_NAME(bundleName), bundleName);
48 bundleName = CloudConfigManager::GetInstance().ToLocal(bundleName);
49 GetValue(node, GET_NAME(containerName), containerName);
50 GetValue(node, GET_NAME(databaseScopes), databaseScopes);
51 if (!Unmarshall(databaseScopes, scopes)) {
52 return false;
53 }
54 GetValue(node, GET_NAME(recordTypes), recordTypes);
55 if (!Unmarshall(recordTypes, tables)) {
56 return false;
57 }
58 std::string data;
59 GetValue(node, GET_NAME(context), data);
60 if (data.empty()) {
61 return true;
62 }
63 return context.Unmarshall(data);
64 }
65
Marshal(Serializable::json &node) const66 bool ExtraData::Marshal(Serializable::json &node) const
67 {
68 SetValue(node[GET_NAME(header)], header);
69 SetValue(node[GET_NAME(data)], data);
70 return true;
71 }
72
Unmarshal(const Serializable::json &node)73 bool ExtraData::Unmarshal(const Serializable::json &node)
74 {
75 GetValue(node, GET_NAME(header), header);
76 GetValue(node, GET_NAME(data), data);
77 return info.Unmarshall(data);
78 }
79
isPrivate() const80 bool ExtraData::isPrivate() const
81 {
82 return (std::find(info.scopes.begin(), info.scopes.end(), PRIVATE_TABLE) != info.scopes.end());
83 }
84
isShared() const85 bool ExtraData::isShared() const
86 {
87 return (std::find(info.scopes.begin(), info.scopes.end(), SHARED_TABLE) != info.scopes.end());
88 }
89 } // namespace OHOS::DistributedData