From 469c741de32f53161df5bb1276193e43bc1c644a Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 11 Apr 2024 15:01:02 +0200 Subject: [PATCH] fix: rename encoding fields --- include/zenoh-pico/protocol/core.h | 4 ++-- src/api/api.c | 5 ++--- src/net/memory.c | 12 ++++++------ src/protocol/codec.c | 26 +++++++++++++------------- src/protocol/codec/message.c | 6 +++--- src/protocol/core.c | 4 ++-- src/protocol/definitions/message.c | 8 ++++---- src/session/query.c | 4 ++-- src/session/subscription.c | 2 +- tests/z_msgcodec_test.c | 10 +++++----- 10 files changed, 40 insertions(+), 41 deletions(-) diff --git a/include/zenoh-pico/protocol/core.h b/include/zenoh-pico/protocol/core.h index a8009aed2..2d8e8ebdb 100644 --- a/include/zenoh-pico/protocol/core.h +++ b/include/zenoh-pico/protocol/core.h @@ -59,8 +59,8 @@ _z_id_t _z_id_empty(void); * A zenoh encoding. */ typedef struct { - _z_bytes_t suffix; - z_encoding_prefix_t prefix; + _z_bytes_t schema; + uint16_t id; } _z_encoding_t; /** diff --git a/src/api/api.c b/src/api/api.c index 69a6c4631..d327e6e94 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -259,8 +259,7 @@ int8_t zp_scouting_config_insert(z_scouting_config_t sc, uint8_t key, z_string_t z_encoding_t z_encoding(z_encoding_prefix_t prefix, const char *suffix) { return (_z_encoding_t){ - .prefix = prefix, - .suffix = _z_bytes_wrap((const uint8_t *)suffix, (suffix == NULL) ? (size_t)0 : strlen(suffix))}; + .id = prefix, .schema = _z_bytes_wrap((const uint8_t *)suffix, (suffix == NULL) ? (size_t)0 : strlen(suffix))}; } z_encoding_t z_encoding_default(void) { return z_encoding(Z_ENCODING_PREFIX_DEFAULT, NULL); } @@ -948,7 +947,7 @@ int8_t z_query_reply(const z_query_t *query, const z_keyexpr_t keyexpr, const ui ._is_alloc = false, .len = payload_len, }, - .encoding = {.prefix = opts.encoding.prefix, .suffix = opts.encoding.suffix}}; + .encoding = {.id = opts.encoding.id, .schema = opts.encoding.schema}}; return _z_send_reply(&query->_val._rc.in->val, keyexpr, value, Z_SAMPLE_KIND_PUT); return _Z_ERR_GENERIC; } diff --git a/src/net/memory.c b/src/net/memory.c index f21c51529..44d5eb61a 100644 --- a/src/net/memory.c +++ b/src/net/memory.c @@ -24,8 +24,8 @@ void _z_sample_move(_z_sample_t *dst, _z_sample_t *src) { _z_bytes_move(&dst->payload, &src->payload); - dst->encoding.prefix = src->encoding.prefix; // FIXME: call the z_encoding_move - _z_bytes_move(&dst->encoding.suffix, &src->encoding.suffix); // FIXME: call the z_encoding_move + dst->encoding.id = src->encoding.id; // FIXME: call the z_encoding_move + _z_bytes_move(&dst->encoding.schema, &src->encoding.schema); // FIXME: call the z_encoding_move dst->timestamp.time = src->timestamp.time; // FIXME: call the z_timestamp_move dst->timestamp.id = src->timestamp.id; // FIXME: call the z_timestamp_move @@ -34,7 +34,7 @@ void _z_sample_move(_z_sample_t *dst, _z_sample_t *src) { void _z_sample_clear(_z_sample_t *sample) { _z_keyexpr_clear(&sample->keyexpr); _z_bytes_clear(&sample->payload); - _z_bytes_clear(&sample->encoding.suffix); // FIXME: call the z_encoding_clear + _z_bytes_clear(&sample->encoding.schema); // FIXME: call the z_encoding_clear _z_timestamp_clear(&sample->timestamp); } @@ -55,8 +55,8 @@ void _z_sample_copy(_z_sample_t *dst, const _z_sample_t *src) { dst->timestamp = _z_timestamp_duplicate(&src->timestamp); // TODO(sashacmc): should be changed after encoding rework - dst->encoding.prefix = src->encoding.prefix; - _z_bytes_copy(&dst->encoding.suffix, &src->encoding.suffix); + dst->encoding.id = src->encoding.id; + _z_bytes_copy(&dst->encoding.schema, &src->encoding.schema); dst->kind = src->kind; #if Z_FEATURE_ATTACHMENT == 1 @@ -104,7 +104,7 @@ void _z_reply_data_free(_z_reply_data_t **reply_data) { } void _z_value_clear(_z_value_t *value) { - _z_bytes_clear(&value->encoding.suffix); + _z_bytes_clear(&value->encoding.schema); _z_bytes_clear(&value->payload); } diff --git a/src/protocol/codec.c b/src/protocol/codec.c index 02c4a1708..923ec1f27 100644 --- a/src/protocol/codec.c +++ b/src/protocol/codec.c @@ -291,36 +291,36 @@ int8_t _z_str_decode(char **str, _z_zbuf_t *zbf) { #define _Z_ENCODING_FLAG_S 0x01 size_t _z_encoding_len(const _z_encoding_t *en) { - size_t en_len = _z_zint_len((uint32_t)(en->prefix) << 1); - if (_z_bytes_check(en->suffix)) { - en_len += _z_bytes_encode_len(&en->suffix); + size_t en_len = _z_zint_len((uint32_t)(en->id) << 1); + if (_z_bytes_check(en->schema)) { + en_len += _z_bytes_encode_len(&en->schema); } return en_len; } int8_t _z_encoding_encode(_z_wbuf_t *wbf, const _z_encoding_t *en) { - _Bool has_suffix = _z_bytes_check(en->suffix); - uint32_t id = (uint32_t)(en->prefix) << 1; - if (has_suffix) { + _Bool has_schema = _z_bytes_check(en->schema); + uint32_t id = (uint32_t)(en->id) << 1; + if (has_schema) { id |= _Z_ENCODING_FLAG_S; } _Z_RETURN_IF_ERR(_z_zint32_encode(wbf, id)); - if (has_suffix) { - _Z_RETURN_IF_ERR(_z_bytes_encode(wbf, &en->suffix)); + if (has_schema) { + _Z_RETURN_IF_ERR(_z_bytes_encode(wbf, &en->schema)); } return _Z_RES_OK; } int8_t _z_encoding_decode(_z_encoding_t *en, _z_zbuf_t *zbf) { uint32_t id = 0; - _Bool has_suffix = false; + _Bool has_schema = false; _Z_RETURN_IF_ERR(_z_zint32_decode(&id, zbf)); if ((id & _Z_ENCODING_FLAG_S) != 0) { - has_suffix = true; + has_schema = true; } - en->prefix = (z_encoding_prefix_t)(id >> 1); - if (has_suffix) { - _Z_RETURN_IF_ERR(_z_bytes_decode(&en->suffix, zbf)); + en->id = (uint16_t)(id >> 1); + if (has_schema) { + _Z_RETURN_IF_ERR(_z_bytes_decode(&en->schema, zbf)); } return _Z_RES_OK; } diff --git a/src/protocol/codec/message.c b/src/protocol/codec/message.c index 84291ec78..025c97fd4 100644 --- a/src/protocol/codec/message.c +++ b/src/protocol/codec/message.c @@ -279,8 +279,8 @@ int8_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb) { if (has_timestamp) { header |= _Z_FLAG_Z_P_T; } - has_encoding = pshb->_body._put._encoding.prefix != Z_ENCODING_PREFIX_EMPTY || - !_z_bytes_is_empty(&pshb->_body._put._encoding.suffix); + has_encoding = pshb->_body._put._encoding.id != Z_ENCODING_PREFIX_EMPTY || + !_z_bytes_is_empty(&pshb->_body._put._encoding.schema); if (has_encoding) { header |= _Z_FLAG_Z_P_E; } @@ -556,7 +556,7 @@ int8_t _z_err_encode(_z_wbuf_t *wbf, const _z_msg_err_t *err) { uint8_t header = _Z_MID_Z_ERR; // Encode header - _Bool has_encoding = err->encoding.prefix != Z_ENCODING_PREFIX_EMPTY; + _Bool has_encoding = err->encoding.id != Z_ENCODING_PREFIX_EMPTY; if (has_encoding) { _Z_SET_FLAG(header, _Z_FLAG_Z_E_E); } diff --git a/src/protocol/core.c b/src/protocol/core.c index 2e4619443..d8f3729f1 100644 --- a/src/protocol/core.c +++ b/src/protocol/core.c @@ -73,8 +73,8 @@ _z_value_t _z_value_steal(_z_value_t *value) { return ret; } void _z_value_copy(_z_value_t *dst, const _z_value_t *src) { - dst->encoding.prefix = src->encoding.prefix; - _z_bytes_copy(&dst->encoding.suffix, &src->encoding.suffix); + dst->encoding.id = src->encoding.id; + _z_bytes_copy(&dst->encoding.schema, &src->encoding.schema); _z_bytes_copy(&dst->payload, &src->payload); } diff --git a/src/protocol/definitions/message.c b/src/protocol/definitions/message.c index 0218f3420..40f0dc347 100644 --- a/src/protocol/definitions/message.c +++ b/src/protocol/definitions/message.c @@ -23,7 +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) { - _z_bytes_clear(&msg->_encoding.suffix); + _z_bytes_clear(&msg->_encoding.schema); _z_bytes_clear(&msg->_payload); _z_timestamp_clear(&msg->_commons._timestamp); } @@ -33,8 +33,8 @@ _z_msg_query_reqexts_t _z_msg_query_required_extensions(const _z_msg_query_t *ms z_attachment_t att = _z_encoded_as_attachment(&msg->_ext_attachment); #endif return (_z_msg_query_reqexts_t) { - .body = msg->_ext_value.payload.start != NULL || msg->_ext_value.encoding.prefix != 0 || - !_z_bytes_is_empty(&msg->_ext_value.encoding.suffix), + .body = msg->_ext_value.payload.start != NULL || msg->_ext_value.encoding.id != 0 || + !_z_bytes_is_empty(&msg->_ext_value.encoding.schema), .info = _z_id_check(msg->_ext_info._id) || msg->_ext_info._entity_id != 0 || msg->_ext_info._source_sn != 0, #if Z_FEATURE_ATTACHMENT == 1 .attachment = z_attachment_check(&att) @@ -49,6 +49,6 @@ void _z_msg_query_clear(_z_msg_query_t *msg) { _z_value_clear(&msg->_ext_value); } void _z_msg_err_clear(_z_msg_err_t *err) { - _z_bytes_clear(&err->encoding.suffix); + _z_bytes_clear(&err->encoding.schema); _z_bytes_clear(&err->_payload); } diff --git a/src/session/query.c b/src/session/query.c index 8e596e6c3..16ab2b487 100644 --- a/src/session/query.c +++ b/src/session/query.c @@ -156,8 +156,8 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons reply.data.replier_id = zn->_local_zid; reply.data.sample.keyexpr = expanded_ke; _z_bytes_copy(&reply.data.sample.payload, &msg->_payload); - reply.data.sample.encoding.prefix = msg->_encoding.prefix; - _z_bytes_copy(&reply.data.sample.encoding.suffix, &msg->_encoding.suffix); + reply.data.sample.encoding.id = msg->_encoding.id; + _z_bytes_copy(&reply.data.sample.encoding.schema, &msg->_encoding.schema); reply.data.sample.kind = Z_SAMPLE_KIND_PUT; reply.data.sample.timestamp = _z_timestamp_duplicate(&msg->_commons._timestamp); diff --git a/src/session/subscription.c b/src/session/subscription.c index 27a258804..b9faf89f3 100644 --- a/src/session/subscription.c +++ b/src/session/subscription.c @@ -143,7 +143,7 @@ void _z_trigger_local_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr z_attachment_t att #endif ) { - _z_encoding_t encoding = {.prefix = Z_ENCODING_PREFIX_DEFAULT, .suffix = _z_bytes_wrap(NULL, 0)}; + _z_encoding_t encoding = {.id = Z_ENCODING_PREFIX_DEFAULT, .schema = _z_bytes_wrap(NULL, 0)}; int8_t ret = _z_trigger_subscriptions(zn, keyexpr, _z_bytes_wrap(payload, payload_len), encoding, Z_SAMPLE_KIND_PUT, _z_timestamp_null(), qos #if Z_FEATURE_ATTACHMENT == 1 diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index 40d549c0f..39d761c72 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -238,11 +238,11 @@ _z_locator_array_t gen_locator_array(size_t size) { _z_encoding_t gen_encoding(void) { _z_encoding_t en; - en.prefix = gen_uint32() & 0x7fffffff; + en.id = gen_uint16(); if (gen_bool()) { - en.suffix = gen_bytes(16); + en.schema = gen_bytes(16); } else { - en.suffix = _z_bytes_empty(); + en.schema = _z_bytes_empty(); } return en; } @@ -538,8 +538,8 @@ void assert_eq_source_info(const _z_source_info_t *left, const _z_source_info_t assert(memcmp(left->_id.id, right->_id.id, 16) == 0); } void assert_eq_encoding(const _z_encoding_t *left, const _z_encoding_t *right) { - assert(left->prefix == right->prefix); - assert_eq_bytes(&left->suffix, &right->suffix); + assert(left->id == right->id); + assert_eq_bytes(&left->schema, &right->schema); } void assert_eq_value(const _z_value_t *left, const _z_value_t *right) { assert_eq_encoding(&left->encoding, &right->encoding);