Skip to content

Commit

Permalink
Refined QueryableInfo message format
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Mar 26, 2024
1 parent b0ae036 commit 50de33d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions include/zenoh-pico/protocol/definitions/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions src/protocol/codec/declarations.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/definitions/declarations.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion zenohpico.pc
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 50de33d

Please sign in to comment.