Skip to content

Commit

Permalink
Fix codec bugs (#244)
Browse files Browse the repository at this point in the history
* Fix codec bugs

* Ignore response final extensions

* Make _z_n_qos_make macro even safer
  • Loading branch information
OlivierHecart authored Sep 11, 2023
1 parent e3a86d9 commit bd245f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/zenoh-pico/protocol/definitions/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef struct {
} _z_n_qos_t;

#define _z_n_qos_make(express, nodrop, priority) \
(_z_n_qos_t) { ._val = ((express << 4) | (nodrop << 3) | priority) }
(_z_n_qos_t) { ._val = (((express) << 4) | ((nodrop) << 3) | (priority)) }
#define _Z_N_QOS_DEFAULT _z_n_qos_make(0, 0, 5)

// RESPONSE FINAL message flags:
Expand Down
9 changes: 7 additions & 2 deletions src/protocol/codec/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@
int8_t _z_push_encode(_z_wbuf_t *wbf, const _z_n_msg_push_t *msg) {
uint8_t header = _Z_MID_N_PUSH | (_z_keyexpr_is_local(&msg->_key) ? _Z_FLAG_N_REQUEST_M : 0);
_Bool has_suffix = _z_keyexpr_has_suffix(msg->_key);
_Bool has_qos_ext = msg->_qos._val != _Z_N_QOS_DEFAULT._val;
_Bool has_timestamp_ext = _z_timestamp_check(&msg->_timestamp);
if (has_suffix) {
header |= _Z_FLAG_N_REQUEST_N;
}
if (has_timestamp_ext) {
if (has_qos_ext || has_timestamp_ext) {
header |= _Z_FLAG_N_Z;
}
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header));
_Z_RETURN_IF_ERR(_z_keyexpr_encode(wbf, has_suffix, &msg->_key));

if (msg->_qos._val != _Z_N_QOS_DEFAULT._val) {
if (has_qos_ext) {
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ENC_ZINT | 0x01 | (has_timestamp_ext << 7)));
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, msg->_qos._val));
}
Expand Down Expand Up @@ -411,12 +412,16 @@ int8_t _z_response_final_encode(_z_wbuf_t *wbf, const _z_n_msg_response_final_t

return ret;
}

int8_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, uint8_t header) {
(void)(header);

*msg = (_z_n_msg_response_final_t){0};
int8_t ret = _Z_RES_OK;
ret |= _z_zint_decode(&msg->_request_id, zbf);
if (_Z_HAS_FLAG(header, _Z_FLAG_Z_Z)) {
_Z_RETURN_IF_ERR(_z_msg_ext_skip_non_mandatories(zbf, 0x1a));
}
return ret;
}

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.10.20230906dev
Version: 0.10.20230911dev
Cflags: -I${prefix}/
Libs: -L${prefix}/ -lzenohpico

0 comments on commit bd245f9

Please sign in to comment.