Skip to content

Commit

Permalink
refactor: use flag macros
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Mar 7, 2024
1 parent 0890f20 commit d01379a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/zenoh-pico/protocol/definitions/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
#define _Z_FLAGS(h) (_Z_FLAGS_MASK & (h))
#define _Z_HAS_FLAG(h, f) (((h) & (f)) != 0)
#define _Z_SET_FLAG(h, f) (h |= f)
#define _Z_CLEAR_FLAG(h, f) (h &= ~(f))

#endif /* INCLUDE_ZENOH_PICO_PROTOCOL_DEFINITIONS_CORE_H */
20 changes: 10 additions & 10 deletions src/protocol/codec/declarations.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,27 @@ int8_t _z_decl_interest_encode(_z_wbuf_t *wbf, const _z_decl_interest_t *decl) {
// Set header
uint8_t header = _Z_DECL_INTEREST_MID;
if (_Z_HAS_FLAG(decl->interest_flags, _Z_INTEREST_FLAG_CURRENT)) {
header |= _Z_INTEREST_FLAG_CURRENT;
_Z_SET_FLAG(header, _Z_INTEREST_FLAG_CURRENT);
}
if (_Z_HAS_FLAG(decl->interest_flags, _Z_INTEREST_FLAG_FUTURE)) {
header |= _Z_INTEREST_FLAG_FUTURE;
_Z_SET_FLAG(header, _Z_INTEREST_FLAG_FUTURE);
}
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header));
// Set id
_Z_RETURN_IF_ERR(_z_zint_encode(wbf, decl->_id));
// Copy flags but clear double use ones.
uint8_t interest_flags = decl->interest_flags;
interest_flags &= ~_Z_DECL_SUBSCRIBER_FLAG_N;
interest_flags &= ~_Z_DECL_SUBSCRIBER_FLAG_M;
_Z_CLEAR_FLAG(interest_flags, _Z_INTEREST_FLAG_CURRENT);
_Z_CLEAR_FLAG(interest_flags, _Z_INTEREST_FLAG_FUTURE);
// Process restricted flag
if (_Z_HAS_FLAG(interest_flags, _Z_INTEREST_FLAG_RESTRICTED)) {
// Set Named & Mapping flags
_Bool has_kesuffix = _z_keyexpr_has_suffix(decl->_keyexpr);
if (has_kesuffix) {
interest_flags |= _Z_DECL_SUBSCRIBER_FLAG_N;
_Z_SET_FLAG(interest_flags, _Z_DECL_SUBSCRIBER_FLAG_N);
}
if (_z_keyexpr_is_local(&decl->_keyexpr)) {
interest_flags |= _Z_DECL_SUBSCRIBER_FLAG_M;
_Z_SET_FLAG(interest_flags, _Z_DECL_SUBSCRIBER_FLAG_M);
}
// Set decl flags & keyexpr
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, decl->interest_flags));
Expand Down Expand Up @@ -398,13 +398,13 @@ int8_t _z_decl_interest_decode(_z_decl_interest_t *decl, _z_zbuf_t *zbf, uint8_t
}
}
// Replace named & mapping by current & future flags
decl->interest_flags &= ~_Z_DECL_SUBSCRIBER_FLAG_M;
decl->interest_flags &= ~_Z_DECL_SUBSCRIBER_FLAG_N;
_Z_CLEAR_FLAG(decl->interest_flags, _Z_DECL_SUBSCRIBER_FLAG_M);
_Z_CLEAR_FLAG(decl->interest_flags, _Z_DECL_SUBSCRIBER_FLAG_N);
if (_Z_HAS_FLAG(header, _Z_INTEREST_FLAG_CURRENT)) {
decl->interest_flags |= _Z_INTEREST_FLAG_CURRENT;
_Z_SET_FLAG(decl->interest_flags, _Z_INTEREST_FLAG_CURRENT);
}
if (_Z_HAS_FLAG(header, _Z_INTEREST_FLAG_FUTURE)) {
decl->interest_flags |= _Z_INTEREST_FLAG_FUTURE;
_Z_SET_FLAG(decl->interest_flags, _Z_INTEREST_FLAG_FUTURE);
}
// Decode extention
if (_Z_HAS_FLAG(header, _Z_FLAG_Z_Z)) {
Expand Down

0 comments on commit d01379a

Please sign in to comment.