Skip to content

Commit

Permalink
feat: add config value for initial frame size evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Nov 2, 2024
1 parent 13eba0e commit 1c4942f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 5 additions & 0 deletions include/zenoh-pico/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/codec/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/protocol/definitions/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1c4942f

Please sign in to comment.