Skip to content

Commit bffc549

Browse files
committed
Fix codec bugs
1 parent e3a86d9 commit bffc549

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

include/zenoh-pico/protocol/definitions/network.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef struct {
6363
} _z_n_qos_t;
6464

6565
#define _z_n_qos_make(express, nodrop, priority) \
66-
(_z_n_qos_t) { ._val = ((express << 4) | (nodrop << 3) | priority) }
66+
(_z_n_qos_t) { ._val = (((express) << 4) | ((nodrop) << 3) | priority) }
6767
#define _Z_N_QOS_DEFAULT _z_n_qos_make(0, 0, 5)
6868

6969
// RESPONSE FINAL message flags:

src/protocol/codec/network.c

+28-2
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@
3939
int8_t _z_push_encode(_z_wbuf_t *wbf, const _z_n_msg_push_t *msg) {
4040
uint8_t header = _Z_MID_N_PUSH | (_z_keyexpr_is_local(&msg->_key) ? _Z_FLAG_N_REQUEST_M : 0);
4141
_Bool has_suffix = _z_keyexpr_has_suffix(msg->_key);
42+
_Bool has_qos_ext = msg->_qos._val != _Z_N_QOS_DEFAULT._val;
4243
_Bool has_timestamp_ext = _z_timestamp_check(&msg->_timestamp);
4344
if (has_suffix) {
4445
header |= _Z_FLAG_N_REQUEST_N;
4546
}
46-
if (has_timestamp_ext) {
47+
if (has_qos_ext || has_timestamp_ext) {
4748
header |= _Z_FLAG_N_Z;
4849
}
4950
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header));
5051
_Z_RETURN_IF_ERR(_z_keyexpr_encode(wbf, has_suffix, &msg->_key));
5152

52-
if (msg->_qos._val != _Z_N_QOS_DEFAULT._val) {
53+
if (has_qos_ext) {
5354
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ENC_ZINT | 0x01 | (has_timestamp_ext << 7)));
5455
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, msg->_qos._val));
5556
}
@@ -411,12 +412,37 @@ int8_t _z_response_final_encode(_z_wbuf_t *wbf, const _z_n_msg_response_final_t
411412

412413
return ret;
413414
}
415+
416+
int8_t _z_response_final_decode_extension(_z_msg_ext_t *extension, void *ctx) {
417+
int8_t ret = _Z_RES_OK;
418+
_z_n_msg_response_t *msg = (_z_n_msg_response_t *)ctx;
419+
switch (_Z_EXT_FULL_ID(extension->_header)) {
420+
case _Z_MSG_EXT_ENC_ZINT | 0x01: {
421+
msg->_ext_qos._val = extension->_body._zint._val;
422+
break;
423+
}
424+
case _Z_MSG_EXT_ENC_ZBUF | 0x02: {
425+
_z_zbuf_t zbf = _z_zbytes_as_zbuf(extension->_body._zbuf._val);
426+
ret = _z_timestamp_decode(&msg->_ext_timestamp, &zbf);
427+
break;
428+
}
429+
default:
430+
if (_Z_HAS_FLAG(extension->_header, _Z_MSG_EXT_FLAG_M)) {
431+
ret = _z_msg_ext_unknown_error(extension, 0x0d);
432+
}
433+
}
434+
return ret;
435+
}
436+
414437
int8_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, uint8_t header) {
415438
(void)(header);
416439

417440
*msg = (_z_n_msg_response_final_t){0};
418441
int8_t ret = _Z_RES_OK;
419442
ret |= _z_zint_decode(&msg->_request_id, zbf);
443+
if (_Z_HAS_FLAG(header, _Z_FLAG_Z_Z)) {
444+
_Z_RETURN_IF_ERR(_z_msg_ext_decode_iter(zbf, _z_response_final_decode_extension, msg));
445+
}
420446
return ret;
421447
}
422448

zenohpico.pc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ prefix=/usr/local
33
Name: zenohpico
44
Description:
55
URL:
6-
Version: 0.10.20230906dev
6+
Version: 0.10.20230911dev
77
Cflags: -I${prefix}/
88
Libs: -L${prefix}/ -lzenohpico

0 commit comments

Comments
 (0)