Skip to content

Commit

Permalink
Remove Put/Del from ResponseBody
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Mar 19, 2024
1 parent 61683e4 commit 6125424
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 80 deletions.
6 changes: 3 additions & 3 deletions include/zenoh-pico/protocol/codec/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "zenoh-pico/protocol/definitions/network.h"
#include "zenoh-pico/protocol/iobuf.h"

int8_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb);
int8_t _z_push_body_decode(_z_push_body_t *body, _z_zbuf_t *zbf, uint8_t header);

int8_t _z_query_encode(_z_wbuf_t *wbf, const _z_msg_query_t *query);
int8_t _z_query_decode(_z_msg_query_t *query, _z_zbuf_t *zbf, uint8_t header);

Expand All @@ -27,9 +30,6 @@ int8_t _z_reply_decode(_z_msg_reply_t *reply, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_err_encode(_z_wbuf_t *wbf, const _z_msg_err_t *err);
int8_t _z_err_decode(_z_msg_err_t *err, _z_zbuf_t *zbf, uint8_t header);

int8_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb);
int8_t _z_push_body_decode(_z_push_body_t *body, _z_zbuf_t *zbf, uint8_t header);

int8_t _z_put_encode(_z_wbuf_t *wbf, const _z_msg_put_t *put);
int8_t _z_put_decode(_z_msg_put_t *put, _z_zbuf_t *zbf, uint8_t header);

Expand Down
4 changes: 0 additions & 4 deletions include/zenoh-pico/protocol/definitions/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,10 @@ typedef struct {
enum {
_Z_RESPONSE_BODY_REPLY,
_Z_RESPONSE_BODY_ERR,
_Z_RESPONSE_BODY_PUT,
_Z_RESPONSE_BODY_DEL,
} _tag;
union {
_z_msg_reply_t _reply;
_z_msg_err_t _err;
_z_msg_put_t _put;
_z_msg_del_t _del;
} _body;
} _z_n_msg_response_t;
void _z_n_msg_response_clear(_z_n_msg_response_t *msg);
Expand Down
18 changes: 0 additions & 18 deletions src/protocol/codec/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,6 @@ int8_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg) {
_Z_RETURN_IF_ERR(_z_err_encode(wbf, &msg->_body._err));
break;
}
case _Z_RESPONSE_BODY_PUT: {
_Z_RETURN_IF_ERR(_z_put_encode(wbf, &msg->_body._put));
break;
}
case _Z_RESPONSE_BODY_DEL: {
_Z_RETURN_IF_ERR(_z_del_encode(wbf, &msg->_body._del));
break;
}
}

return ret;
Expand Down Expand Up @@ -368,16 +360,6 @@ int8_t _z_response_decode(_z_n_msg_response_t *msg, _z_zbuf_t *zbf, uint8_t head
ret = _z_err_decode(&msg->_body._err, zbf, inner_header);
break;
}
case _Z_MID_Z_PUT: {
msg->_tag = _Z_RESPONSE_BODY_PUT;
ret = _z_put_decode(&msg->_body._put, zbf, inner_header);
break;
}
case _Z_MID_Z_DEL: {
msg->_tag = _Z_RESPONSE_BODY_DEL;
ret = _z_del_decode(&msg->_body._del, zbf, inner_header);
break;
}
default: {
_Z_ERROR("Unknown N_MID: %d", _Z_MID(inner_header));
ret = _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
Expand Down
7 changes: 0 additions & 7 deletions src/protocol/definitions/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ void _z_n_msg_response_clear(_z_n_msg_response_t *msg) {
_z_msg_err_clear(&msg->_body._err);
break;
}
case _Z_RESPONSE_BODY_PUT: {
_z_msg_put_clear(&msg->_body._put);
break;
}
case _Z_RESPONSE_BODY_DEL: {
break;
}
}
}

Expand Down
27 changes: 0 additions & 27 deletions src/session/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,33 +152,6 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint
_Z_ERROR("Received Err for query %zu: message=%.*s", response._request_id, (int)payload.len,
payload.start);
} break;
case _Z_RESPONSE_BODY_PUT: {
_z_msg_put_t put = response._body._put;
#if Z_FEATURE_SUBSCRIPTION == 1
#if Z_FEATURE_ATTACHMENT == 1
z_attachment_t att = _z_encoded_as_attachment(&put._attachment);
#endif
ret = _z_trigger_subscriptions(zn, response._key, put._payload, put._encoding, Z_SAMPLE_KIND_PUT,
put._commons._timestamp
#if Z_FEATURE_ATTACHMENT == 1
,
att
#endif
);
#endif
} break;
case _Z_RESPONSE_BODY_DEL: {
_z_msg_del_t del = response._body._del;
#if Z_FEATURE_SUBSCRIPTION == 1
ret = _z_trigger_subscriptions(zn, response._key, _z_bytes_empty(), z_encoding_default(),
Z_SAMPLE_KIND_DELETE, del._commons._timestamp
#if Z_FEATURE_ATTACHMENT == 1
,
z_attachment_null()
#endif
);
#endif
} break;
}
} break;
case _Z_N_RESPONSE_FINAL: {
Expand Down
25 changes: 4 additions & 21 deletions tests/z_msgcodec_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,26 +1283,16 @@ _z_n_msg_response_t gen_response(void) {
._ext_timestamp = gen_bool() ? gen_timestamp() : _z_timestamp_null(),
._ext_responder = {._eid = gen_uint16(), ._zid = gen_zid()},
};
switch (gen_uint() % 3) {
switch (gen_uint() % 2) {
case 0: {
ret._tag = _Z_RESPONSE_BODY_ERR;
ret._body._err = gen_err();
} break;
case 1: {
case 1:
default: {
ret._tag = _Z_RESPONSE_BODY_REPLY;
ret._body._reply = gen_reply();
} break;
case 2:
default: {
_z_push_body_t body = gen_push_body();
if (body._is_put) {
ret._tag = _Z_RESPONSE_BODY_PUT;
ret._body._put = body._body._put;
} else {
ret._tag = _Z_RESPONSE_BODY_DEL;
ret._body._del = body._body._del;
}
} break;
}
return ret;
}
Expand All @@ -1321,14 +1311,7 @@ void assert_eq_response(const _z_n_msg_response_t *left, const _z_n_msg_response
} break;
case _Z_RESPONSE_BODY_ERR: {
assert_eq_err(&left->_body._err, &right->_body._err);
} break;
case _Z_RESPONSE_BODY_PUT: {
assert_eq_push_body(&(_z_push_body_t){._is_put = true, ._body._put = left->_body._put},
&(_z_push_body_t){._is_put = true, ._body._put = right->_body._put});
} break;
case _Z_RESPONSE_BODY_DEL: {
assert_eq_push_body(&(_z_push_body_t){._is_put = false, ._body._del = left->_body._del},
&(_z_push_body_t){._is_put = false, ._body._del = right->_body._del});

} break;
}
}
Expand Down

0 comments on commit 6125424

Please sign in to comment.