Skip to content

Commit

Permalink
fix: rename start/stop marker to first/drop
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo committed Dec 4, 2024
1 parent 3736054 commit 218019a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions include/zenoh-pico/protocol/definitions/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ extern "C" {
/// if >= 1, then fragmentation start/stop marker
#define _Z_NO_PATCH 0x00
#define _Z_CURRENT_PATCH 0x01
#define _Z_PATCH_HAS_FRAGMENT_START_STOP(patch) (patch >= 1)
#define _Z_PATCH_HAS_FRAGMENT_MARKERS(patch) (patch >= 1)

/*=============================*/
/* Transport Messages */
Expand Down Expand Up @@ -494,8 +494,8 @@ void _z_t_msg_frame_clear(_z_t_msg_frame_t *msg);
typedef struct {
_z_slice_t _payload;
_z_zint_t _sn;
bool start;
bool stop;
bool first;
bool drop;
} _z_t_msg_fragment_t;
void _z_t_msg_fragment_clear(_z_t_msg_fragment_t *msg);

Expand Down Expand Up @@ -531,9 +531,9 @@ _z_transport_message_t _z_t_msg_make_frame(_z_zint_t sn, _z_network_message_vec_
z_reliability_t reliability);
_z_transport_message_t _z_t_msg_make_frame_header(_z_zint_t sn, z_reliability_t reliability);
_z_transport_message_t _z_t_msg_make_fragment_header(_z_zint_t sn, z_reliability_t reliability, bool is_last,
bool start, bool stop);
bool first, bool drop);
_z_transport_message_t _z_t_msg_make_fragment(_z_zint_t sn, _z_slice_t messages, z_reliability_t reliability,
bool is_last, bool start, bool stop);
bool is_last, bool first, bool drop);

/*------------------ Copy ------------------*/
void _z_t_msg_copy(_z_transport_message_t *clone, _z_transport_message_t *msg);
Expand Down
4 changes: 2 additions & 2 deletions include/zenoh-pico/protocol/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ extern "C" {
#define _Z_MSG_EXT_ID_JOIN_QOS (0x01 | _Z_MSG_EXT_FLAG_M | _Z_MSG_EXT_ENC_ZBUF)
#define _Z_MSG_EXT_ID_JOIN_PATCH (0x07 | _Z_MSG_EXT_ENC_ZINT)
#define _Z_MSG_EXT_ID_INIT_PATCH (0x07 | _Z_MSG_EXT_ENC_ZINT)
#define _Z_MSG_EXT_ID_FRAGMENT_START (0x02 | _Z_MSG_EXT_ENC_UNIT)
#define _Z_MSG_EXT_ID_FRAGMENT_STOP (0x03 | _Z_MSG_EXT_ENC_UNIT)
#define _Z_MSG_EXT_ID_FRAGMENT_FIRST (0x02 | _Z_MSG_EXT_ENC_UNIT)
#define _Z_MSG_EXT_ID_FRAGMENT_DROP (0x03 | _Z_MSG_EXT_ENC_UNIT)

/*=============================*/
/* Extension Encodings */
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/transport/common/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void __unsafe_z_finalize_wbuf(_z_wbuf_t *buf, uint8_t link_flow_capability);
/*This function is unsafe because it operates in potentially concurrent
data.*Make sure that the following mutexes are locked before calling this function : *-ztu->mutex_tx */
z_result_t __unsafe_z_serialize_zenoh_fragment(_z_wbuf_t *dst, _z_wbuf_t *src, z_reliability_t reliability, size_t sn,
bool start);
bool first);

