1 /*
2 * Copyright (c) 2024 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/switches_meta_data.h"
17 #include "utils/constant.h"
18
19 namespace OHOS::DistributedData {
Marshal(json & node) const20 bool SwitchesMetaData::Marshal(json &node) const
21 {
22 SetValue(node[GET_NAME(version)], version);
23 SetValue(node[GET_NAME(value)], value);
24 SetValue(node[GET_NAME(length)], length);
25 SetValue(node[GET_NAME(deviceId)], deviceId);
26 return true;
27 }
28
Unmarshal(const json & node)29 bool SwitchesMetaData::Unmarshal(const json &node)
30 {
31 GetValue(node, GET_NAME(version), version);
32 GetValue(node, GET_NAME(value), value);
33 GetValue(node, GET_NAME(length), length);
34 GetValue(node, GET_NAME(deviceId), deviceId);
35 return true;
36 }
37
GetKey() const38 std::string SwitchesMetaData::GetKey() const
39 {
40 return Constant::Join(KEY_PREFIX, Constant::KEY_SEPARATOR, { deviceId });
41 }
42
GetPrefix(const std::initializer_list<std::string> & fields)43 std::string SwitchesMetaData::GetPrefix(const std::initializer_list<std::string> &fields)
44 {
45 return Constant::Join(KEY_PREFIX, Constant::KEY_SEPARATOR, fields);
46 }
47
operator ==(const SwitchesMetaData & meta) const48 bool SwitchesMetaData::operator==(const SwitchesMetaData &meta) const
49 {
50 return (length == meta.length) && (value == meta.value);
51 }
52
operator !=(const SwitchesMetaData & meta) const53 bool SwitchesMetaData::operator!=(const SwitchesMetaData &meta) const
54 {
55 return !(*this == meta);
56 }
57 } // namespace OHOS::DistributedData