Skip to content

Commit f0c17b7

Browse files
format
1 parent f36e2e4 commit f0c17b7

File tree

6 files changed

+17
-34
lines changed

6 files changed

+17
-34
lines changed

include/zenoh-pico/api/olv_macros.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,4 @@
160160
// Gets internal value from refcounted owned type (e.g. z_owned_session_t, z_owned_query_t)
161161
#define _Z_OWNED_RC_IN_VAL(arg) ((arg)->_rc.in->val)
162162

163-
164163
#endif /* INCLUDE_ZENOH_PICO_API_OLV_MACROS_H */

include/zenoh-pico/api/primitives.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,11 +928,11 @@ int64_t z_bytes_reader_tell(z_bytes_reader_t *reader);
928928
* Return:
929929
* ``0`` if encode successful, ``negative value`` otherwise.
930930
*/
931-
int8_t z_bytes_get_writer(z_loaned_bytes_t *bytes, z_owned_bytes_writer_t* writer);
931+
int8_t z_bytes_get_writer(z_loaned_bytes_t *bytes, z_owned_bytes_writer_t *writer);
932932

933933
/**
934934
* Writes `len` bytes from `src` into underlying :c:type:`z_loaned_bytes_t.
935-
*
935+
*
936936
* Parameters:
937937
* writer: A data writer
938938
* src: Buffer to write from.

include/zenoh-pico/collections/bytes.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ typedef struct {
9898
_z_bytes_iterator_t _z_bytes_get_iterator(const _z_bytes_t *bytes);
9999
_Bool _z_bytes_iterator_next(_z_bytes_iterator_t *iter, _z_bytes_t *b);
100100

101-
102101
typedef struct {
103-
uint8_t* cache;
102+
uint8_t *cache;
104103
size_t cache_size;
105104
_z_bytes_t *bytes;
106105
} _z_bytes_writer_t;

src/api/api.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,11 @@ _Bool z_bytes_iterator_next(z_bytes_iterator_t *iter, z_owned_bytes_t *bytes) {
493493
return true;
494494
}
495495

496-
int8_t z_bytes_get_writer(z_loaned_bytes_t *bytes, z_owned_bytes_writer_t* writer) {
496+
int8_t z_bytes_get_writer(z_loaned_bytes_t *bytes, z_owned_bytes_writer_t *writer) {
497497
writer->_val = (z_loaned_bytes_writer_t *)z_malloc(sizeof(z_loaned_bytes_writer_t));
498498
if (writer->_val == NULL) return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
499499
*writer->_val = _z_bytes_get_writer(bytes, Z_IOSLICE_SIZE);
500-
return _Z_RES_OK;
500+
return _Z_RES_OK;
501501
}
502502

503503
int8_t z_bytes_writer_write(z_loaned_bytes_writer_t *writer, const uint8_t *src, size_t len) {
@@ -607,7 +607,6 @@ _Z_OWNED_FUNCTIONS_PTR_IMPL(_z_slice_t, slice, _z_slice_copy, _z_slice_free)
607607
_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_bytes_t, bytes, _z_bytes_copy, _z_bytes_free)
608608
_Z_OWNED_FUNCTIONS_PTR_TRIVIAL_IMPL(_z_bytes_writer_t, bytes_writer)
609609

610-
611610
#if Z_FEATURE_PUBLICATION == 1 || Z_FEATURE_QUERYABLE == 1 || Z_FEATURE_QUERY == 1
612611
// Convert a user owned bytes payload to an internal bytes payload, returning an empty one if value invalid
613612
static _z_bytes_t _z_bytes_from_owned_bytes(z_owned_bytes_t *bytes) {

src/collections/bytes.c

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
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

438432
int8_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

465456
int8_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
}
497485
int8_t _z_bytes_iterator_writer_write(_z_bytes_iterator_writer_t *writer, _z_bytes_t *src) {
498486
uint8_t l_buf[16];

tests/z_bytes_test.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ void test_reader_seek(void) {
161161
_z_bytes_drop(&b);
162162
}
163163

164-
165164
void test_writer_no_cache(void) {
166165
uint8_t data1[5] = {1, 2, 3, 4, 5};
167166
uint8_t data2[5] = {1, 2, 6, 7, 8};
@@ -190,7 +189,7 @@ void test_writer_with_cache(void) {
190189
uint8_t data1[5] = {1, 2, 3, 4, 5};
191190
uint8_t data2[5] = {1, 2, 6, 7, 8};
192191
uint8_t data3[3] = {3, 9, 10};
193-
192+
194193
uint8_t data1_out[7] = {1, 2, 3, 4, 5, 1, 2};
195194
uint8_t data2_out[6] = {6, 7, 8, 3, 9, 10};
196195
_z_bytes_t b = _z_bytes_null();
@@ -213,7 +212,6 @@ void test_writer_with_cache(void) {
213212
_z_bytes_drop(&b);
214213
}
215214

216-
217215
int main(void) {
218216
test_null_bytes();
219217
test_slice();

0 commit comments

Comments
 (0)