|
39 | 39 | int8_t _z_push_encode(_z_wbuf_t *wbf, const _z_n_msg_push_t *msg) {
|
40 | 40 | uint8_t header = _Z_MID_N_PUSH | (_z_keyexpr_is_local(&msg->_key) ? _Z_FLAG_N_REQUEST_M : 0);
|
41 | 41 | _Bool has_suffix = _z_keyexpr_has_suffix(msg->_key);
|
| 42 | + _Bool has_qos_ext = msg->_qos._val != _Z_N_QOS_DEFAULT._val; |
42 | 43 | _Bool has_timestamp_ext = _z_timestamp_check(&msg->_timestamp);
|
43 | 44 | if (has_suffix) {
|
44 | 45 | header |= _Z_FLAG_N_REQUEST_N;
|
45 | 46 | }
|
46 |
| - if (has_timestamp_ext) { |
| 47 | + if (has_qos_ext || has_timestamp_ext) { |
47 | 48 | header |= _Z_FLAG_N_Z;
|
48 | 49 | }
|
49 | 50 | _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header));
|
50 | 51 | _Z_RETURN_IF_ERR(_z_keyexpr_encode(wbf, has_suffix, &msg->_key));
|
51 | 52 |
|
52 |
| - if (msg->_qos._val != _Z_N_QOS_DEFAULT._val) { |
| 53 | + if (has_qos_ext) { |
53 | 54 | _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ENC_ZINT | 0x01 | (has_timestamp_ext << 7)));
|
54 | 55 | _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, msg->_qos._val));
|
55 | 56 | }
|
@@ -411,12 +412,37 @@ int8_t _z_response_final_encode(_z_wbuf_t *wbf, const _z_n_msg_response_final_t
|
411 | 412 |
|
412 | 413 | return ret;
|
413 | 414 | }
|
| 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 | + |
414 | 437 | int8_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, uint8_t header) {
|
415 | 438 | (void)(header);
|
416 | 439 |
|
417 | 440 | *msg = (_z_n_msg_response_final_t){0};
|
418 | 441 | int8_t ret = _Z_RES_OK;
|
419 | 442 | 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 | + } |
420 | 446 | return ret;
|
421 | 447 | }
|
422 | 448 |
|
|
0 commit comments