diff --git a/include/zenoh-pico/protocol/codec/transport.h b/include/zenoh-pico/protocol/codec/transport.h index 344081992..0feaf1784 100644 --- a/include/zenoh-pico/protocol/codec/transport.h +++ b/include/zenoh-pico/protocol/codec/transport.h @@ -17,9 +17,10 @@ #include "zenoh-pico/protocol/definitions/transport.h" #include "zenoh-pico/protocol/iobuf.h" +#define _ZENOH_PICO_FRAME_MESSAGES_VEC_SIZE 32 + int8_t _z_scouting_message_encode(_z_wbuf_t *buf, const _z_scouting_message_t *msg); int8_t _z_scouting_message_decode(_z_scouting_message_t *msg, _z_zbuf_t *buf); -int8_t _z_scouting_message_decode_na(_z_scouting_message_t *msg, _z_zbuf_t *buf); int8_t _z_transport_message_encode(_z_wbuf_t *buf, const _z_transport_message_t *msg); int8_t _z_transport_message_decode(_z_transport_message_t *msg, _z_zbuf_t *buf); @@ -41,4 +42,10 @@ int8_t _z_keep_alive_decode(_z_t_msg_keep_alive_t *msg, _z_zbuf_t *zbf, uint8_t int8_t _z_frame_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_frame_t *msg); int8_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header); + +int8_t _z_fragment_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_fragment_t *msg); +int8_t _z_fragment_decode(_z_t_msg_fragment_t *msg, _z_zbuf_t *zbf, uint8_t header); + +int8_t _z_transport_message_encode(_z_wbuf_t *wbf, const _z_transport_message_t *msg); +int8_t _z_transport_message_decode(_z_transport_message_t *msg, _z_zbuf_t *zbf); #endif /* INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_TRANSPORT_H */ diff --git a/include/zenoh-pico/protocol/msgcodec.h b/include/zenoh-pico/protocol/msgcodec.h deleted file mode 100644 index d87c166a9..000000000 --- a/include/zenoh-pico/protocol/msgcodec.h +++ /dev/null @@ -1,149 +0,0 @@ -// -// Copyright (c) 2022 ZettaScale Technology -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// -// Contributors: -// ZettaScale Zenoh Team, -// - -#ifndef INCLUDE_ZENOH_PICO_PROTOCOL_MSGCODEC_H -#define INCLUDE_ZENOH_PICO_PROTOCOL_MSGCODEC_H - -#include -#define _ZENOH_PICO_FRAME_MESSAGES_VEC_SIZE 32 - -#include "zenoh-pico/collections/element.h" -#include "zenoh-pico/link/endpoint.h" -#include "zenoh-pico/protocol/codec.h" -#include "zenoh-pico/protocol/definitions/transport.h" -#include "zenoh-pico/utils/result.h" - -/*------------------ Zenoh Message ------------------*/ - -// int8_t _z_zenoh_message_encode(_z_wbuf_t *buf, const _z_zenoh_message_t *msg); -// int8_t _z_zenoh_message_decode(_z_zenoh_message_t *msg, _z_zbuf_t *buf); -// int8_t _z_zenoh_message_decode_na(_z_zenoh_message_t *msg, _z_zbuf_t *buf); -#endif /* INCLUDE_ZENOH_PICO_PROTOCOL_MSGCODEC_H */ - -// NOTE: the following headers are for unit testing only -#ifdef ZENOH_PICO_TEST_H -// ------------------ Message Fields ------------------ -int8_t _z_payload_encode(_z_wbuf_t *buf, const _z_bytes_t *pld); -int8_t _z_payload_decode(_z_bytes_t *pld, _z_zbuf_t *buf); -int8_t _z_payload_decode_na(_z_bytes_t *pld, _z_zbuf_t *buf); -int8_t _z_subinfo_decode_na(_z_subinfo_t *si, _z_zbuf_t *buf, uint8_t header); - -int8_t _z_data_info_encode(_z_wbuf_t *buf, const _z_data_info_t *di); -int8_t _z_data_info_decode(_z_data_info_t *di, _z_zbuf_t *buf); -int8_t _z_data_info_decode_na(_z_data_info_t *di, _z_zbuf_t *buf); - -// ------------------ Zenoh Message ------------------ -int8_t _z_res_decl_encode(_z_wbuf_t *buf, uint8_t header, const _z_res_decl_t *dcl); -int8_t _z_res_decl_decode(_z_res_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); -int8_t _z_res_decl_decode_na(_z_res_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); - -int8_t _z_pub_decl_encode(_z_wbuf_t *buf, uint8_t header, const _z_pub_decl_t *dcl); -int8_t _z_pub_decl_decode(_z_pub_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); -int8_t _z_pub_decl_decode_na(_z_pub_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); - -int8_t _z_sub_decl_encode(_z_wbuf_t *buf, uint8_t header, const _z_sub_decl_t *dcl); -int8_t _z_sub_decl_decode(_z_sub_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); -int8_t _z_sub_decl_decode_na(_z_sub_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); - -int8_t _z_qle_decl_encode(_z_wbuf_t *buf, uint8_t header, const _z_qle_decl_t *dcl); -int8_t _z_qle_decl_decode(_z_qle_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); -int8_t _z_qle_decl_decode_na(_z_qle_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); - -int8_t _z_forget_res_decl_encode(_z_wbuf_t *buf, const _z_forget_res_decl_t *dcl); -int8_t _z_forget_res_decl_decode(_z_forget_res_decl_t *dcl, _z_zbuf_t *buf); -int8_t _z_forget_res_decl_decode_na(_z_forget_res_decl_t *dcl, _z_zbuf_t *buf); - -int8_t _z_forget_pub_decl_encode(_z_wbuf_t *buf, uint8_t header, const _z_forget_pub_decl_t *dcl); -int8_t _z_forget_pub_decl_decode(_z_forget_pub_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); -int8_t _z_forget_pub_decl_decode_na(_z_forget_pub_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); - -int8_t _z_forget_sub_decl_encode(_z_wbuf_t *buf, uint8_t header, const _z_forget_sub_decl_t *dcl); -int8_t _z_forget_sub_decl_decode(_z_forget_sub_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); -int8_t _z_forget_sub_decl_decode_na(_z_forget_sub_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); - -int8_t _z_forget_qle_decl_encode(_z_wbuf_t *buf, uint8_t header, const _z_forget_qle_decl_t *dcl); -int8_t _z_forget_qle_decl_decode(_z_forget_qle_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); -int8_t _z_forget_qle_decl_decode_na(_z_forget_qle_decl_t *dcl, _z_zbuf_t *buf, uint8_t header); - -int8_t _z_reply_context_encode(_z_wbuf_t *buf, const _z_reply_context_t *rc); -int8_t _z_reply_context_decode(_z_reply_context_t **rc, _z_zbuf_t *buf, uint8_t header); -int8_t _z_reply_context_decode_na(_z_reply_context_t *rc, _z_zbuf_t *buf, uint8_t header); - -int8_t _z_data_encode(_z_wbuf_t *wbf, uint8_t header, const _z_msg_data_t *msg); -int8_t _z_data_decode_na(_z_msg_data_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_data_decode(_z_msg_data_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_pull_encode(_z_wbuf_t *wbf, uint8_t header, const _z_msg_pull_t *msg); -int8_t _z_pull_decode_na(_z_msg_pull_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_pull_decode(_z_msg_pull_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_query_encode(_z_wbuf_t *wbf, uint8_t header, const _z_msg_query_t *msg); -int8_t _z_query_decode_na(_z_msg_query_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_query_decode(_z_msg_query_t *msg, _z_zbuf_t *zbf, uint8_t header); - -// ------------------ Network Message ------------------ -int8_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *msg); -int8_t _z_declare_decode(_z_n_msg_declare_t *msg, _z_zbuf_t *zbf); -int8_t _z_declare_decode_na(_z_n_msg_declare_t *msg, _z_zbuf_t *zbf); - -int8_t _z_push_encode(_z_wbuf_t *wbf, uint8_t header, const _z_n_msg_push_t *msg); -int8_t _z_push_decode(_z_n_msg_push_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_request_encode(_z_wbuf_t *wbf, uint8_t header, const _z_n_msg_request_t *msg); -int8_t _z_request_decode(_z_n_msg_request_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_request_decode_na(_z_n_msg_request_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_response_encode(_z_wbuf_t *wbf, uint8_t header, const _z_n_msg_response_t *msg); -int8_t _z_response_decode(_z_n_msg_response_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_response_decode_na(_z_n_msg_response_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_response_final_encode(_z_wbuf_t *wbf, uint8_t header, const _z_n_msg_response_final_t *msg); -int8_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_response_final_decode_na(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, uint8_t header); - -// ------------------ Transport Message ------------------ -int8_t _z_join_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_join_t *msg); -int8_t _z_join_decode(_z_t_msg_join_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_init_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_init_t *msg); -int8_t _z_init_decode(_z_t_msg_init_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_open_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_open_t *msg); -int8_t _z_open_decode(_z_t_msg_open_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_close_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_close_t *msg); -int8_t _z_close_decode(_z_t_msg_close_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_keep_alive_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_keep_alive_t *msg); -int8_t _z_keep_alive_decode(_z_t_msg_keep_alive_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_frame_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_frame_t *msg); -int8_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_fragment_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_fragment_t *msg); -int8_t _z_fragment_decode(_z_t_msg_fragment_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_extensions_encode(_z_wbuf_t *wbf, uint8_t header, const _z_msg_ext_vec_t *v_ext); -int8_t _z_extensions_decode(_z_msg_ext_vec_t *v_ext, _z_zbuf_t *zbf, uint8_t header); - -// ------------------ Discovery Message ------------------ -int8_t _z_scout_encode(_z_wbuf_t *wbf, uint8_t header, const _z_s_msg_scout_t *msg); -int8_t _z_scout_decode_na(_z_s_msg_scout_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_scout_decode(_z_s_msg_scout_t *msg, _z_zbuf_t *zbf, uint8_t header); - -int8_t _z_hello_encode(_z_wbuf_t *wbf, uint8_t header, const _z_s_msg_hello_t *msg); -int8_t _z_hello_decode_na(_z_s_msg_hello_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_hello_decode(_z_s_msg_hello_t *msg, _z_zbuf_t *zbf, uint8_t header); - -#endif /* ZENOH_PICO_TEST_H */ diff --git a/include/zenoh-pico/transport/link/rx.h b/include/zenoh-pico/transport/link/rx.h index b1c5f7c6a..f4c428a64 100644 --- a/include/zenoh-pico/transport/link/rx.h +++ b/include/zenoh-pico/transport/link/rx.h @@ -16,7 +16,6 @@ #define ZENOH_PICO_TRANSPORT_LINK_RX_H #include "zenoh-pico/link/link.h" -#include "zenoh-pico/protocol/msgcodec.h" #include "zenoh-pico/transport/transport.h" /*------------------ Transmission and Reception helpers ------------------*/ diff --git a/src/protocol/codec/message.c b/src/protocol/codec/message.c index 68474cbac..141294d67 100644 --- a/src/protocol/codec/message.c +++ b/src/protocol/codec/message.c @@ -32,7 +32,6 @@ #include "zenoh-pico/protocol/ext.h" #include "zenoh-pico/protocol/iobuf.h" #include "zenoh-pico/protocol/keyexpr.h" -#include "zenoh-pico/protocol/msgcodec.h" #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/result.h" diff --git a/src/protocol/codec/network.c b/src/protocol/codec/network.c index a522af3d7..cac062fc5 100644 --- a/src/protocol/codec/network.c +++ b/src/protocol/codec/network.c @@ -31,7 +31,6 @@ #include "zenoh-pico/protocol/definitions/message.h" #include "zenoh-pico/protocol/ext.h" #include "zenoh-pico/protocol/iobuf.h" -#include "zenoh-pico/protocol/msgcodec.h" #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/result.h" @@ -380,6 +379,7 @@ int8_t _z_response_decode(_z_n_msg_response_t *msg, _z_zbuf_t *zbf, uint8_t head break; } default: { + _Z_ERROR("Unknown N_MID: %d\n", _Z_MID(inner_header)); ret = _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; } } diff --git a/src/protocol/codec/transport.c b/src/protocol/codec/transport.c index 75f0b0aba..9c7281b2f 100644 --- a/src/protocol/codec/transport.c +++ b/src/protocol/codec/transport.c @@ -12,16 +12,18 @@ // ZettaScale Zenoh Team, // +#include "zenoh-pico/protocol/definitions/transport.h" + #include #include #include "zenoh-pico/protocol/codec/core.h" #include "zenoh-pico/protocol/codec/ext.h" #include "zenoh-pico/protocol/codec/network.h" +#include "zenoh-pico/protocol/codec/transport.h" #include "zenoh-pico/protocol/definitions/core.h" #include "zenoh-pico/protocol/ext.h" #include "zenoh-pico/protocol/iobuf.h" -#include "zenoh-pico/protocol/msgcodec.h" #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/result.h" /*------------------ Join Message ------------------*/ @@ -94,6 +96,7 @@ int8_t _z_join_decode_ext(_z_msg_ext_t *extension, void *ctx) { int8_t _z_join_decode(_z_t_msg_join_t *msg, _z_zbuf_t *zbf, uint8_t header) { _Z_DEBUG("Decoding _Z_MID_T_JOIN\n"); int8_t ret = _Z_RES_OK; + *msg = (_z_t_msg_join_t){0}; ret |= _z_uint8_decode(&msg->_version, zbf); @@ -172,6 +175,7 @@ int8_t _z_init_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_init_t *msg int8_t _z_init_decode(_z_t_msg_init_t *msg, _z_zbuf_t *zbf, uint8_t header) { _Z_DEBUG("Decoding _Z_MID_T_INIT\n"); + *msg = (_z_t_msg_init_t){0}; int8_t ret = _Z_RES_OK; ret |= _z_uint8_decode(&msg->_version, zbf); @@ -238,6 +242,7 @@ int8_t _z_open_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_open_t *msg int8_t _z_open_decode(_z_t_msg_open_t *msg, _z_zbuf_t *zbf, uint8_t header) { _Z_DEBUG("Decoding _Z_MID_T_OPEN\n"); int8_t ret = _Z_RES_OK; + *msg = (_z_t_msg_open_t){0}; ret |= _z_zint_decode(&msg->_lease, zbf); if ((ret == _Z_RES_OK) && (_Z_HAS_FLAG(header, _Z_FLAG_T_OPEN_T) == true)) { @@ -275,6 +280,7 @@ int8_t _z_close_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_close_t *m int8_t _z_close_decode(_z_t_msg_close_t *msg, _z_zbuf_t *zbf, uint8_t header) { (void)(header); int8_t ret = _Z_RES_OK; + *msg = (_z_t_msg_close_t){0}; _Z_DEBUG("Decoding _Z_MID_T_CLOSE\n"); ret |= _z_uint8_decode(&msg->_reason, zbf); @@ -298,6 +304,7 @@ int8_t _z_keep_alive_decode(_z_t_msg_keep_alive_t *msg, _z_zbuf_t *zbf, uint8_t (void)(msg); (void)(zbf); (void)(header); + *msg = (_z_t_msg_keep_alive_t){0}; int8_t ret = _Z_RES_OK; _Z_DEBUG("Decoding _Z_MID_T_KEEP_ALIVE\n"); @@ -331,6 +338,7 @@ int8_t _z_frame_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_frame_t *m int8_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header) { int8_t ret = _Z_RES_OK; + *msg = (_z_t_msg_frame_t){0}; ret |= _z_zint_decode(&msg->_sn, zbf); if ((ret == _Z_RES_OK) && (_Z_HAS_FLAG(header, _Z_FLAG_T_Z) == true)) { @@ -381,6 +389,8 @@ int8_t _z_fragment_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_fragmen int8_t _z_fragment_decode(_z_t_msg_fragment_t *msg, _z_zbuf_t *zbf, uint8_t header) { int8_t ret = _Z_RES_OK; + *msg = (_z_t_msg_fragment_t){0}; + _Z_DEBUG("Decoding _Z_TRANSPORT_FRAGMENT\n"); ret |= _z_zint_decode(&msg->_sn, zbf); @@ -424,8 +434,6 @@ int8_t _z_extensions_decode(_z_msg_ext_vec_t *v_ext, _z_zbuf_t *zbf, uint8_t hea int8_t _z_transport_message_encode(_z_wbuf_t *wbf, const _z_transport_message_t *msg) { int8_t ret = _Z_RES_OK; - // Encode the decorators if present - uint8_t header = msg->_header; _Z_RETURN_IF_ERR(_z_wbuf_write(wbf, header)) diff --git a/src/session/rx.c b/src/session/rx.c index 10e16b06d..b865b1785 100644 --- a/src/session/rx.c +++ b/src/session/rx.c @@ -21,7 +21,6 @@ #include "zenoh-pico/protocol/definitions/message.h" #include "zenoh-pico/protocol/definitions/network.h" #include "zenoh-pico/protocol/keyexpr.h" -#include "zenoh-pico/protocol/msgcodec.h" #include "zenoh-pico/session/query.h" #include "zenoh-pico/session/queryable.h" #include "zenoh-pico/session/resource.h" diff --git a/src/transport/unicast/link/tx.c b/src/transport/unicast/link/tx.c index 4e56517bd..2482ec2b0 100644 --- a/src/transport/unicast/link/tx.c +++ b/src/transport/unicast/link/tx.c @@ -18,7 +18,6 @@ #include "zenoh-pico/protocol/codec/network.h" #include "zenoh-pico/protocol/codec/transport.h" #include "zenoh-pico/protocol/iobuf.h" -#include "zenoh-pico/protocol/msgcodec.h" #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index f3523d21f..aa9d640ee 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -190,7 +190,7 @@ _z_id_t gen_zid(void) { for (uint8_t i = 0; i < len; i++) { uint8_t byte = gen_uint8(); id.id[i] = byte; - hash ^= byte; + hash ^= i * byte; } id.id[0] = hash; return id; @@ -1683,6 +1683,99 @@ void frame_message(void) { _z_wbuf_clear(&wbf); } +_z_transport_message_t gen_fragment(void) { + return _z_t_msg_make_fragment(gen_uint(), gen_bytes(gen_uint8()), gen_bool(), gen_bool()); +} +void assert_eq_fragment(const _z_t_msg_fragment_t *left, const _z_t_msg_fragment_t *right) { + assert(left->_sn == right->_sn); + assert_eq_bytes(&left->_payload, &right->_payload); +} +void fragment_message(void) { + printf("\n>> fragment message\n"); + __auto_type wbf = gen_wbuf(UINT16_MAX); + __auto_type expected = gen_fragment(); + assert(_z_fragment_encode(&wbf, expected._header, &expected._body._fragment) == _Z_RES_OK); + _z_t_msg_fragment_t decoded; + __auto_type zbf = _z_wbuf_to_zbuf(&wbf); + int8_t ret = _z_fragment_decode(&decoded, &zbf, expected._header); + assert(_Z_RES_OK == ret); + assert_eq_fragment(&expected._body._fragment, &decoded); + _z_t_msg_fragment_clear(&decoded); + _z_t_msg_clear(&expected); + _z_zbuf_clear(&zbf); + _z_wbuf_clear(&wbf); +} + +_z_transport_message_t gen_transport(void) { + switch (gen_uint8() % 7) { + case 0: { + return gen_join(); + }; + case 1: { + return gen_init(); + }; + case 2: { + return gen_open(); + }; + case 3: { + return gen_close(); + }; + case 4: { + return gen_keep_alive(); + }; + case 5: { + return gen_frame(); + }; + case 6: { + return gen_fragment(); + }; + } + assert(false); +} +void assert_eq_transport(const _z_transport_message_t *left, const _z_transport_message_t *right) { + assert(left->_header == right->_header); + switch (_Z_MID(left->_header)) { + case _Z_MID_T_JOIN: { + assert_eq_join(&left->_body._join, &right->_body._join); + } break; + case _Z_MID_T_CLOSE: { + assert_eq_close(&left->_body._close, &right->_body._close); + } break; + case _Z_MID_T_INIT: { + assert_eq_init(&left->_body._init, &right->_body._init); + } break; + case _Z_MID_T_OPEN: { + assert_eq_open(&left->_body._open, &right->_body._open); + } break; + case _Z_MID_T_KEEP_ALIVE: { + assert_eq_keep_alive(&left->_body._keep_alive, &right->_body._keep_alive); + } break; + case _Z_MID_T_FRAME: { + assert_eq_frame(&left->_body._frame, &right->_body._frame); + } break; + case _Z_MID_T_FRAGMENT: { + assert_eq_fragment(&left->_body._fragment, &right->_body._fragment); + } break; + default: + assert(false); + } +} +void transport_message(void) { + printf("\n>> transport message\n"); + __auto_type wbf = gen_wbuf(UINT16_MAX); + __auto_type expected = gen_transport(); + assert(_z_transport_message_encode(&wbf, &expected) == _Z_RES_OK); + _z_transport_message_t decoded; + __auto_type zbf = _z_wbuf_to_zbuf(&wbf); + int8_t ret = _z_transport_message_decode(&decoded, &zbf); + assert(_Z_RES_OK == ret); + assert_eq_transport(&expected, &decoded); + _z_t_msg_clear(&decoded); + _z_t_msg_clear(&expected); + _z_zbuf_clear(&zbf); + _z_wbuf_clear(&wbf); +} + /*=============================*/ /* Main */ /*=============================*/ @@ -1727,8 +1820,8 @@ int main(void) { close_message(); keep_alive_message(); frame_message(); - // fragment_message(); - // transport_message(); + fragment_message(); + transport_message(); // batch(); // fragmentation();