diff --git a/include/zenoh-pico/protocol/codec/network.h b/include/zenoh-pico/protocol/codec/network.h index 9569cc36f..661ee9de2 100644 --- a/include/zenoh-pico/protocol/codec/network.h +++ b/include/zenoh-pico/protocol/codec/network.h @@ -24,20 +24,20 @@ extern "C" { #endif -z_result_t _z_push_encode(_z_wbuf_t *wbf, const _z_n_msg_push_t *msg, bool *is_express); +z_result_t _z_push_encode(_z_wbuf_t *wbf, const _z_n_msg_push_t *msg); z_result_t _z_push_decode(_z_n_msg_push_t *msg, _z_zbuf_t *zbf, uint8_t header, _z_arc_slice_t *arcs); -z_result_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg, bool *is_express); +z_result_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg); z_result_t _z_request_decode(_z_n_msg_request_t *msg, _z_zbuf_t *zbf, uint8_t header, _z_arc_slice_t *arcs); -z_result_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg, bool *is_express); +z_result_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg); z_result_t _z_response_decode(_z_n_msg_response_t *msg, _z_zbuf_t *zbf, uint8_t header, _z_arc_slice_t *arcs); z_result_t _z_response_final_encode(_z_wbuf_t *wbf, const _z_n_msg_response_final_t *msg); z_result_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, uint8_t header); -z_result_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl, bool *is_express); +z_result_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl); z_result_t _z_declare_decode(_z_n_msg_declare_t *decl, _z_zbuf_t *zbf, uint8_t header); z_result_t _z_n_interest_encode(_z_wbuf_t *wbf, const _z_n_msg_interest_t *interest); z_result_t _z_n_interest_decode(_z_n_msg_interest_t *interest, _z_zbuf_t *zbf, uint8_t header); -z_result_t _z_network_message_encode(_z_wbuf_t *wbf, const _z_network_message_t *msg, bool *is_express); +z_result_t _z_network_message_encode(_z_wbuf_t *wbf, const _z_network_message_t *msg); z_result_t _z_network_message_decode(_z_network_message_t *msg, _z_zbuf_t *zbf, _z_arc_slice_t *arcs); #ifdef __cplusplus diff --git a/include/zenoh-pico/protocol/definitions/network.h b/include/zenoh-pico/protocol/definitions/network.h index 2bc7eb0ba..2af9d97ef 100644 --- a/include/zenoh-pico/protocol/definitions/network.h +++ b/include/zenoh-pico/protocol/definitions/network.h @@ -80,8 +80,6 @@ extern "C" { typedef _z_qos_t _z_n_qos_t; -#define _Z_N_QOS_IS_EXPRESS_FLAG (1 << 4) - static inline _z_qos_t _z_n_qos_create(bool express, z_congestion_control_t congestion_control, z_priority_t priority) { _z_n_qos_t ret; bool nodrop = congestion_control == Z_CONGESTION_CONTROL_DROP ? 0 : 1; diff --git a/src/protocol/codec/network.c b/src/protocol/codec/network.c index 93d829449..44cf9cde9 100644 --- a/src/protocol/codec/network.c +++ b/src/protocol/codec/network.c @@ -38,14 +38,11 @@ /*------------------ Push Message ------------------*/ -z_result_t _z_push_encode(_z_wbuf_t *wbf, const _z_n_msg_push_t *msg, bool *is_express) { +z_result_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 (is_express != NULL) { - *is_express = _Z_HAS_FLAG(msg->_qos._val, _Z_N_QOS_IS_EXPRESS_FLAG); - } if (has_suffix) { header |= _Z_FLAG_N_REQUEST_N; } @@ -114,7 +111,7 @@ z_result_t _z_push_decode(_z_n_msg_push_t *msg, _z_zbuf_t *zbf, uint8_t header, } /*------------------ Request Message ------------------*/ -z_result_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg, bool *is_express) { +z_result_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg) { z_result_t ret = _Z_RES_OK; uint8_t header = _Z_MID_N_REQUEST | (_z_keyexpr_is_local(&msg->_key) ? _Z_FLAG_N_REQUEST_M : 0); bool has_suffix = _z_keyexpr_has_suffix(&msg->_key); @@ -131,9 +128,6 @@ z_result_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg, bool uint8_t extheader = 0x01 | _Z_MSG_EXT_ENC_ZINT | (exts.n ? _Z_FLAG_Z_Z : 0); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_ext_qos._val)); - if (is_express != NULL) { - *is_express = _Z_HAS_FLAG(msg->_ext_qos._val, _Z_N_QOS_IS_EXPRESS_FLAG); - } } if (exts.ext_tstamp) { exts.n -= 1; @@ -244,7 +238,7 @@ z_result_t _z_request_decode(_z_n_msg_request_t *msg, _z_zbuf_t *zbf, const uint } /*------------------ Response Message ------------------*/ -z_result_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg, bool *is_express) { +z_result_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg) { z_result_t ret = _Z_RES_OK; uint8_t header = _Z_MID_N_RESPONSE; _Z_DEBUG("Encoding _Z_MID_N_RESPONSE"); @@ -253,9 +247,6 @@ z_result_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg, bo bool has_responder_ext = _z_id_check(msg->_ext_responder._zid) || msg->_ext_responder._eid != 0; int n_ext = (has_qos_ext ? 1 : 0) + (has_ts_ext ? 1 : 0) + (has_responder_ext ? 1 : 0); bool has_suffix = _z_keyexpr_has_suffix(&msg->_key); - if (is_express != NULL) { - *is_express = _Z_HAS_FLAG(msg->_ext_qos._val, _Z_N_QOS_IS_EXPRESS_FLAG); - } if (_z_keyexpr_is_local(&msg->_key)) { _Z_SET_FLAG(header, _Z_FLAG_N_RESPONSE_M); } @@ -398,13 +389,10 @@ z_result_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *z return ret; } -z_result_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl, bool *is_express) { +z_result_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl) { uint8_t header = _Z_MID_N_DECLARE; bool has_qos_ext = decl->_ext_qos._val != _Z_N_QOS_DEFAULT._val; bool has_timestamp_ext = _z_timestamp_check(&decl->_ext_timestamp); - if (is_express != NULL) { - *is_express = _Z_HAS_FLAG(decl->_ext_qos._val, _Z_N_QOS_IS_EXPRESS_FLAG); - } int n_ext = (has_qos_ext ? 1 : 0) + (has_timestamp_ext ? 1 : 0); if (n_ext != 0) { header |= _Z_FLAG_N_Z; @@ -501,19 +489,19 @@ z_result_t _z_n_interest_decode(_z_n_msg_interest_t *interest, _z_zbuf_t *zbf, u return _z_interest_decode(&interest->_interest, zbf, is_final, has_ext); } -z_result_t _z_network_message_encode(_z_wbuf_t *wbf, const _z_network_message_t *msg, bool *is_express) { +z_result_t _z_network_message_encode(_z_wbuf_t *wbf, const _z_network_message_t *msg) { switch (msg->_tag) { case _Z_N_DECLARE: { - return _z_declare_encode(wbf, &msg->_body._declare, is_express); + return _z_declare_encode(wbf, &msg->_body._declare); } break; case _Z_N_PUSH: { - return _z_push_encode(wbf, &msg->_body._push, is_express); + return _z_push_encode(wbf, &msg->_body._push); } break; case _Z_N_REQUEST: { - return _z_request_encode(wbf, &msg->_body._request, is_express); + return _z_request_encode(wbf, &msg->_body._request); } break; case _Z_N_RESPONSE: { - return _z_response_encode(wbf, &msg->_body._response, is_express); + return _z_response_encode(wbf, &msg->_body._response); } break; case _Z_N_RESPONSE_FINAL: { return _z_response_final_encode(wbf, &msg->_body._response_final); diff --git a/src/protocol/codec/transport.c b/src/protocol/codec/transport.c index 3bc17d24b..894fb41d8 100644 --- a/src/protocol/codec/transport.c +++ b/src/protocol/codec/transport.c @@ -388,7 +388,7 @@ z_result_t _z_frame_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_frame_ if (ret == _Z_RES_OK) { size_t len = _z_network_message_svec_len(&msg->_messages); for (size_t i = 0; i < len; i++) { - _Z_RETURN_IF_ERR(_z_network_message_encode(wbf, _z_network_message_svec_get(&msg->_messages, i), NULL)) + _Z_RETURN_IF_ERR(_z_network_message_encode(wbf, _z_network_message_svec_get(&msg->_messages, i))) } } diff --git a/src/transport/raweth/tx.c b/src/transport/raweth/tx.c index 9116930c5..e8f9be4c4 100644 --- a/src/transport/raweth/tx.c +++ b/src/transport/raweth/tx.c @@ -252,7 +252,7 @@ z_result_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_ _Z_CLEAN_RETURN_IF_ERR(_z_transport_message_encode(&ztm->_common._wbuf, &t_msg), _z_transport_tx_mutex_unlock(&ztm->_common)); // Encode the network message - if (_z_network_message_encode(&ztm->_common._wbuf, n_msg, NULL) == _Z_RES_OK) { + if (_z_network_message_encode(&ztm->_common._wbuf, n_msg) == _Z_RES_OK) { // Write the eth header _Z_CLEAN_RETURN_IF_ERR(__unsafe_z_raweth_write_header(&ztm->_common._link, &ztm->_common._wbuf), _z_transport_tx_mutex_unlock(&ztm->_common)); @@ -266,8 +266,7 @@ z_result_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_ // Create an expandable wbuf for fragmentation _z_wbuf_t fbf = _z_wbuf_make(_Z_FRAG_BUFF_BASE_SIZE, true); // Encode the message on the expandable wbuf - _Z_CLEAN_RETURN_IF_ERR(_z_network_message_encode(&fbf, n_msg, NULL), - _z_transport_tx_mutex_unlock(&ztm->_common)); + _Z_CLEAN_RETURN_IF_ERR(_z_network_message_encode(&fbf, n_msg), _z_transport_tx_mutex_unlock(&ztm->_common)); // Fragment and send the message bool is_first = true; while (_z_wbuf_len(&fbf) > 0) { diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index b1c288a2f..a87c258e4 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -1163,7 +1163,7 @@ void declare_message(void) { _z_network_message_t n_msg = gen_declare_message(); // Encode - z_result_t res = _z_network_message_encode(&wbf, &n_msg, NULL); + z_result_t res = _z_network_message_encode(&wbf, &n_msg); assert(res == _Z_RES_OK); (void)(res); @@ -1433,7 +1433,7 @@ void push_message(void) { printf("\n>> Push message\n"); _z_wbuf_t wbf = gen_wbuf(UINT16_MAX); _z_n_msg_push_t expected = gen_push(); - assert(_z_push_encode(&wbf, &expected, NULL) == _Z_RES_OK); + assert(_z_push_encode(&wbf, &expected) == _Z_RES_OK); _z_n_msg_push_t decoded = {0}; _z_arc_slice_t arcs = {0}; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); @@ -1505,7 +1505,7 @@ void request_message(void) { printf("\n>> Request message\n"); _z_wbuf_t wbf = gen_wbuf(UINT16_MAX); _z_n_msg_request_t expected = gen_request(); - assert(_z_request_encode(&wbf, &expected, NULL) == _Z_RES_OK); + assert(_z_request_encode(&wbf, &expected) == _Z_RES_OK); _z_n_msg_request_t decoded = {0}; _z_arc_slice_t arcs = {0}; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); @@ -1564,7 +1564,7 @@ void response_message(void) { printf("\n>> Response message\n"); _z_wbuf_t wbf = gen_wbuf(UINT16_MAX); _z_n_msg_response_t expected = gen_response(); - assert(_z_response_encode(&wbf, &expected, NULL) == _Z_RES_OK); + assert(_z_response_encode(&wbf, &expected) == _Z_RES_OK); _z_n_msg_response_t decoded = {0}; _z_arc_slice_t arcs = {0}; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf);