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 #include "metadata/user_meta_data.h"
16
17 #include "utils/constant.h"
18
19 namespace OHOS::DistributedData {
20 constexpr const char *UserMetaRow::KEY_PREFIX;
Marshal(json & node) const21 bool UserMetaData::Marshal(json &node) const
22 {
23 bool ret = true;
24 ret = SetValue(node[GET_NAME(deviceId)], deviceId) && ret;
25 ret = SetValue(node[GET_NAME(users)], users) && ret;
26
27 return ret;
28 }
29
Unmarshal(const json & node)30 bool UserMetaData::Unmarshal(const json &node)
31 {
32 bool ret = true;
33 ret = GetValue(node, GET_NAME(deviceId), deviceId) && ret;
34 ret = GetValue(node, GET_NAME(users), users) && ret;
35
36 return ret;
37 }
38
Marshal(json & node) const39 bool UserStatus::Marshal(json &node) const
40 {
41 bool ret = true;
42 ret = SetValue(node[GET_NAME(id)], id) && ret;
43 ret = SetValue(node[GET_NAME(isActive)], isActive) && ret;
44 return ret;
45 }
46
Unmarshal(const json & node)47 bool UserStatus::Unmarshal(const json &node)
48 {
49 bool ret = true;
50 ret = GetValue(node, GET_NAME(id), id) && ret;
51 ret = GetValue(node, GET_NAME(isActive), isActive) && ret;
52 return ret;
53 }
UserStatus(int id,bool isActive)54 UserStatus::UserStatus(int id, bool isActive) : id(id), isActive(isActive)
55 {
56 }
57
GetKeyFor(const std::string & key)58 std::string UserMetaRow::GetKeyFor(const std::string &key)
59 {
60 std::string str = Constant::Concatenate({ KEY_PREFIX, Constant::KEY_SEPARATOR, key });
61 return { str.begin(), str.end() };
62 }
63 } // namespace OHOS::DistributedData
64