/*------------------ Transmission and Reception helpers ------------------*/
z_result_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg);
Expand Down
20 changes: 10 additions & 10 deletions src/protocol/codec/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,17 +434,17 @@ z_result_t _z_fragment_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_fra
z_result_t ret = _Z_RES_OK;
_Z_DEBUG("Encoding _Z_TRANSPORT_FRAGMENT");
_Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_sn))
if (msg->start == true) {
if (msg->first == true) {
if (_Z_HAS_FLAG(header, _Z_FLAG_T_Z) == true) {
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ID_FRAGMENT_START | _Z_MSG_EXT_MORE(msg->stop)));
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ID_FRAGMENT_FIRST | _Z_MSG_EXT_MORE(msg->drop)));
} else {
_Z_DEBUG("Attempted to serialize Start extension, but the header extension flag was unset");
ret |= _Z_ERR_MESSAGE_SERIALIZATION_FAILED;
}
}
if (msg->stop == true) {
if (msg->drop == true) {
if (_Z_HAS_FLAG(header, _Z_FLAG_T_Z) == true) {
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ID_FRAGMENT_STOP));
_Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ID_FRAGMENT_DROP));
} else {
_Z_DEBUG("Attempted to serialize Stop extension, but the header extension flag was unset");
ret |= _Z_ERR_MESSAGE_SERIALIZATION_FAILED;
Expand All @@ -460,10 +460,10 @@ z_result_t _z_fragment_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_fra
z_result_t _z_fragment_decode_ext(_z_msg_ext_t *extension, void *ctx) {
z_result_t ret = _Z_RES_OK;
_z_t_msg_fragment_t *msg = (_z_t_msg_fragment_t *)ctx;
if (_Z_EXT_FULL_ID(extension->_header) == _Z_MSG_EXT_ID_FRAGMENT_START) {
msg->start = true;
} else if (_Z_EXT_FULL_ID(extension->_header) == _Z_MSG_EXT_ID_FRAGMENT_STOP) {
msg->stop = true;
if (_Z_EXT_FULL_ID(extension->_header) == _Z_MSG_EXT_ID_FRAGMENT_FIRST) {
msg->first = true;
} else if (_Z_EXT_FULL_ID(extension->_header) == _Z_MSG_EXT_ID_FRAGMENT_DROP) {
msg->drop = true;
} else if (_Z_MSG_EXT_IS_MANDATORY(extension->_header)) {
ret = _Z_ERR_MESSAGE_EXTENSION_MANDATORY_AND_UNKNOWN;
}
Expand All @@ -477,8 +477,8 @@ z_result_t _z_fragment_decode(_z_t_msg_fragment_t *msg, _z_zbuf_t *zbf, uint8_t
_Z_DEBUG("Decoding _Z_TRANSPORT_FRAGMENT");
ret |= _z_zsize_decode(&msg->_sn, zbf);

msg->start = false;
msg->stop = false;
msg->first = false;
msg->drop = false;
if ((ret == _Z_RES_OK) && (_Z_HAS_FLAG(header, _Z_FLAG_T_Z) == true)) {
ret |= _z_msg_ext_decode_iter(zbf, _z_fragment_decode_ext, msg);
}
Expand Down
16 changes: 8 additions & 8 deletions src/protocol/definitions/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ _z_transport_message_t _z_t_msg_make_frame_header(_z_zint_t sn, z_reliability_t

/*------------------ Fragment Message ------------------*/
_z_transport_message_t _z_t_msg_make_fragment_header(_z_zint_t sn, z_reliability_t reliability, bool is_last,
bool start, bool stop) {
return _z_t_msg_make_fragment(sn, _z_slice_empty(), reliability, is_last, start, stop);
bool first, bool drop) {
return _z_t_msg_make_fragment(sn, _z_slice_empty(), reliability, is_last, first, drop);
}
_z_transport_message_t _z_t_msg_make_fragment(_z_zint_t sn, _z_slice_t payload, z_reliability_t reliability,
bool is_last, bool start, bool stop) {
bool is_last, bool first, bool drop) {
_z_transport_message_t msg;
msg._header = _Z_MID_T_FRAGMENT;
if (is_last == false) {
Expand All @@ -296,20 +296,20 @@ _z_transport_message_t _z_t_msg_make_fragment(_z_zint_t sn, _z_slice_t payload,

msg._body._fragment._sn = sn;
msg._body._fragment._payload = payload;
if (start == true || stop == true) {
if (first == true || drop == true) {
_Z_SET_FLAG(msg._header, _Z_FLAG_T_Z);
}
msg._body._fragment.start = start;
msg._body._fragment.stop = stop;
msg._body._fragment.first = first;
msg._body._fragment.drop = drop;

return msg;
}

void _z_t_msg_copy_fragment(_z_t_msg_fragment_t *clone, _z_t_msg_fragment_t *msg) {
clone->_payload = msg->_payload;
_z_slice_copy(&clone->_payload, &msg->_payload);
clone->start = msg->start;
clone->stop = msg->stop;
clone->first = msg->first;
clone->drop = msg->drop;
}

void _z_t_msg_copy_join(_z_t_msg_join_t *clone, _z_t_msg_join_t *msg) {
Expand Down
4 changes: 2 additions & 2 deletions src/transport/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ z_result_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t
}

z_result_t __unsafe_z_serialize_zenoh_fragment(_z_wbuf_t *dst, _z_wbuf_t *src, z_reliability_t reliability, size_t sn,
bool start) {
bool first) {
z_result_t ret = _Z_RES_OK;

// Assume first that this is not the final fragment
Expand All @@ -145,7 +145,7 @@ z_result_t __unsafe_z_serialize_zenoh_fragment(_z_wbuf_t *dst, _z_wbuf_t *src, z
size_t w_pos = _z_wbuf_get_wpos(dst); // Mark the buffer for the writing operation

_z_transport_message_t f_hdr =
_z_t_msg_make_fragment_header(sn, reliability == Z_RELIABILITY_RELIABLE, is_final, start, false);
_z_t_msg_make_fragment_header(sn, reliability == Z_RELIABILITY_RELIABLE, is_final, first, false);
ret = _z_transport_message_encode(dst, &f_hdr); // Encode the frame header
if (ret == _Z_RES_OK) {
size_t space_left = _z_wbuf_space_left(dst);
Expand Down
8 changes: 4 additions & 4 deletions src/transport/multicast/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ z_result_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm,
}
}
// Handle fragment markers
if (_Z_PATCH_HAS_FRAGMENT_START_STOP(entry->_patch)) {
if (t_msg->_body._fragment.start == true) {
if (_Z_PATCH_HAS_FRAGMENT_MARKERS(entry->_patch)) {
if (t_msg->_body._fragment.first == true) {
_z_wbuf_clear(dbuf);
} else if (_z_wbuf_len(dbuf) == 0) {
_Z_DEBUG("First fragment received without the start marker");
_Z_DEBUG("First fragment received without the first marker");
break;
}
if (t_msg->_body._fragment.stop == true) {
if (t_msg->_body._fragment.drop == true) {
_z_wbuf_clear(dbuf);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/transport/unicast/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ z_result_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_t
}
}
// Handle fragment markers
if (_Z_PATCH_HAS_FRAGMENT_START_STOP(ztu->_patch)) {
if (t_msg->_body._fragment.start == true) {
if (_Z_PATCH_HAS_FRAGMENT_MARKERS(ztu->_patch)) {
if (t_msg->_body._fragment.first == true) {
_z_wbuf_clear(dbuf);
} else if (_z_wbuf_len(dbuf) == 0) {
_Z_DEBUG("First fragment received without the start marker");
break;
}
if (t_msg->_body._fragment.stop == true) {
if (t_msg->_body._fragment.drop == true) {
_z_wbuf_clear(dbuf);
break;
}
Expand Down

0 comments on commit 218019a

Please sign in to comment.