From 1c4942f419cadb58601941cbd5dbc711ce4fef7d Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Sat, 2 Nov 2024 22:13:56 +0100 Subject: [PATCH] feat: add config value for initial frame size evaluation --- include/zenoh-pico/config.h | 5 +++++ include/zenoh-pico/config.h.in | 5 +++++ src/protocol/codec/transport.c | 4 ++-- src/protocol/definitions/message.c | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index bac250c4a..c08bbd56a 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -177,6 +177,11 @@ */ #define Z_GET_TIMEOUT_DEFAULT 10000 +/** + * Average size of a frame message (bytes). Used to evaluate initial decoding frame size. + */ +#define Z_CONFIG_FRAME_AVG_MSG_SIZE 16 + /** * Default "nop" instruction */ diff --git a/include/zenoh-pico/config.h.in b/include/zenoh-pico/config.h.in index 6461d3d97..4eff5ab2f 100644 --- a/include/zenoh-pico/config.h.in +++ b/include/zenoh-pico/config.h.in @@ -177,6 +177,11 @@ */ #define Z_GET_TIMEOUT_DEFAULT 10000 +/** + * Average size of a frame message (bytes). Used to evaluate initial decoding frame size. + */ +#define Z_CONFIG_FRAME_AVG_MSG_SIZE 16 + /** * Default "nop" instruction */ diff --git a/src/protocol/codec/transport.c b/src/protocol/codec/transport.c index 9f5daba26..5eb267404 100644 --- a/src/protocol/codec/transport.c +++ b/src/protocol/codec/transport.c @@ -28,8 +28,9 @@ #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/result.h" +#define _Z_FRAME_VEC_BASE_SIZE 16 // Abritrary small value #define _Z_FRAME_VEC_SIZE_FROM_ZBUF_LEN(len) \ - 16 + (len) / 32 // Arbritrary values to approximate number of messages in frame + _Z_FRAME_VEC_BASE_SIZE + (len) / Z_CONFIG_FRAME_AVG_MSG_SIZE // Approximate number of messages in frame uint8_t _z_whatami_to_uint8(z_whatami_t whatami) { return (whatami >> 1) & 0x03; // get set bit index; only first 3 bits can be set @@ -361,7 +362,6 @@ z_result_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header } // Create message vector size_t var_size = _Z_FRAME_VEC_SIZE_FROM_ZBUF_LEN(_z_zbuf_len(zbf)); - // printf("Pouet %ld\n", var_size); msg->_messages = _z_network_message_svec_make(var_size); if (msg->_messages._capacity == 0) { return _Z_ERR_SYSTEM_OUT_OF_MEMORY; diff --git a/src/protocol/definitions/message.c b/src/protocol/definitions/message.c index 3001b3372..0c3058e0a 100644 --- a/src/protocol/definitions/message.c +++ b/src/protocol/definitions/message.c @@ -23,6 +23,7 @@ void _z_msg_reply_clear(_z_msg_reply_t *msg) { _z_push_body_clear(&msg->_body); } void _z_msg_put_clear(_z_msg_put_t *msg) { + // TODO: systematically move everything so there's nothing to clear _z_bytes_drop(&msg->_payload); _z_bytes_drop(&msg->_attachment); _z_encoding_clear(&msg->_encoding);