• 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 "metadata/capability_meta_data.h"
17 
18 #include "utils/constant.h"
19 namespace OHOS::DistributedData {
20 constexpr int32_t CapMetaData::CURRENT_VERSION;
21 constexpr int32_t CapMetaData::INVALID_VERSION;
22 constexpr const char *CapMetaRow::KEY_PREFIX;
23 constexpr int32_t INDEX_NUM = 2;
24 constexpr int32_t INDEX_PREFIX = 0;
25 constexpr int32_t INDEX_DEVICE = 1;
Marshal(json & node) const26 bool CapMetaData::Marshal(json &node) const
27 {
28     bool ret = true;
29     ret = SetValue(node[GET_NAME(version)], version) && ret;
30     ret = SetValue(node[GET_NAME(deviceId)], deviceId) && ret;
31     return ret;
32 }
33 
Unmarshal(const json & node)34 bool CapMetaData::Unmarshal(const json &node)
35 {
36     bool ret = true;
37     ret = GetValue(node, GET_NAME(version), version) && ret;
38     ret = GetValue(node, GET_NAME(deviceId), deviceId) && ret;
39     return ret;
40 }
41 
GetKeyFor(const std::string & key)42 std::vector<uint8_t> CapMetaRow::GetKeyFor(const std::string &key)
43 {
44     std::string str = Constant::Concatenate({ KEY_PREFIX, Constant::KEY_SEPARATOR, key });
45     return { str.begin(), str.end() };
46 }
47 
GetDeviceId(const std::string & key)48 const std::string CapMetaRow::GetDeviceId(const std::string &key)
49 {
50     auto items = Constant::Split(key, Constant::KEY_SEPARATOR);
51     if (items.size() < INDEX_NUM || items[INDEX_PREFIX] != KEY_PREFIX) {
52         return "";
53     }
54     return items[INDEX_DEVICE];
55 }
56 } // namespace OHOS::DistributedData
57