diff --git a/include/zenoh-pico/protocol/definitions/declarations.h b/include/zenoh-pico/protocol/definitions/declarations.h index 4e0bae713..66e21add2 100644 --- a/include/zenoh-pico/protocol/definitions/declarations.h +++ b/include/zenoh-pico/protocol/definitions/declarations.h @@ -48,8 +48,8 @@ typedef struct { _z_keyexpr_t _keyexpr; uint32_t _id; struct { - uint8_t _complete; - uint32_t _distance; + _Bool _complete; + uint16_t _distance; } _ext_queryable_info; } _z_decl_queryable_t; _z_decl_queryable_t _z_decl_queryable_null(void); @@ -132,7 +132,7 @@ _z_declaration_t _z_make_undecl_keyexpr(uint16_t id); _z_declaration_t _z_make_decl_subscriber(_Z_MOVE(_z_keyexpr_t) key, uint32_t id, _Bool reliable); _z_declaration_t _z_make_undecl_subscriber(uint32_t id, _Z_OPTIONAL const _z_keyexpr_t* key); -_z_declaration_t _z_make_decl_queryable(_Z_MOVE(_z_keyexpr_t) key, uint32_t id, uint32_t distance, uint8_t complete); +_z_declaration_t _z_make_decl_queryable(_Z_MOVE(_z_keyexpr_t) key, uint32_t id, uint16_t distance, _Bool complete); _z_declaration_t _z_make_undecl_queryable(uint32_t id, _Z_OPTIONAL const _z_keyexpr_t* key); _z_declaration_t _z_make_decl_token(_Z_MOVE(_z_keyexpr_t) key, uint32_t id); diff --git a/src/protocol/codec/declarations.c b/src/protocol/codec/declarations.c index d9d86d684..824965c2d 100644 --- a/src/protocol/codec/declarations.c +++ b/src/protocol/codec/declarations.c @@ -107,12 +107,16 @@ int8_t _z_undecl_subscriber_encode(_z_wbuf_t *wbf, const _z_undecl_subscriber_t } int8_t _z_decl_queryable_encode(_z_wbuf_t *wbf, const _z_decl_queryable_t *decl) { uint8_t header = _Z_DECL_QUERYABLE_MID; - _Bool has_info_ext = (decl->_ext_queryable_info._complete != 0) || (decl->_ext_queryable_info._distance != 0); + _Bool has_info_ext = decl->_ext_queryable_info._complete || (decl->_ext_queryable_info._distance != 0); _Z_RETURN_IF_ERR(_z_decl_commons_encode(wbf, header, has_info_ext, decl->_id, decl->_keyexpr)); if (has_info_ext) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ENC_ZINT | 0x01)); - _Z_RETURN_IF_ERR(_z_zint64_encode( - wbf, ((uint64_t)decl->_ext_queryable_info._distance << 8) | decl->_ext_queryable_info._complete)); + uint8_t flags = 0; + if (decl->_ext_queryable_info._complete) { + flags |= 0x01; + } + uint64_t value = (uint64_t)flags | (uint64_t)decl->_ext_queryable_info._distance << 8; + _Z_RETURN_IF_ERR(_z_zint64_encode(wbf, value)); } return _Z_RES_OK; } @@ -328,8 +332,8 @@ int8_t _z_decl_queryable_decode_extensions(_z_msg_ext_t *extension, void *ctx) { switch (extension->_header) { case _Z_MSG_EXT_ENC_ZINT | 0x01: { uint64_t val = extension->_body._zint._val; - decl->_ext_queryable_info._complete = val & 0xff; - decl->_ext_queryable_info._distance = (uint32_t)(val >> 8); + decl->_ext_queryable_info._complete = _Z_HAS_FLAG(val, 0x01); + decl->_ext_queryable_info._distance = (uint16_t)(val >> 8); } break; default: if (_Z_HAS_FLAG(extension->_header, _Z_MSG_EXT_FLAG_M)) { diff --git a/src/protocol/definitions/declarations.c b/src/protocol/definitions/declarations.c index 709899619..69dc52560 100644 --- a/src/protocol/definitions/declarations.c +++ b/src/protocol/definitions/declarations.c @@ -83,7 +83,7 @@ _z_declaration_t _z_make_undecl_subscriber(uint32_t id, _Z_OPTIONAL const _z_key ._id = id, ._ext_keyexpr = (key == NULL) ? _z_keyexpr_null() : _z_keyexpr_duplicate(*key)}}}; } -_z_declaration_t _z_make_decl_queryable(_Z_MOVE(_z_keyexpr_t) key, uint32_t id, uint32_t distance, uint8_t complete) { +_z_declaration_t _z_make_decl_queryable(_Z_MOVE(_z_keyexpr_t) key, uint32_t id, uint16_t distance, _Bool complete) { return (_z_declaration_t){ ._tag = _Z_DECL_QUERYABLE, ._body = {._decl_queryable = {._id = id, diff --git a/zenohpico.pc b/zenohpico.pc index 19ac5e7de..17aab2980 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -3,6 +3,6 @@ prefix=/usr/local Name: zenohpico Description: URL: -Version: 0.11.20240319dev +Version: 0.11.20240326dev Cflags: -I${prefix}/include Libs: -L${prefix}/lib -lzenohpico