Skip to content

Commit

Permalink
move _z_decl_fix_mapping out of line so bad compilers might understan…
Browse files Browse the repository at this point in the history
…d it better?
  • Loading branch information
p-avital committed Aug 7, 2023
1 parent e002243 commit f10b806
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 42 deletions.
34 changes: 1 addition & 33 deletions include/zenoh-pico/protocol/definitions/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,39 +123,7 @@ typedef struct {
} _body;
} _z_declaration_t;
void _z_declaration_clear(_z_declaration_t* decl);
static inline void _z_decl_fix_mapping(_z_declaration_t* msg, uint16_t mapping) {
switch (msg->_tag) {
case _Z_DECL_KEXPR: {
_z_keyexpr_fix_mapping(&msg->_body._decl_kexpr._keyexpr, mapping);
} break;
case _Z_DECL_SUBSCRIBER: {
_z_keyexpr_fix_mapping(&msg->_body._decl_subscriber._keyexpr, mapping);
} break;
case _Z_UNDECL_SUBSCRIBER: {
_z_keyexpr_fix_mapping(&msg->_body._undecl_subscriber._ext_keyexpr, mapping);
} break;
case _Z_DECL_QUERYABLE: {
_z_keyexpr_fix_mapping(&msg->_body._decl_queryable._keyexpr, mapping);
} break;
case _Z_UNDECL_QUERYABLE: {
_z_keyexpr_fix_mapping(&msg->_body._undecl_queryable._ext_keyexpr, mapping);
} break;
case _Z_DECL_TOKEN: {
_z_keyexpr_fix_mapping(&msg->_body._decl_token._keyexpr, mapping);
} break;
case _Z_UNDECL_TOKEN: {
_z_keyexpr_fix_mapping(&msg->_body._undecl_token._ext_keyexpr, mapping);
} break;
case _Z_DECL_INTEREST: {
_z_keyexpr_fix_mapping(&msg->_body._decl_interest._keyexpr, mapping);
} break;
case _Z_UNDECL_INTEREST: {
_z_keyexpr_fix_mapping(&msg->_body._undecl_interest._ext_keyexpr, mapping);
} break;
default:
break;
}
}
void _z_decl_fix_mapping(_z_declaration_t* msg, uint16_t mapping);

