Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-slice bytes support #439

Merged
merged 27 commits into from
Jun 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
58a73de
wip
DenisBiryukov91 Jun 20, 2024
eaff4a2
bytes tests and fixes
DenisBiryukov91 Jun 21, 2024
99abc68
merge
DenisBiryukov91 Jun 24, 2024
61afacc
warning fixes
DenisBiryukov91 Jun 24, 2024
ed88be7
use new zz_bytes on user side
DenisBiryukov91 Jun 24, 2024
38cbee0
rename zz_bytes -> z_bytes
DenisBiryukov91 Jun 24, 2024
f04f702
merge
DenisBiryukov91 Jun 24, 2024
b955bd0
Merge branch 'dev/fix_bytes' into dev/multi_slice_bytes
DenisBiryukov91 Jun 24, 2024
efdad63
fmt
DenisBiryukov91 Jun 24, 2024
b175b35
fixes
DenisBiryukov91 Jun 25, 2024
ea30ca1
fixes
DenisBiryukov91 Jun 25, 2024
5f8e54f
fixed svec implementation;
DenisBiryukov91 Jun 25, 2024
13d2224
fixe _z_sample_create signature
DenisBiryukov91 Jun 25, 2024
cd95ad2
fix _z_trigger_local_subscriptions signature
DenisBiryukov91 Jun 25, 2024
c673cd4
fix attachment examples
DenisBiryukov91 Jun 25, 2024
acc3f59
fixed uninitialized owned_bytes pointer
DenisBiryukov91 Jun 26, 2024
c33bf76
added z_bytes_len and z_bytes_is_empty functions; updated docs
DenisBiryukov91 Jun 26, 2024
1c20290
exposed z_bytes_reader_t
DenisBiryukov91 Jun 26, 2024
00f9577
remove _Z_DO_AND_RETURN_IF_ERR since _Z_CLEAN_RETURN_IF_ERR does the …
DenisBiryukov91 Jun 27, 2024
57e2022
serialization fixes
DenisBiryukov91 Jun 27, 2024
baf0d00
ensure that decoded z_bytes never contanin non-_is_alloc slice
DenisBiryukov91 Jun 27, 2024
f36e2e4
added z_bytes_writer implementation
DenisBiryukov91 Jun 27, 2024
f0c17b7
format
DenisBiryukov91 Jun 27, 2024
1bb55e5
fixed attachments
DenisBiryukov91 Jun 27, 2024
6c1cc65
use _ZP_UNUSED instead of (void)(...)
DenisBiryukov91 Jun 27, 2024
8cb3ef0
fixed _z_bytes_reader_read return value;
DenisBiryukov91 Jun 27, 2024
4ac44f8
Merge branch 'dev/1.0.0' into dev/multi_slice_bytes
DenisBiryukov91 Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
exposed z_bytes_reader_t
DenisBiryukov91 committed Jun 26, 2024

Verified

This commit was signed with the committer’s verified signature.
derekcollison Derek Collison
commit 1c202904c86129846379c5510950e2bd73426811
5 changes: 5 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ Data Structures
.. autoctype:: types.h::zp_send_keep_alive_options_t
.. autoctype:: types.h::zp_send_join_options_t
.. autoctype:: types.h::z_qos_t
.. autoctype:: types.h::z_bytes_reader_t
.. autoctype:: types.h::z_bytes_iterator_t


