1818#include <stdio.h>
1919#include <string.h>
2020
21+ #include "zenoh-pico/api/olv_macros.h"
2122#include "zenoh-pico/protocol/codec/core.h"
2223#include "zenoh-pico/system/platform.h"
2324#include "zenoh-pico/utils/endianness.h"
2425#include "zenoh-pico/utils/result.h"
25- #include "zenoh-pico/api/olv_macros.h"
2626
2727/*-------- Bytes --------*/
2828_Bool _z_bytes_check (const _z_bytes_t * bytes ) { return !_z_bytes_is_empty (bytes ); }
@@ -133,11 +133,9 @@ int8_t _z_bytes_to_slice(const _z_bytes_t *bytes, _z_slice_t *s) {
133133 return _Z_RES_OK ;
134134}
135135
136- int8_t _z_bytes_append_slice (_z_bytes_t * dst , _z_arc_slice_t * s ) {
137- _Z_CLEAN_RETURN_IF_ERR (
138- _z_arc_slice_svec_append (& dst -> _slices , s ) ? _Z_RES_OK : _Z_ERR_SYSTEM_OUT_OF_MEMORY ,
139- _z_arc_slice_drop (s )
140- );
136+ int8_t _z_bytes_append_slice (_z_bytes_t * dst , _z_arc_slice_t * s ) {
137+ _Z_CLEAN_RETURN_IF_ERR (_z_arc_slice_svec_append (& dst -> _slices , s ) ? _Z_RES_OK : _Z_ERR_SYSTEM_OUT_OF_MEMORY ,
138+ _z_arc_slice_drop (s ));
141139 return _Z_RES_OK ;
142140}
143141
@@ -428,11 +426,7 @@ _Bool _z_bytes_iterator_next(_z_bytes_iterator_t *iter, _z_bytes_t *b) {
428426}
429427
430428_z_bytes_writer_t _z_bytes_get_writer (_z_bytes_t * bytes , size_t cache_size ) {
431- return (_z_bytes_writer_t ) {
432- .cache = NULL ,
433- .cache_size = cache_size ,
434- .bytes = bytes
435- };
429+ return (_z_bytes_writer_t ){.cache = NULL , .cache_size = cache_size , .bytes = bytes };
436430}
437431
438432int8_t _z_bytes_writer_ensure_cache (_z_bytes_writer_t * writer ) {
@@ -454,27 +448,24 @@ int8_t _z_bytes_writer_ensure_cache(_z_bytes_writer_t *writer) {
454448 return _Z_ERR_SYSTEM_OUT_OF_MEMORY ;
455449 }
456450
457- _Z_CLEAN_RETURN_IF_ERR (
458- _z_bytes_append_slice (writer -> bytes , & cache ),
459- _z_arc_slice_drop (& cache )
460- );
461- writer -> cache = (uint8_t * )_Z_RC_IN_VAL (& cache .slice ).start ;
451+ _Z_CLEAN_RETURN_IF_ERR (_z_bytes_append_slice (writer -> bytes , & cache ), _z_arc_slice_drop (& cache ));
452+ writer -> cache = (uint8_t * )_Z_RC_IN_VAL (& cache .slice ).start ;
462453 return _Z_RES_OK ;
463454}
464455
465456int8_t _z_bytes_writer_write (_z_bytes_writer_t * writer , const uint8_t * src , size_t len ) {
466- if (writer -> cache_size == 0 ) { // no cache append data as a single slice
457+ if (writer -> cache_size == 0 ) { // no cache append data as a single slice
467458 _z_slice_t s = _z_slice_wrap_copy (src , len );
468459 if (s .len != len ) return _Z_ERR_SYSTEM_OUT_OF_MEMORY ;
469460 _z_arc_slice_t arc_s = _z_arc_slice_wrap (s , 0 , len );
470- if _Z_RC_IS_NULL (& arc_s .slice ) {
461+ if _Z_RC_IS_NULL (& arc_s .slice ) {
471462 _z_slice_clear (& s );
472463 return _Z_ERR_SYSTEM_OUT_OF_MEMORY ;
473464 }
474465 return _z_bytes_append_slice (writer -> bytes , & arc_s );
475466 }
476467
477- while (len > 0 ) {
468+ while (len > 0 ) {
478469 _Z_RETURN_IF_ERR (_z_bytes_writer_ensure_cache (writer ));
479470 _z_arc_slice_t * arc_s = _z_bytes_get_slice (writer -> bytes , _z_bytes_num_slices (writer -> bytes ) - 1 );
480471 size_t remaining_in_cache = _Z_RC_IN_VAL (& arc_s -> slice ).len - arc_s -> len ;
@@ -488,11 +479,8 @@ int8_t _z_bytes_writer_write(_z_bytes_writer_t *writer, const uint8_t *src, size
488479 return _Z_RES_OK ;
489480}
490481
491-
492482_z_bytes_iterator_writer_t _z_bytes_get_iterator_writer (_z_bytes_t * bytes ) {
493- return (_z_bytes_iterator_writer_t ){
494- .writer = _z_bytes_get_writer (bytes , 0 )
495- };
483+ return (_z_bytes_iterator_writer_t ){.writer = _z_bytes_get_writer (bytes , 0 )};
496484}
497485int8_t _z_bytes_iterator_writer_write (_z_bytes_iterator_writer_t * writer , _z_bytes_t * src ) {
498486 uint8_t l_buf [16 ];
0 commit comments