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

Add documentation about bytes reader/writer #724

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
60 changes: 60 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,66 @@ See details at :ref:`owned_types_concept`
.. c:function:: const z_loaned_keyexpr_t * z_keyexpr_loan(const z_owned_keyexpr_t * keyexpr)
.. c:function:: z_loaned_keyexpr_t * z_keyexpr_loan_mut(z_owned_keyexpr_t * keyexpr)

Payload
-------

Types
^^^^^

see details at :ref:`owned_types_concept`

.. c:type:: z_owned_bytes_t
.. c:type:: z_loaned_bytes_t
.. c:type:: z_moved_bytes_t

.. c:type:: z_owned_bytes_writter_t
.. c:type:: z_loaned_bytes_writter_t
.. c:type:: z_moved_bytes_writter_t

.. autoctype:: types.h::z_bytes_reader_t

Functions
^^^^^^^^^
.. autocfunction:: primitives.h::z_bytes_empty
.. autocfunction:: primitives.h::z_bytes_len
.. autocfunction:: primitives.h::z_bytes_from_buf
.. autocfunction:: primitives.h::z_bytes_from_slice
.. autocfunction:: primitives.h::z_bytes_from_static_buf
.. autocfunction:: primitives.h::z_bytes_from_static_str
.. autocfunction:: primitives.h::z_bytes_from_str
.. autocfunction:: primitives.h::z_bytes_from_string
.. autocfunction:: primitives.h::z_bytes_copy_from_buf
.. autocfunction:: primitives.h::z_bytes_copy_from_slice
.. autocfunction:: primitives.h::z_bytes_copy_from_str
.. autocfunction:: primitives.h::z_bytes_copy_from_string
.. autocfunction:: primitives.h::z_bytes_to_slice
.. autocfunction:: primitives.h::z_bytes_to_string

.. autocfunction:: primitives.h::z_bytes_get_reader
.. autocfunction:: primitives.h::z_bytes_reader_read
.. autocfunction:: primitives.h::z_bytes_reader_remaining
.. autocfunction:: primitives.h::z_bytes_reader_seek
.. autocfunction:: primitives.h::z_bytes_reader_tell

.. autocfunction:: primitives.h::z_bytes_writer_append
.. autocfunction:: primitives.h::z_bytes_writer_empty
.. autocfunction:: primitives.h::z_bytes_writer_finish
.. autocfunction:: primitives.h::z_bytes_writer_write_all

Ownership Functions
^^^^^^^^^^^^^^^^^^^

See details at :ref:`owned_types_concept`

.. c:function:: void z_bytes_drop(z_moved_bytes_t * bytes)
.. c:function:: void z_bytes_clone(z_owned_bytes_t * dst, const z_loaned_bytes_t * bytes)
.. c:function:: const z_loaned_bytes_t * z_bytes_loan(const z_owned_bytes_t * bytes)
.. c:function:: z_loaned_bytes_t * z_bytes_loan_mut(z_owned_bytes_t * bytes)

.. c:function:: void z_bytes_writer_drop(z_moved_bytes_writer_t * bytes_writer)
.. c:function:: void z_bytes_writer_clone(z_owned_bytes_writer_t * dst, const z_loaned_bytes_writer_t * bytes_writer)
.. c:function:: const z_loaned_bytes_writer_t * z_bytes_writer_loan(const z_owned_bytes_writer_t * bytes_writer)
.. c:function:: z_loaned_bytes_writer_t * z_bytes_writer_loan_mut(z_owned_bytes_writer_t * bytes_writer)

Encoding
--------
Expand Down
12 changes: 8 additions & 4 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ z_result_t z_bytes_from_str(z_owned_bytes_t *bytes, char *value, void (*deleter)
* ``0`` if conversion is successful, ``negative value`` otherwise.
*/
z_result_t z_bytes_copy_from_str(z_owned_bytes_t *bytes, const char *value);

/**
* Converts a statically allocated constant null-terminated string into a :c:type:`z_owned_bytes_t` by aliasing.
*
Expand All @@ -655,8 +656,10 @@ z_result_t z_bytes_copy_from_str(z_owned_bytes_t *bytes, const char *value);
z_result_t z_bytes_from_static_str(z_owned_bytes_t *bytes, const char *value);

/**
* Constructs an empty payload.
*
* Parameters:
* bytes: Pointer to an unitialized :c:type:`z_lowned_bytes_t` instance.
* bytes: Pointer to an unitialized :c:type:`z_loaned_bytes_t` instance.
*/
void z_bytes_empty(z_owned_bytes_t *bytes);

Expand Down Expand Up @@ -747,9 +750,10 @@ size_t z_bytes_reader_read(z_bytes_reader_t *reader, uint8_t *dst, size_t len);
* origin: Origin for the new position.
*
* Return:
* ``0`` upon success, negative error code otherwise.
* ``0`` in case of success, ``negative value`` otherwise.
*/
z_result_t z_bytes_reader_seek(z_bytes_reader_t *reader, int64_t offset, int origin);

/**
* Gets the read position indicator.
*
Expand Down Expand Up @@ -793,7 +797,7 @@ z_result_t z_bytes_writer_empty(z_owned_bytes_writer_t *writer);
void z_bytes_writer_finish(z_moved_bytes_writer_t *writer, z_owned_bytes_t *bytes);

/**
* Writes `len` bytes from `src` into underlying :c:type:`z_loaned_bytes_t.
* Writes `len` bytes from `src` into underlying :c:type:`z_loaned_bytes_t`.
*
* Parameters:
* writer: A data writer.
Expand All @@ -815,7 +819,7 @@ z_result_t z_bytes_writer_write_all(z_loaned_bytes_writer_t *writer, const uint8
* bytes: A data to append.
*
* Return:
* ``0`` in case of success, negative error code otherwise
* ``0`` if write is successful, ``negative value`` otherwise.
*/
z_result_t z_bytes_writer_append(z_loaned_bytes_writer_t *writer, z_moved_bytes_t *bytes);

Expand Down
Loading