diff --git a/include/zenoh-pico/protocol/codec/core.h b/include/zenoh-pico/protocol/codec/core.h index 5320a5ce8..13cb2d06a 100644 --- a/include/zenoh-pico/protocol/codec/core.h +++ b/include/zenoh-pico/protocol/codec/core.h @@ -50,25 +50,19 @@ int8_t _z_query_target_decode(z_query_target_t *en, _z_zbuf_t *zbf); int8_t _z_whatami_encode(_z_wbuf_t *wbf, z_whatami_t en); int8_t _z_whatami_decode(z_whatami_t *en, _z_zbuf_t *zbf); -int8_t _z_uint_encode(_z_wbuf_t *buf, unsigned int v); -int8_t _z_uint_decode(unsigned int *u, _z_zbuf_t *buf); - int8_t _z_uint8_encode(_z_wbuf_t *buf, uint8_t v); int8_t _z_uint8_decode(uint8_t *u8, _z_zbuf_t *buf); int8_t _z_uint16_encode(_z_wbuf_t *buf, uint16_t v); int8_t _z_uint16_decode(uint16_t *u16, _z_zbuf_t *buf); -int8_t _z_uint64_encode(_z_wbuf_t *buf, uint64_t v); -int8_t _z_uint64_decode(uint64_t *u64, _z_zbuf_t *buf); - -uint8_t _z_zint_len(_z_zint_t v); -int8_t _z_zint_encode(_z_wbuf_t *buf, _z_zint_t v); +uint8_t _z_zint_len(uint64_t v); +int8_t _z_zsize_encode(_z_wbuf_t *buf, _z_zint_t v); int8_t _z_zint64_encode(_z_wbuf_t *buf, uint64_t v); int8_t _z_zint16_decode(uint16_t *zint, _z_zbuf_t *buf); int8_t _z_zint32_decode(uint32_t *zint, _z_zbuf_t *buf); int8_t _z_zint64_decode(uint64_t *zint, _z_zbuf_t *buf); -int8_t _z_zint_decode(_z_zint_t *zint, _z_zbuf_t *buf); +int8_t _z_zsize_decode(_z_zint_t *zint, _z_zbuf_t *buf); int8_t _z_bytes_val_encode(_z_wbuf_t *buf, const _z_bytes_t *bs); int8_t _z_bytes_val_decode(_z_bytes_t *bs, _z_zbuf_t *buf); diff --git a/src/protocol/codec.c b/src/protocol/codec.c index 2e13129ed..8a371ef52 100644 --- a/src/protocol/codec.c +++ b/src/protocol/codec.c @@ -21,85 +21,54 @@ #include "zenoh-pico/utils/result.h" /*------------------ uint8 -------------------*/ -int8_t _z_encoding_prefix_encode(_z_wbuf_t *wbf, z_encoding_prefix_t en) { return _z_zint_encode(wbf, en); } +int8_t _z_encoding_prefix_encode(_z_wbuf_t *wbf, z_encoding_prefix_t en) { return _z_zsize_encode(wbf, en); } int8_t _z_encoding_prefix_decode(z_encoding_prefix_t *en, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; _z_zint_t tmp; - ret |= _z_zint_decode(&tmp, zbf); + ret |= _z_zsize_decode(&tmp, zbf); *en = tmp; return ret; } -int8_t _z_consolidation_mode_encode(_z_wbuf_t *wbf, z_consolidation_mode_t en) { return _z_zint_encode(wbf, en); } +int8_t _z_consolidation_mode_encode(_z_wbuf_t *wbf, z_consolidation_mode_t en) { return _z_zsize_encode(wbf, en); } int8_t _z_consolidation_mode_decode(z_consolidation_mode_t *en, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; _z_zint_t tmp; - ret |= _z_zint_decode(&tmp, zbf); + ret |= _z_zsize_decode(&tmp, zbf); *en = tmp; return ret; } -int8_t _z_query_target_encode(_z_wbuf_t *wbf, z_query_target_t en) { return _z_zint_encode(wbf, en); } +int8_t _z_query_target_encode(_z_wbuf_t *wbf, z_query_target_t en) { return _z_zsize_encode(wbf, en); } int8_t _z_query_target_decode(z_query_target_t *en, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; _z_zint_t tmp; - ret |= _z_zint_decode(&tmp, zbf); + ret |= _z_zsize_decode(&tmp, zbf); *en = tmp; return ret; } -int8_t _z_whatami_encode(_z_wbuf_t *wbf, z_whatami_t en) { return _z_zint_encode(wbf, en); } +int8_t _z_whatami_encode(_z_wbuf_t *wbf, z_whatami_t en) { return _z_zsize_encode(wbf, en); } int8_t _z_whatami_decode(z_whatami_t *en, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; _z_zint_t tmp; - ret |= _z_zint_decode(&tmp, zbf); + ret |= _z_zsize_decode(&tmp, zbf); *en = tmp; return ret; } -int8_t _z_uint_encode(_z_wbuf_t *wbf, unsigned int uint) { - unsigned int lv = uint; - - while (lv > (unsigned int)0x7f) { - uint8_t c = (uint8_t)(lv & (unsigned int)0x7f) | (uint8_t)0x80; - _Z_RETURN_IF_ERR(_z_wbuf_write(wbf, c)) - lv = lv >> (unsigned int)7; - } - - uint8_t c = (uint8_t)(lv & (unsigned int)0xff); - return _z_wbuf_write(wbf, c); -} - -int8_t _z_uint_decode(unsigned int *uint, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; - *uint = 0; - - uint8_t i = 0; - uint8_t u8 = 0; - do { - if (_z_uint8_decode(&u8, zbf) == _Z_RES_OK) { - *uint = *uint | (((unsigned int)u8 & (unsigned int)0x7f) << (unsigned int)i); - i = i + (uint8_t)7; - } else { - ret |= _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; - } - } while (u8 > (uint8_t)0x7f); - - return ret; -} - int8_t _z_uint8_encode(_z_wbuf_t *wbf, uint8_t u8) { return _z_wbuf_write(wbf, u8); } int8_t _z_uint8_decode(uint8_t *u8, _z_zbuf_t *zbf) { @@ -138,74 +107,73 @@ int8_t _z_uint16_decode(uint16_t *u16, _z_zbuf_t *zbf) { return ret; } -int8_t _z_uint64_encode(_z_wbuf_t *wbf, uint64_t u64) { - uint64_t lv = u64; - - while (lv > (uint64_t)0x7f) { - uint8_t c = (uint8_t)(lv & (uint64_t)0x7f) | (uint8_t)0x80; - _Z_RETURN_IF_ERR(_z_wbuf_write(wbf, c)) - lv = lv >> (_z_zint_t)7; - } - - uint8_t c = lv & (uint64_t)0xff; - return _z_wbuf_write(wbf, c); -} - -int8_t _z_uint64_decode(uint64_t *u64, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; - *u64 = 0; - - uint8_t i = 0; - uint8_t u8 = 0; - do { - if (_z_uint8_decode(&u8, zbf) == _Z_RES_OK) { - *u64 = *u64 | (((_z_zint_t)u8 & 0x7f) << i); - i = i + (uint8_t)7; - } else { - ret |= _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; - } - } while (u8 > (uint8_t)0x7f); - - return ret; -} - /*------------------ z_zint ------------------*/ -uint8_t _z_zint_len(_z_zint_t v) { - uint8_t len = 1; - while (v > 0x7f) { - v >>= 7; - len++; +#define VLE_LEN 9 + +uint8_t _z_zint_len(uint64_t v) { + if ((v & (UINT64_MAX << (7 * 1))) == 0) { + return 1; + } else if ((v & (UINT64_MAX << (7 * 2))) == 0) { + return 2; + } else if ((v & (UINT64_MAX << (7 * 3))) == 0) { + return 3; + } else if ((v & (UINT64_MAX << (7 * 4))) == 0) { + return 4; + } else if ((v & (UINT64_MAX << (7 * 5))) == 0) { + return 5; + } else if ((v & (UINT64_MAX << (7 * 6))) == 0) { + return 6; + } else if ((v & (UINT64_MAX << (7 * 7))) == 0) { + return 7; + } else if ((v & (UINT64_MAX << (7 * 8))) == 0) { + return 8; + } else { + return 9; } - return len; } -int8_t _z_zint_encode(_z_wbuf_t *wbf, _z_zint_t v) { - _z_zint_t lv = v; - while (lv > 0x7f) { +int8_t _z_zint64_encode(_z_wbuf_t *wbf, uint64_t v) { + uint64_t lv = v; + uint8_t len = 0; + while ((lv & (uint64_t)~0x7f) != 0) { uint8_t c = (lv & 0x7f) | 0x80; _Z_RETURN_IF_ERR(_z_wbuf_write(wbf, c)) - lv = lv >> (_z_zint_t)7; + len++; + lv = lv >> (uint64_t)7; + } + if (len != VLE_LEN) { + uint8_t c = (lv & 0xff); + _Z_RETURN_IF_ERR(_z_wbuf_write(wbf, c)) } - uint8_t c = lv & 0xff; - return _z_wbuf_write(wbf, c); + return _Z_RES_OK; } -int8_t _z_zint64_encode(_z_wbuf_t *wbf, uint64_t v) { - uint64_t lv = v; - while (lv > 0x7f) { - uint8_t c = (lv & 0x7f) | 0x80; - _Z_RETURN_IF_ERR(_z_wbuf_write(wbf, c)) - lv = lv >> (uint64_t)7; +int8_t _z_zint16_encode(_z_wbuf_t *wbf, uint16_t v) { return _z_zint64_encode(wbf, (uint64_t)v); } +int8_t _z_zint32_encode(_z_wbuf_t *wbf, uint32_t v) { return _z_zint64_encode(wbf, (uint64_t)v); } +int8_t _z_zsize_encode(_z_wbuf_t *wbf, _z_zint_t v) { return _z_zint64_encode(wbf, (uint64_t)v); } + +int8_t _z_zint64_decode(uint64_t *zint, _z_zbuf_t *zbf) { + *zint = 0; + + uint8_t b = 0; + _Z_RETURN_IF_ERR(_z_uint8_decode(&b, zbf)); + + uint8_t i = 0; + while (((b & 0x80) != 0) && (i != 7 * (VLE_LEN - 1))) { + *zint = *zint | ((uint64_t)(b & 0x7f)) << i; + _Z_RETURN_IF_ERR(_z_uint8_decode(&b, zbf)); + i = i + (uint8_t)7; } + *zint = *zint | ((uint64_t)b << i); - uint8_t c = lv & 0xff; - return _z_wbuf_write(wbf, c); + return _Z_RES_OK; } + int8_t _z_zint16_decode(uint16_t *zint, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; - _z_zint_t buf; - _Z_RETURN_IF_ERR(_z_zint_decode(&buf, zbf)); + uint64_t buf; + _Z_RETURN_IF_ERR(_z_zint64_decode(&buf, zbf)); if (buf <= UINT16_MAX) { *zint = (uint16_t)buf; } else { @@ -213,10 +181,11 @@ int8_t _z_zint16_decode(uint16_t *zint, _z_zbuf_t *zbf) { } return ret; } + int8_t _z_zint32_decode(uint32_t *zint, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; - _z_zint_t buf; - _Z_RETURN_IF_ERR(_z_zint_decode(&buf, zbf)); + uint64_t buf; + _Z_RETURN_IF_ERR(_z_zint64_decode(&buf, zbf)); if (buf <= UINT32_MAX) { *zint = (uint32_t)buf; } else { @@ -224,38 +193,16 @@ int8_t _z_zint32_decode(uint32_t *zint, _z_zbuf_t *zbf) { } return ret; } -int8_t _z_zint_decode(_z_zint_t *zint, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; - *zint = 0; - uint8_t i = 0; - uint8_t u8 = 0; - do { - if (_z_uint8_decode(&u8, zbf) == _Z_RES_OK) { - *zint = *zint | (((_z_zint_t)u8 & 0x7f) << i); - i = i + (uint8_t)7; - } else { - ret |= _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; - } - } while (u8 > (uint8_t)0x7f); - - return ret; -} -int8_t _z_zint64_decode(uint64_t *zint, _z_zbuf_t *zbf) { +int8_t _z_zsize_decode(_z_zint_t *zint, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; - *zint = 0; - - uint8_t i = 0; - uint8_t u8 = 0; - do { - if (_z_uint8_decode(&u8, zbf) == _Z_RES_OK) { - *zint = *zint | (((uint64_t)u8 & 0x7f) << i); - i = i + (uint8_t)7; - } else { - ret |= _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; - } - } while (u8 > (uint8_t)0x7f); - + uint64_t buf; + _Z_RETURN_IF_ERR(_z_zint64_decode(&buf, zbf)); + if (buf <= SIZE_MAX) { + *zint = (_z_zint_t)buf; + } else { + ret = _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; + } return ret; } @@ -275,7 +222,7 @@ int8_t _z_bytes_val_encode(_z_wbuf_t *wbf, const _z_bytes_t *bs) { int8_t _z_bytes_encode(_z_wbuf_t *wbf, const _z_bytes_t *bs) { int8_t ret = _Z_RES_OK; - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, bs->len)) + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, bs->len)) _Z_RETURN_IF_ERR(_z_bytes_val_encode(wbf, bs)) return ret; @@ -306,7 +253,7 @@ int8_t _z_bytes_val_decode_na(_z_bytes_t *bs, _z_zbuf_t *zbf) { int8_t _z_bytes_decode_na(_z_bytes_t *bs, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; - ret |= _z_zint_decode(&bs->len, zbf); + ret |= _z_zsize_decode(&bs->len, zbf); ret |= _z_bytes_val_decode_na(bs, zbf); return ret; @@ -319,7 +266,7 @@ int8_t _z_bytes_decode(_z_bytes_t *bs, _z_zbuf_t *zbf) { return _z_bytes_decode_ /*------------------ string with null terminator ------------------*/ int8_t _z_str_encode(_z_wbuf_t *wbf, const char *s) { size_t len = strlen(s); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, len)) + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, len)) // Note that this does not put the string terminator on the wire. return _z_wbuf_write_bytes(wbf, (const uint8_t *)s, 0, len); } @@ -328,7 +275,7 @@ int8_t _z_str_decode(char **str, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; _z_zint_t len = 0; - ret |= _z_zint_decode(&len, zbf); + ret |= _z_zsize_decode(&len, zbf); if (ret == _Z_RES_OK) { if (_z_zbuf_len(zbf) >= len) { // Check if we have enough bytes to read char *tmp = (char *)zp_malloc(len + (size_t)1); // Allocate space for the string terminator diff --git a/src/protocol/codec/declarations.c b/src/protocol/codec/declarations.c index 207bd6129..d9d86d684 100644 --- a/src/protocol/codec/declarations.c +++ b/src/protocol/codec/declarations.c @@ -38,9 +38,9 @@ int8_t _z_decl_ext_keyexpr_encode(_z_wbuf_t *wbf, _z_keyexpr_t ke, _Bool has_nex _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); uint32_t kelen = (uint32_t)(_z_keyexpr_has_suffix(ke) ? strlen(ke._suffix) : 0); header = (_z_keyexpr_is_local(&ke) ? 2 : 0) | (kelen != 0 ? 1 : 0); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, 1 + kelen + _z_zint_len(ke._id))); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, 1 + kelen + _z_zint_len(ke._id))); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, ke._id)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, ke._id)); if (kelen) { _Z_RETURN_IF_ERR(_z_wbuf_write_bytes(wbf, (const uint8_t *)ke._suffix, 0, kelen)) } @@ -54,7 +54,7 @@ int8_t _z_decl_kexpr_encode(_z_wbuf_t *wbf, const _z_decl_kexpr_t *decl) { header |= _Z_DECL_KEXPR_FLAG_N; } _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, decl->_id)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, decl->_id)); _Z_RETURN_IF_ERR(_z_keyexpr_encode(wbf, has_kesuffix, &decl->_keyexpr)) return _Z_RES_OK; @@ -72,7 +72,7 @@ int8_t _z_decl_commons_encode(_z_wbuf_t *wbf, uint8_t header, _Bool has_extensio header |= _Z_DECL_SUBSCRIBER_FLAG_M; } _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, id)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, id)); return _z_keyexpr_encode(wbf, has_kesuffix, &keyexpr); } int8_t _z_decl_subscriber_encode(_z_wbuf_t *wbf, const _z_decl_subscriber_t *decl) { @@ -88,7 +88,7 @@ int8_t _z_decl_subscriber_encode(_z_wbuf_t *wbf, const _z_decl_subscriber_t *dec } int8_t _z_undecl_kexpr_encode(_z_wbuf_t *wbf, const _z_undecl_kexpr_t *decl) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_UNDECL_KEXPR)); - return _z_zint_encode(wbf, decl->_id); + return _z_zsize_encode(wbf, decl->_id); } int8_t _z_undecl_encode(_z_wbuf_t *wbf, uint8_t header, _z_zint_t decl_id, _z_keyexpr_t ke) { _Bool has_keyexpr_ext = _z_keyexpr_check(ke); @@ -96,7 +96,7 @@ int8_t _z_undecl_encode(_z_wbuf_t *wbf, uint8_t header, _z_zint_t decl_id, _z_ke header |= _Z_FLAG_Z_Z; } _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, decl_id)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, decl_id)); if (has_keyexpr_ext) { _Z_RETURN_IF_ERR(_z_decl_ext_keyexpr_encode(wbf, ke, false)); } @@ -139,7 +139,7 @@ int8_t _z_decl_interest_encode(_z_wbuf_t *wbf, const _z_decl_interest_t *decl) { } _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); // Set id - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, decl->_id)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, decl->_id)); // Copy flags but clear double use ones. uint8_t interest_flags = decl->interest_flags; _Z_CLEAR_FLAG(interest_flags, _Z_INTEREST_FLAG_CURRENT); @@ -167,7 +167,7 @@ int8_t _z_decl_interest_encode(_z_wbuf_t *wbf, const _z_decl_interest_t *decl) { int8_t _z_final_interest_encode(_z_wbuf_t *wbf, const _z_final_interest_t *decl) { uint8_t header = _Z_FINAL_INTEREST_MID; _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, decl->_id)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, decl->_id)); return _Z_RES_OK; } @@ -279,7 +279,7 @@ int8_t _z_decl_commons_decode(_z_zbuf_t *zbf, uint8_t header, _Bool *has_extensi _Z_RETURN_IF_ERR(_z_zint16_decode(&ke->_id, zbf)); if (_Z_HAS_FLAG(header, _Z_DECL_SUBSCRIBER_FLAG_N)) { _z_zint_t len; - _Z_RETURN_IF_ERR(_z_zint_decode(&len, zbf)); + _Z_RETURN_IF_ERR(_z_zsize_decode(&len, zbf)); if (_z_zbuf_len(zbf) < len) { return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; } @@ -379,7 +379,7 @@ int8_t _z_decl_interest_decode(_z_decl_interest_t *decl, _z_zbuf_t *zbf, uint8_t // Decode ke suffix if (_Z_HAS_FLAG(decl->interest_flags, _Z_DECL_SUBSCRIBER_FLAG_N)) { _z_zint_t len; - _Z_RETURN_IF_ERR(_z_zint_decode(&len, zbf)); + _Z_RETURN_IF_ERR(_z_zsize_decode(&len, zbf)); if (_z_zbuf_len(zbf) < len) { return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; } diff --git a/src/protocol/codec/message.c b/src/protocol/codec/message.c index f79a641ee..7dd176d87 100644 --- a/src/protocol/codec/message.c +++ b/src/protocol/codec/message.c @@ -87,13 +87,13 @@ int8_t _z_timestamp_encode(_z_wbuf_t *wbf, const _z_timestamp_t *ts) { int8_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _TIMESTAMP"); - _Z_RETURN_IF_ERR(_z_uint64_encode(wbf, ts->time)) + _Z_RETURN_IF_ERR(_z_zint64_encode(wbf, ts->time)) ret |= _z_id_encode_as_zbytes(wbf, &ts->id); return ret; } int8_t _z_timestamp_encode_ext(_z_wbuf_t *wbf, const _z_timestamp_t *ts) { - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, _z_zint_len(ts->time) + 1 + _z_id_len(ts->id))); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, _z_zint_len(ts->time) + (uint8_t)1 + _z_id_len(ts->id))); return _z_timestamp_encode(wbf, ts); } @@ -101,7 +101,7 @@ int8_t _z_timestamp_decode(_z_timestamp_t *ts, _z_zbuf_t *zbf) { _Z_DEBUG("Decoding _TIMESTAMP"); int8_t ret = _Z_RES_OK; - ret |= _z_uint64_decode(&ts->time, zbf); + ret |= _z_zint64_decode(&ts->time, zbf); ret |= _z_id_decode_as_zbytes(&ts->id, zbf); return ret; @@ -112,7 +112,7 @@ int8_t _z_keyexpr_encode(_z_wbuf_t *wbf, _Bool has_suffix, const _z_keyexpr_t *f int8_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _RESKEY"); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, fld->_id)) + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, fld->_id)) if (has_suffix == true) { _Z_RETURN_IF_ERR(_z_str_encode(wbf, fld->_suffix)) } @@ -146,7 +146,7 @@ int8_t _z_keyexpr_decode(_z_keyexpr_t *ke, _z_zbuf_t *zbf, _Bool has_suffix) { int8_t _z_locators_encode(_z_wbuf_t *wbf, const _z_locator_array_t *la) { int8_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _LOCATORS"); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, la->_len)) + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, la->_len)) for (size_t i = 0; i < la->_len; i++) { char *s = _z_locator_to_str(&la->_val[i]); _Z_RETURN_IF_ERR(_z_str_encode(wbf, s)) @@ -161,7 +161,7 @@ int8_t _z_locators_decode_na(_z_locator_array_t *a_loc, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; _z_zint_t len = 0; // Number of elements in the array - ret |= _z_zint_decode(&len, zbf); + ret |= _z_zsize_decode(&len, zbf); if (ret == _Z_RES_OK) { *a_loc = _z_locator_array_make(len); @@ -203,7 +203,7 @@ int8_t _z_source_info_decode(_z_source_info_t *info, _z_zbuf_t *zbf) { } } if (ret == _Z_RES_OK) { - ret = _z_zint_decode(&intbuf, zbf); + ret = _z_zsize_decode(&intbuf, zbf); if (intbuf <= UINT32_MAX) { info->_entity_id = (uint32_t)intbuf; } else { @@ -211,7 +211,7 @@ int8_t _z_source_info_decode(_z_source_info_t *info, _z_zbuf_t *zbf) { } } if (ret == _Z_RES_OK) { - ret = _z_zint_decode(&intbuf, zbf); + ret = _z_zsize_decode(&intbuf, zbf); if (intbuf <= UINT32_MAX) { info->_source_sn = (uint32_t)intbuf; } else { @@ -226,20 +226,20 @@ int8_t _z_source_info_encode(_z_wbuf_t *wbf, const _z_source_info_t *info) { ret |= _z_uint8_encode(wbf, zidlen << 4); _z_bytes_t zid = _z_bytes_wrap(info->_id.id, zidlen); ret |= _z_bytes_val_encode(wbf, &zid); - ret |= _z_zint_encode(wbf, info->_entity_id); - ret |= _z_zint_encode(wbf, info->_source_sn); + ret |= _z_zsize_encode(wbf, info->_entity_id); + ret |= _z_zsize_encode(wbf, info->_source_sn); return ret; } int8_t _z_source_info_encode_ext(_z_wbuf_t *wbf, const _z_source_info_t *info) { int8_t ret = 0; uint8_t zidlen = _z_id_len(info->_id); uint16_t len = 1 + zidlen + _z_zint_len(info->_entity_id) + _z_zint_len(info->_source_sn); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, len)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, len)); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, zidlen << 4)); _z_bytes_t zid = _z_bytes_wrap(info->_id.id, zidlen); _Z_RETURN_IF_ERR(_z_bytes_val_encode(wbf, &zid)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, info->_entity_id)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, info->_source_sn)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, info->_entity_id)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, info->_source_sn)); return ret; } #if Z_FEATURE_ATTACHMENT == 1 @@ -251,7 +251,7 @@ int8_t _z_attachment_encode_ext_kv(_z_bytes_t key, _z_bytes_t value, void *ctx) } int8_t _z_attachment_encode_ext(_z_wbuf_t *wbf, z_attachment_t att) { size_t len = _z_attachment_estimate_length(att); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, len)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, len)); _Z_RETURN_IF_ERR(z_attachment_iterate(att, _z_attachment_encode_ext_kv, wbf)); return 0; } @@ -437,9 +437,9 @@ int8_t _z_query_encode(_z_wbuf_t *wbf, const _z_msg_query_t *msg) { extheader |= _Z_FLAG_Z_Z; } _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, _z_zint_len(msg->_ext_value.encoding.prefix) + - _z_bytes_encode_len(&msg->_ext_value.encoding.suffix) + - msg->_ext_value.payload.len)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, _z_zint_len(msg->_ext_value.encoding.prefix) + + _z_bytes_encode_len(&msg->_ext_value.encoding.suffix) + + msg->_ext_value.payload.len)); _Z_RETURN_IF_ERR(_z_encoding_prefix_encode(wbf, msg->_ext_value.encoding.prefix)); _Z_RETURN_IF_ERR(_z_bytes_encode(wbf, &msg->_ext_value.encoding.suffix)); _Z_RETURN_IF_ERR(_z_bytes_val_encode(wbf, &msg->_ext_value.payload)); @@ -655,7 +655,7 @@ int8_t _z_scout_decode(_z_s_msg_scout_t *msg, _z_zbuf_t *zbf, uint8_t header) { msg->_what = cbyte & 0x07; msg->_zid = _z_id_empty(); if ((ret == _Z_RES_OK) && (_Z_HAS_FLAG(cbyte, _Z_FLAG_T_SCOUT_I) == true)) { - uint8_t zidlen = ((cbyte & 0xF0) >> 4) + 1; + uint8_t zidlen = ((cbyte & 0xF0) >> 4) + (uint8_t)1; _z_zbuf_read_bytes(zbf, msg->_zid.id, 0, zidlen); } @@ -692,7 +692,7 @@ int8_t _z_hello_decode_na(_z_s_msg_hello_t *msg, _z_zbuf_t *zbf, uint8_t header) uint8_t cbyte = 0; ret |= _z_uint8_decode(&cbyte, zbf); msg->_whatami = cbyte & 0x03; - uint8_t zidlen = ((cbyte & 0xF0) >> 4) + 1; + uint8_t zidlen = ((cbyte & 0xF0) >> 4) + (uint8_t)1; if (ret == _Z_RES_OK) { msg->_zid = _z_id_empty(); diff --git a/src/protocol/codec/network.c b/src/protocol/codec/network.c index 53d534e6f..5074b8a2e 100644 --- a/src/protocol/codec/network.c +++ b/src/protocol/codec/network.c @@ -118,14 +118,14 @@ int8_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg) { } _z_n_msg_request_exts_t exts = _z_n_msg_request_needed_exts(msg); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header | (exts.n != 0 ? _Z_FLAG_Z_Z : 0))); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_rid)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_rid)); _Z_RETURN_IF_ERR(_z_keyexpr_encode(wbf, has_suffix, &msg->_key)); if (exts.ext_qos) { exts.n -= 1; uint8_t extheader = 0x01 | _Z_MSG_EXT_ENC_ZINT | (exts.n ? _Z_FLAG_Z_Z : 0); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_ext_qos._val)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_ext_qos._val)); } if (exts.ext_tstamp) { exts.n -= 1; @@ -137,19 +137,19 @@ int8_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg) { exts.n -= 1; uint8_t extheader = 0x04 | _Z_MSG_EXT_ENC_ZINT | (exts.n ? _Z_FLAG_Z_Z : 0) | _Z_MSG_EXT_FLAG_M; _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_ext_target)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_ext_target)); } if (exts.ext_budget) { exts.n -= 1; uint8_t extheader = 0x05 | _Z_MSG_EXT_ENC_ZINT | (exts.n ? _Z_FLAG_Z_Z : 0); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_ext_budget)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_ext_budget)); } if (exts.ext_timeout_ms) { exts.n -= 1; uint8_t extheader = 0x06 | _Z_MSG_EXT_ENC_ZINT | (exts.n ? _Z_FLAG_Z_Z : 0); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_ext_timeout_ms)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_ext_timeout_ms)); } switch (msg->_tag) { @@ -208,7 +208,7 @@ int8_t _z_request_decode_extensions(_z_msg_ext_t *extension, void *ctx) { int8_t _z_request_decode(_z_n_msg_request_t *msg, _z_zbuf_t *zbf, const uint8_t header) { *msg = (_z_n_msg_request_t){0}; msg->_ext_qos = _Z_N_QOS_DEFAULT; - _Z_RETURN_IF_ERR(_z_zint_decode(&msg->_rid, zbf)); + _Z_RETURN_IF_ERR(_z_zsize_decode(&msg->_rid, zbf)); _Z_RETURN_IF_ERR(_z_keyexpr_decode(&msg->_key, zbf, _Z_HAS_FLAG(header, _Z_FLAG_N_REQUEST_N))); _z_keyexpr_set_mapping(&msg->_key, _Z_HAS_FLAG(header, _Z_FLAG_N_REQUEST_M) ? _Z_KEYEXPR_MAPPING_UNKNOWN_REMOTE : _Z_KEYEXPR_MAPPING_LOCAL); @@ -257,8 +257,8 @@ int8_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg) { } _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_request_id)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_key._id)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_request_id)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_key._id)); if (has_suffix) { _Z_RETURN_IF_ERR(_z_str_encode(wbf, msg->_key._suffix)) } @@ -269,7 +269,7 @@ int8_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg) { extheader |= _Z_FLAG_Z_Z; } _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_ext_qos._val)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_ext_qos._val)); } if (has_ts_ext) { n_ext -= 1; @@ -283,10 +283,10 @@ int8_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); uint8_t zidlen = _z_id_len(msg->_ext_responder._zid); extheader = (zidlen - 1) << 4; - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, zidlen + 1 + _z_zint_len(msg->_ext_responder._eid))); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, zidlen + (uint8_t)1 + _z_zint_len(msg->_ext_responder._eid))); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); _Z_RETURN_IF_ERR(_z_wbuf_write_bytes(wbf, msg->_ext_responder._zid.id, 0, zidlen)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_ext_responder._eid)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_ext_responder._eid)); } switch (msg->_tag) { @@ -320,7 +320,7 @@ int8_t _z_response_decode_extension(_z_msg_ext_t *extension, void *ctx) { _z_zbuf_t *zbf = &_zbf; uint8_t header; _Z_RETURN_IF_ERR(_z_uint8_decode(&header, zbf)); - uint8_t zidlen = (header >> 4) + 1; + uint8_t zidlen = (header >> 4) + (uint8_t)1; _Z_RETURN_IF_ERR(_z_zbuf_read_exact(zbf, msg->_ext_responder._zid.id, zidlen)); _Z_RETURN_IF_ERR(_z_zint32_decode(&msg->_ext_responder._eid, zbf)); break; @@ -340,7 +340,7 @@ int8_t _z_response_decode(_z_n_msg_response_t *msg, _z_zbuf_t *zbf, uint8_t head int8_t ret = _Z_RES_OK; _z_keyexpr_set_mapping(&msg->_key, _Z_HAS_FLAG(header, _Z_FLAG_N_RESPONSE_M) ? _Z_KEYEXPR_MAPPING_UNKNOWN_REMOTE : _Z_KEYEXPR_MAPPING_LOCAL); - _Z_RETURN_IF_ERR(_z_zint_decode(&msg->_request_id, zbf)); + _Z_RETURN_IF_ERR(_z_zsize_decode(&msg->_request_id, zbf)); _Z_RETURN_IF_ERR(_z_keyexpr_decode(&msg->_key, zbf, _Z_HAS_FLAG(header, _Z_FLAG_N_RESPONSE_N))); if (_Z_HAS_FLAG(header, _Z_FLAG_Z_Z)) { _Z_RETURN_IF_ERR(_z_msg_ext_decode_iter(zbf, _z_response_decode_extension, msg)); @@ -374,7 +374,7 @@ int8_t _z_response_final_encode(_z_wbuf_t *wbf, const _z_n_msg_response_final_t _Z_DEBUG("Encoding _Z_MID_N_RESPONSE"); uint8_t header = _Z_MID_N_RESPONSE_FINAL; _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_request_id)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_request_id)); return ret; } @@ -384,7 +384,7 @@ int8_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, *msg = (_z_n_msg_response_final_t){0}; int8_t ret = _Z_RES_OK; - ret |= _z_zint_decode(&msg->_request_id, zbf); + ret |= _z_zsize_decode(&msg->_request_id, zbf); if (_Z_HAS_FLAG(header, _Z_FLAG_Z_Z)) { _Z_RETURN_IF_ERR(_z_msg_ext_skip_non_mandatories(zbf, 0x1a)); } @@ -403,7 +403,7 @@ int8_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl) { if (has_qos_ext) { n -= 1; _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, 0x01 | _Z_MSG_EXT_ENC_ZINT | (n != 0 ? _Z_FLAG_Z_Z : 0))); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, decl->_ext_qos._val)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, decl->_ext_qos._val)); } if (has_timestamp_ext) { n -= 1; diff --git a/src/protocol/codec/transport.c b/src/protocol/codec/transport.c index 1eaf27a41..730a5ab83 100644 --- a/src/protocol/codec/transport.c +++ b/src/protocol/codec/transport.c @@ -49,12 +49,12 @@ int8_t _z_join_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_join_t *msg _Z_RETURN_IF_ERR(_z_uint16_encode(wbf, msg->_batch_size)); } if (_Z_HAS_FLAG(header, _Z_FLAG_T_JOIN_T) == true) { - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_lease / 1000)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_lease / 1000)); } else { - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_lease)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_lease)); } - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_next_sn._val._plain._reliable)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_next_sn._val._plain._best_effort)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_next_sn._val._plain._reliable)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_next_sn._val._plain._best_effort)); if (msg->_next_sn._is_qos) { if (_Z_HAS_FLAG(header, _Z_FLAG_T_Z)) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ENC_ZBUF | _Z_MSG_EXT_FLAG_M | 1)); @@ -63,10 +63,10 @@ int8_t _z_join_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_join_t *msg len += _z_zint_len(msg->_next_sn._val._qos[i]._reliable) + _z_zint_len(msg->_next_sn._val._qos[i]._best_effort); } - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, len)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, len)); for (uint8_t i = 0; (i < Z_PRIORITIES_NUM) && (ret == _Z_RES_OK); i++) { - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_next_sn._val._qos[i]._reliable)); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_next_sn._val._qos[i]._best_effort)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_next_sn._val._qos[i]._reliable)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_next_sn._val._qos[i]._best_effort)); } } else { _Z_DEBUG("Attempted to serialize QoS-SN extension, but the header extension flag was unset"); @@ -85,8 +85,8 @@ int8_t _z_join_decode_ext(_z_msg_ext_t *extension, void *ctx) { msg->_next_sn._is_qos = true; _z_zbuf_t zbf = _z_zbytes_as_zbuf(extension->_body._zbuf._val); for (int i = 0; (ret == _Z_RES_OK) && (i < Z_PRIORITIES_NUM); ++i) { - ret |= _z_zint_decode(&msg->_next_sn._val._qos[i]._reliable, &zbf); - ret |= _z_zint_decode(&msg->_next_sn._val._qos[i]._best_effort, &zbf); + ret |= _z_zsize_decode(&msg->_next_sn._val._qos[i]._reliable, &zbf); + ret |= _z_zsize_decode(&msg->_next_sn._val._qos[i]._best_effort, &zbf); } } else if (_Z_MSG_EXT_IS_MANDATORY(extension->_header)) { ret = _Z_ERR_MESSAGE_EXTENSION_MANDATORY_AND_UNKNOWN; @@ -105,7 +105,7 @@ int8_t _z_join_decode(_z_t_msg_join_t *msg, _z_zbuf_t *zbf, uint8_t header) { ret |= _z_uint8_decode(&cbyte, zbf); msg->_whatami = cbyte & 0x03; - uint8_t zidlen = ((cbyte & 0xF0) >> 4) + 1; + uint8_t zidlen = ((cbyte & 0xF0) >> 4) + (uint8_t)1; msg->_zid = _z_id_empty(); if (ret == _Z_RES_OK) { if (_z_zbuf_len(zbf) >= zidlen) { @@ -128,15 +128,15 @@ int8_t _z_join_decode(_z_t_msg_join_t *msg, _z_zbuf_t *zbf, uint8_t header) { } } if (ret == _Z_RES_OK) { - ret |= _z_zint_decode(&msg->_lease, zbf); + ret |= _z_zsize_decode(&msg->_lease, zbf); if (_Z_HAS_FLAG(header, _Z_FLAG_T_JOIN_T) == true) { msg->_lease = msg->_lease * 1000; } } if (ret == _Z_RES_OK) { msg->_next_sn._is_qos = false; - ret |= _z_zint_decode(&msg->_next_sn._val._plain._reliable, zbf); - ret |= _z_zint_decode(&msg->_next_sn._val._plain._best_effort, zbf); + ret |= _z_zsize_decode(&msg->_next_sn._val._plain._reliable, zbf); + ret |= _z_zsize_decode(&msg->_next_sn._val._plain._best_effort, zbf); } if ((ret == _Z_RES_OK) && _Z_HAS_FLAG(header, _Z_FLAG_T_Z)) { ret |= _z_msg_ext_decode_iter(zbf, _z_join_decode_ext, msg); @@ -187,7 +187,7 @@ int8_t _z_init_decode(_z_t_msg_init_t *msg, _z_zbuf_t *zbf, uint8_t header) { if (ret == _Z_RES_OK) { msg->_whatami = cbyte & 0x03; - uint8_t zidlen = ((cbyte & 0xF0) >> 4) + 1; + uint8_t zidlen = ((cbyte & 0xF0) >> 4) + (uint8_t)1; if (_z_zbuf_len(zbf) >= zidlen) { _z_zbuf_read_bytes(zbf, msg->_zid.id, 0, zidlen); } else { @@ -226,12 +226,12 @@ int8_t _z_open_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_open_t *msg _Z_DEBUG("Encoding _Z_MID_T_OPEN"); if (_Z_HAS_FLAG(header, _Z_FLAG_T_OPEN_T) == true) { - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_lease / 1000)) + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_lease / 1000)) } else { - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_lease)) + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_lease)) } - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_initial_sn)) + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_initial_sn)) if (_Z_HAS_FLAG(header, _Z_FLAG_T_OPEN_A) == false) { _Z_RETURN_IF_ERR(_z_bytes_encode(wbf, &msg->_cookie)) @@ -245,12 +245,12 @@ int8_t _z_open_decode(_z_t_msg_open_t *msg, _z_zbuf_t *zbf, uint8_t header) { int8_t ret = _Z_RES_OK; *msg = (_z_t_msg_open_t){0}; - ret |= _z_zint_decode(&msg->_lease, zbf); + ret |= _z_zsize_decode(&msg->_lease, zbf); if ((ret == _Z_RES_OK) && (_Z_HAS_FLAG(header, _Z_FLAG_T_OPEN_T) == true)) { msg->_lease = msg->_lease * 1000; } - ret |= _z_zint_decode(&msg->_initial_sn, zbf); + ret |= _z_zsize_decode(&msg->_initial_sn, zbf); if ((ret == _Z_RES_OK) && (_Z_HAS_FLAG(header, _Z_FLAG_T_OPEN_A) == false)) { ret |= _z_bytes_decode(&msg->_cookie, zbf); @@ -322,7 +322,7 @@ int8_t _z_keep_alive_decode(_z_t_msg_keep_alive_t *msg, _z_zbuf_t *zbf, uint8_t int8_t _z_frame_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_frame_t *msg) { int8_t ret = _Z_RES_OK; - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_sn)) + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_sn)) if (_Z_HAS_FLAG(header, _Z_FLAG_T_Z)) { ret = _Z_ERR_MESSAGE_SERIALIZATION_FAILED; @@ -341,7 +341,7 @@ int8_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header) { int8_t ret = _Z_RES_OK; *msg = (_z_t_msg_frame_t){0}; - ret |= _z_zint_decode(&msg->_sn, zbf); + ret |= _z_zsize_decode(&msg->_sn, zbf); if ((ret == _Z_RES_OK) && (_Z_HAS_FLAG(header, _Z_FLAG_T_Z) == true)) { ret |= _z_msg_ext_skip_non_mandatories(zbf, 0x04); } @@ -378,7 +378,7 @@ int8_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header) { int8_t _z_fragment_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_fragment_t *msg) { int8_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _Z_TRANSPORT_FRAGMENT"); - _Z_RETURN_IF_ERR(_z_zint_encode(wbf, msg->_sn)) + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_sn)) if (_Z_HAS_FLAG(header, _Z_FLAG_T_Z)) { ret = _Z_ERR_MESSAGE_SERIALIZATION_FAILED; } @@ -394,7 +394,7 @@ int8_t _z_fragment_decode(_z_t_msg_fragment_t *msg, _z_zbuf_t *zbf, uint8_t head *msg = (_z_t_msg_fragment_t){0}; _Z_DEBUG("Decoding _Z_TRANSPORT_FRAGMENT"); - ret |= _z_zint_decode(&msg->_sn, zbf); + ret |= _z_zsize_decode(&msg->_sn, zbf); if ((ret == _Z_RES_OK) && (_Z_HAS_FLAG(header, _Z_FLAG_T_Z) == true)) { ret |= _z_msg_ext_skip_non_mandatories(zbf, 0x05); diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index cd7f562f1..23e1e5f8d 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -336,6 +336,33 @@ void assert_eq_locator_array(const _z_locator_array_t *left, const _z_locator_ar printf(")"); } +/*=============================*/ +/* Zenoh Core Fields */ +/*=============================*/ +void zint(void) { + printf("\n>> ZINT\n"); + _z_wbuf_t wbf = gen_wbuf(9); + + // Initialize + _z_zint_t e_z = gen_zint(); + + // Encode + int8_t res = _z_zsize_encode(&wbf, e_z); + assert(res == _Z_RES_OK); + (void)(res); + + // Decode + _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); + _z_zint_t d_z; + res = _z_zsize_decode(&d_z, &zbf); + assert(res == _Z_RES_OK); + assert(e_z == d_z); + + // Free + _z_zbuf_clear(&zbf); + _z_wbuf_clear(&wbf); +} + /*=============================*/ /* Zenoh Messages Extensions */ /*=============================*/ @@ -1724,6 +1751,9 @@ int main(void) { for (unsigned int i = 0; i < RUNS; i++) { printf("\n\n== RUN %u", i); + // Core + zint(); + // Message fields payload_field(); timestamp_field();