1 /*
2  * Copyright (c) 2021 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 #ifndef DB_ABILITY_H
17 #define DB_ABILITY_H
18 
19 #include <cstdint>
20 #include <set>
21 #include <map>
22 #include "macro_utils.h"
23 #include "parcel.h"
24 #include "sync_config.h"
25 
26 namespace DistributedDB {
27 class DbAbility {
28 public:
29     DbAbility();
30     DbAbility(const DbAbility &other);
31     DbAbility& operator=(const DbAbility &other);
32     ~DbAbility() = default;
33 
34     bool operator==(const DbAbility &other) const;
35     // translate dbAbility_ to std::vector<uint64_t>
36     static int Serialize(Parcel &parcel, const DbAbility &curAbility);
37 
38     static int DeSerialize(Parcel &parcel, DbAbility &curAbility);
39 
40     static uint32_t CalculateLen(const DbAbility &curAbility);
41 
42     void SetDbAbilityBuff(const std::vector<bool> &buff);
43 
44     const std::vector<bool> &GetDbAbilityBuff() const;
45 
46     uint32_t GetAbilityBitsLen() const;
47 
48     uint8_t GetAbilityItem(const AbilityItem &abilityType) const;
49 
50     int SetAbilityItem(const AbilityItem &abilityType, uint8_t data);
51 private:
52     constexpr static int SERIALIZE_BIT_SIZE = 64; // uint64_t bit size
53 
54     std::vector<bool> dbAbility_;
55     std::set<AbilityItem> dbAbilityItemSet_;
56 };
57 } // namespace DistributedDB
58 
59 #endif // DB_ABILITY_H