Skip to content

Commit

Permalink
fix: revert payload aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Oct 12, 2024
1 parent b58eb20 commit 4e88a66
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion include/zenoh-pico/collections/slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ static inline _z_slice_t _z_slice_alias(const _z_slice_t bs) {
z_result_t _z_slice_init(_z_slice_t *bs, size_t capacity);
_z_slice_t _z_slice_make(size_t capacity);
_z_slice_t _z_slice_alias_buf(const uint8_t *bs, size_t len);
_z_slice_t _z_slice_alias_non_alloced_slice(_z_slice_t *bs);
_z_slice_t _z_slice_from_buf_custom_deleter(const uint8_t *p, size_t len, _z_delete_context_t dc);
_z_slice_t _z_slice_copy_from_buf(const uint8_t *bs, size_t len);
_z_slice_t _z_slice_steal(_z_slice_t *b);
Expand Down
4 changes: 0 additions & 4 deletions src/collections/slice.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ _z_slice_t _z_slice_alias_buf(const uint8_t *p, size_t len) {
return _z_slice_from_buf_custom_deleter(p, len, _z_delete_context_null());
}

_z_slice_t _z_slice_alias_non_alloced_slice(_z_slice_t *bs) {
return _z_slice_from_buf_custom_deleter(bs->start, bs->len, _z_delete_context_null());
}

_z_slice_t _z_slice_copy_from_buf(const uint8_t *p, size_t len) {
_z_slice_t bs = _z_slice_alias_buf(p, len);
return _z_slice_duplicate(&bs);
Expand Down
6 changes: 5 additions & 1 deletion src/protocol/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ z_result_t _z_slice_decode(_z_slice_t *bs, _z_zbuf_t *zbf) { return _z_slice_dec
z_result_t _z_bytes_decode(_z_bytes_t *bs, _z_zbuf_t *zbf) {
_z_slice_t s;
_Z_RETURN_IF_ERR(_z_slice_decode(&s, zbf));
return _z_bytes_from_slice(bs, s);
if (_z_slice_is_alloced(&s)) {
return _z_bytes_from_slice(bs, s);
} else {
return _z_bytes_from_buf(bs, s.start, s.len);
}
}

z_result_t _z_bytes_encode_val(_z_wbuf_t *wbf, const _z_bytes_t *bs) {
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/codec/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ z_result_t _z_push_body_decode_extensions(_z_msg_ext_t *extension, void *ctx) {
if (_z_slice_is_alloced(&extension->_body._zbuf._val)) {
s = _z_slice_steal(&extension->_body._zbuf._val);
} else {
s = _z_slice_alias_non_alloced_slice(&extension->_body._zbuf._val);
_Z_RETURN_IF_ERR(_z_slice_copy(&s, &extension->_body._zbuf._val));
}
ret = _z_bytes_from_slice(&pshb->_body._put._attachment, s);
break;
Expand Down Expand Up @@ -454,7 +454,7 @@ z_result_t _z_query_decode_extensions(_z_msg_ext_t *extension, void *ctx) {
if (_z_slice_is_alloced(&extension->_body._zbuf._val)) {
s = _z_slice_steal(&extension->_body._zbuf._val);
} else {
s = _z_slice_alias_non_alloced_slice(&extension->_body._zbuf._val);
_Z_RETURN_IF_ERR(_z_slice_copy(&s, &extension->_body._zbuf._val));
}
ret = _z_bytes_from_slice(&msg->_ext_attachment, s);
break;
Expand Down

0 comments on commit 4e88a66

Please sign in to comment.