_z_declaration_t _z_make_decl_keyexpr(uint16_t id, _Z_MOVE(_z_keyexpr_t) key);
_z_declaration_t _z_make_undecl_keyexpr(uint16_t id);
Expand Down
5 changes: 0 additions & 5 deletions src/net/primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,6 @@ int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *pay
const _z_encoding_t encoding, const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl,
z_priority_t priority) {
int8_t ret = _Z_RES_OK;

_z_bytes_t pld = {.len = len, .start = payload}; // Payload
_Bool can_be_dropped = cong_ctrl == Z_CONGESTION_CONTROL_DROP; // Congestion control
_z_network_message_t msg;
switch (kind) {
case Z_SAMPLE_KIND_PUT:
Expand Down Expand Up @@ -410,8 +407,6 @@ int8_t _z_subscriber_pull(const _z_subscriber_t *sub) {
_z_subscription_sptr_t *s = _z_get_subscription_by_id(sub->_zn, _Z_RESOURCE_IS_LOCAL, sub->_id);
if (s != NULL) {
_z_zint_t pull_id = _z_get_pull_id(sub->_zn);
_z_zint_t max_samples = 0; // @TODO: get the correct value for max_sample
_Bool is_final = true;
_z_zenoh_message_t z_msg = _z_msg_make_pull(_z_keyexpr_alias(s->ptr->_key), pull_id);
if (_z_send_n_msg(sub->_zn, &z_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != _Z_RES_OK) {
ret = _Z_ERR_TRANSPORT_TX_FAILED;
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/codec/declarations.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int8_t _z_undecl_interest_encode(_z_wbuf_t *wbf, const _z_undecl_interest_t *dec
return _z_undecl_encode(wbf, _Z_UNDECL_INTEREST_MID, decl->_id, decl->_ext_keyexpr);
}
int8_t _z_declaration_encode(_z_wbuf_t *wbf, const _z_declaration_t *decl) {
int8_t ret;
int8_t ret = _Z_RES_OK;
switch (decl->_tag) {
case _Z_DECL_KEXPR: {
ret = _z_decl_kexpr_encode(wbf, &decl->_body._decl_kexpr);
Expand Down
2 changes: 0 additions & 2 deletions src/protocol/codec/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ int8_t _z_msg_ext_vec_push_callback(_z_msg_ext_t *extension, _z_msg_ext_vec_t *e
return 0;
}
int8_t _z_msg_ext_vec_decode(_z_msg_ext_vec_t *extensions, _z_zbuf_t *zbf) {
int8_t ret = _Z_RES_OK;
_z_msg_ext_vec_reset(extensions);
return _z_msg_ext_decode_iter(zbf, (int8_t(*)(_z_msg_ext_t *, void *))_z_msg_ext_vec_push_callback,
(void *)extensions);
Expand Down Expand Up @@ -215,7 +214,6 @@ int8_t _z_msg_ext_decode_iter(_z_zbuf_t *zbf, int8_t (*callback)(_z_msg_ext_t *,
_Bool has_next = true;
while (has_next && ret == _Z_RES_OK) {
_z_msg_ext_t ext = _z_msg_ext_make_unit(0);
size_t start = zbf->_ios._r_pos;
ret |= _z_msg_ext_decode(&ext, zbf, &has_next);
if (ret == _Z_RES_OK) {
ret |= callback(&ext, context);
Expand Down
1 change: 0 additions & 1 deletion src/protocol/codec/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ int8_t _z_timestamp_encode(_z_wbuf_t *wbf, const _z_timestamp_t *ts) {
return ret;
}
int8_t _z_timestamp_encode_ext(_z_wbuf_t *wbf, const _z_timestamp_t *ts) {
int8_t ret = _Z_RES_OK;
_Z_RETURN_IF_ERR(_z_zint_encode(wbf, _z_zint_len(ts->time) + 1 + _z_id_len(ts->id)));
return _z_timestamp_encode(wbf, ts);
}
Expand Down
33 changes: 33 additions & 0 deletions src/protocol/definitions/declarations.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,36 @@ _z_undecl_queryable_t _z_undecl_queryable_null(void) { return (_z_undecl_queryab
_z_undecl_token_t _z_undecl_token_null(void) { return (_z_undecl_token_t){0}; }
_z_undecl_interest_t _z_undecl_interest_null(void) { return (_z_undecl_interest_t){0}; }
_z_final_interest_t _z_final_interest_null(void) { return (_z_final_interest_t){0}; }
void _z_decl_fix_mapping(_z_declaration_t* msg, uint16_t mapping) {
switch (msg->_tag) {
case _Z_DECL_KEXPR: {
_z_keyexpr_fix_mapping(&msg->_body._decl_kexpr._keyexpr, mapping);
} break;
case _Z_DECL_SUBSCRIBER: {
_z_keyexpr_fix_mapping(&msg->_body._decl_subscriber._keyexpr, mapping);
} break;
case _Z_UNDECL_SUBSCRIBER: {
_z_keyexpr_fix_mapping(&msg->_body._undecl_subscriber._ext_keyexpr, mapping);
} break;
case _Z_DECL_QUERYABLE: {
_z_keyexpr_fix_mapping(&msg->_body._decl_queryable._keyexpr, mapping);
} break;
case _Z_UNDECL_QUERYABLE: {
_z_keyexpr_fix_mapping(&msg->_body._undecl_queryable._ext_keyexpr, mapping);
} break;
case _Z_DECL_TOKEN: {
_z_keyexpr_fix_mapping(&msg->_body._decl_token._keyexpr, mapping);
} break;
case _Z_UNDECL_TOKEN: {
_z_keyexpr_fix_mapping(&msg->_body._undecl_token._ext_keyexpr, mapping);
} break;
case _Z_DECL_INTEREST: {
_z_keyexpr_fix_mapping(&msg->_body._decl_interest._keyexpr, mapping);
} break;
case _Z_UNDECL_INTEREST: {
_z_keyexpr_fix_mapping(&msg->_body._undecl_interest._ext_keyexpr, mapping);
} break;
default:
break;
}
}

0 comments on commit f10b806

Please sign in to comment.