@@ -327,6 +328,10 @@ Primitives
.. autocfunction:: primitives.h::z_bytes_is_empty
.. autocfunction:: primitives.h::z_bytes_get_iterator
.. autocfunction:: primitives.h::z_bytes_iterator_next
.. autocfunction:: primitives.h::z_bytes_get_reader
.. autocfunction:: primitives.h::z_bytes_reader_read
.. autocfunction:: primitives.h::z_bytes_reader_seek
.. autocfunction:: primitives.h::z_bytes_reader_tell
.. autocfunction:: primitives.h::z_timestamp_check
.. autocfunction:: primitives.h::z_query_target_default
.. autocfunction:: primitives.h::z_query_consolidation_auto
79 changes: 71 additions & 8 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
@@ -824,6 +824,26 @@ int8_t z_bytes_serialize_from_pair(z_owned_bytes_t *bytes, z_owned_bytes_t *firs
*/
int8_t z_bytes_empty(z_owned_bytes_t *bytes);

/**
* Returns total number of bytes in the container.
*
* Parameters:
* bytes: Pointer to a :c:type:`z_loaned_bytes_t` to decode.
* Return:
* Number of bytes in the container.
*/
size_t z_bytes_len(const z_loaned_bytes_t *bytes);

/**
* Checks if container is empty
*
* Parameters:
* bytes: Pointer to a :c:type:`z_loaned_bytes_t` to decode.
* Return:
* ``true`` if conainer is empty, ``false`` otherwise.
*/
_Bool z_bytes_is_empty(const z_loaned_bytes_t *bytes);

/**
* Returns an iterator for multi-element serialized data.
*
@@ -849,24 +869,67 @@ z_bytes_iterator_t z_bytes_get_iterator(const z_loaned_bytes_t *bytes);
_Bool z_bytes_iterator_next(z_bytes_iterator_t *iter, z_owned_bytes_t *out);

/**
* Returns total number of bytes in the container.
* Returns a reader for the `bytes`.
*
* The `bytes` should outlive the reader and should not be modified, while reader is in use.
*
* Parameters:
* bytes: Pointer to a :c:type:`z_loaned_bytes_t` to decode.
* bytes: Data to read.
*
* Return:
* Number of bytes in the container.
* The constructed :c:type:`z_bytes_reader_t`.
*/
size_t z_bytes_len(const z_loaned_bytes_t *bytes);
z_bytes_reader_t z_bytes_get_reader(const z_loaned_bytes_t *bytes);

/**
* Checks if container is empty
* Reads data into specified destination.
*
* Parameters:
* bytes: Pointer to a :c:type:`z_loaned_bytes_t` to decode.
* reader: Data reader to read from.
* dst: Buffer where the read data is written.
* len: Maximum number of bytes to read.
*
* Return:
* ``true`` if conainer is empty, ``false`` otherwise.
* Number of bytes read. If return value is smaller than `len`, it means that the end of the data was reached.
*/
_Bool z_bytes_is_empty(const z_loaned_bytes_t *bytes);
size_t z_bytes_reader_read(z_bytes_reader_t *reader, uint8_t *dst, size_t len);
/**
* Sets the `reader` position indicator for the payload to the value pointed to by offset.
* The new position is exactly `offset` bytes measured from the beginning of the payload if origin is `SEEK_SET`,
* from the current reader position if origin is `SEEK_CUR`, and from the end of the payload if origin is `SEEK_END`.
*
* Parameters:
* reader: Data reader to reposition.
* offset: New position ffset in bytes.
* origin: Origin for the new position.
*
* Return:
* ​0​ upon success, negative error code otherwise.
*/
int8_t z_bytes_reader_seek(z_bytes_reader_t *reader, int64_t offset, int origin);
/**
* Gets the read position indicator.
*
* Parameters:
* reader: Data reader to get position of.
*
* Return:
* Read position indicator on success or -1L if failure occurs.
*/
int64_t z_bytes_reader_tell(z_bytes_reader_t *reader);

/**
* Constructs :c:type:`z_owned_bytes_t` object corresponding to the next element of serialized data.
*
* Will construct null-state `z_owned_bytes_t` when iterator reaches the end (or in case of error).
*
* Parameters:
* iter: An iterator over multi-element serialized data.
* out: An uninitialized :c:type:`z_owned_bytes_t` that will contained next serialized element.
* Return:
* ``false`` when iterator reaches the end, ``true`` otherwise.
*/
_Bool z_bytes_iterator_next(z_bytes_iterator_t *iter, z_owned_bytes_t *out);

/**
* Checks validity of a timestamp
5 changes: 5 additions & 0 deletions include/zenoh-pico/api/types.h
Original file line number Diff line number Diff line change
@@ -80,6 +80,11 @@ _Z_LOANED_TYPE(_z_bytes_t, bytes)
*/
typedef _z_bytes_iterator_t z_bytes_iterator_t;

/**
* A reader for serialized data.
*/
typedef _z_bytes_reader_t z_bytes_reader_t;

/**
* Represents a string without null-terminator.
*
12 changes: 12 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
@@ -476,6 +476,18 @@ size_t z_bytes_len(const z_loaned_bytes_t *bytes) { return _z_bytes_len(bytes);

_Bool z_bytes_is_empty(const z_loaned_bytes_t *bytes) { return _z_bytes_is_empty(bytes); }

z_bytes_reader_t z_bytes_get_reader(const z_loaned_bytes_t *bytes) { return _z_bytes_get_reader(bytes); }

size_t z_bytes_reader_read(z_bytes_reader_t *reader, uint8_t *dst, size_t len) {
return _z_bytes_reader_read(reader, dst, len);
}

int8_t z_bytes_reader_seek(z_bytes_reader_t *reader, int64_t offset, int origin) {
return _z_bytes_reader_seek(reader, offset, origin);
}

int64_t z_bytes_reader_tell(z_bytes_reader_t *reader) { return _z_bytes_reader_tell(reader); }

z_bytes_iterator_t z_bytes_get_iterator(const z_loaned_bytes_t *bytes) { return _z_bytes_get_iterator(bytes); }

_Bool z_bytes_iterator_next(z_bytes_iterator_t *iter, z_owned_bytes_t *bytes) {