Skip to content

Commit

Permalink
clang tidy union
Browse files Browse the repository at this point in the history
Signed-off-by: turuslan <[email protected]>
  • Loading branch information
turuslan committed Sep 27, 2024
1 parent eb9a830 commit 3648105
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions core/network/types/roles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,42 @@

#include "scale/tie.hpp"

// NOLINTBEGIN(cppcoreguidelines-pro-type-union-access)
namespace kagome::network {

union Roles {
struct Roles {
SCALE_TIE_ONLY(value);

struct {
/**
* Full node, does not participate in consensus.
*/
uint8_t full : 1;
union {
struct {
/**
* Full node, does not participate in consensus.
*/
uint8_t full : 1;

/**
* Light client node.
*/
uint8_t light : 1;
/**
* Light client node.
*/
uint8_t light : 1;

/**
* Act as an authority
*/
uint8_t authority : 1;
/**
* Act as an authority
*/
uint8_t authority : 1;

} flags;
uint8_t value;
} flags;
uint8_t value;
};

Roles() : value(0) {}
Roles(uint8_t v) : value(v) {}

// https://github.com/paritytech/polkadot-sdk/blob/6c3219ebe9231a0305f53c7b33cb558d46058062/substrate/client/network/common/src/role.rs#L101
bool isFull() const {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
return flags.full != 0 or isAuthority();
}

bool isAuthority() const {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
return flags.authority != 0;
}

Expand All @@ -53,7 +54,7 @@ namespace kagome::network {
};

inline std::string to_string(Roles r) {
switch (r.value) { // NOLINT(cppcoreguidelines-pro-type-union-access)
switch (r.value) {
case 0:
return "none";
case 1:
Expand All @@ -63,7 +64,7 @@ namespace kagome::network {
case 4:
return "authority";
}
return to_string(
r.value); // NOLINT(cppcoreguidelines-pro-type-union-access)
return to_string(r.value);
}
} // namespace kagome::network
// NOLINTEND(cppcoreguidelines-pro-type-union-access)

0 comments on commit 3648105

Please sign in to comment.