diff --git a/examples/arduino/z_get.ino b/examples/arduino/z_get.ino index 538618475..a4a5a9f2d 100644 --- a/examples/arduino/z_get.ino +++ b/examples/arduino/z_get.ino @@ -119,7 +119,7 @@ void loop() { if (strcmp(VALUE, "") != 0) { z_view_string_t value_str; z_view_string_wrap(&value_str, VALUE); - z_owned_slice_t payload; + z_owned_bytes_t payload; z_bytes_encode_from_string(&payload, z_view_string_loan(&value_str)); opts.payload = &payload; } diff --git a/examples/arduino/z_queryable.ino b/examples/arduino/z_queryable.ino index 7fe9136e7..da225a613 100644 --- a/examples/arduino/z_queryable.ino +++ b/examples/arduino/z_queryable.ino @@ -43,8 +43,8 @@ void query_handler(const z_loaned_query_t *query, void *arg) { Serial.println("'"); // Process value - const z_loaned_slice_t *payload = z_value_payload(z_query_value(query)); - if (z_slice_len(payload) > 0) { + const z_loaned_bytes_t *payload = z_value_payload(z_query_value(query)); + if (z_bytes_len(payload) > 0) { z_owned_string_t payload_string; z_bytes_decode_into_string(payload, &payload_string); Serial.print(" with value '"); @@ -59,10 +59,10 @@ void query_handler(const z_loaned_query_t *query, void *arg) { // Reply value encoding z_view_string_t reply_str; z_view_string_wrap(&reply_str, VALUE); - z_owned_slice_t reply_payload; + z_owned_bytes_t reply_payload; z_bytes_encode_from_string(&reply_payload, z_view_string_loan(&reply_str)); - z_query_reply(query, z_view_keyexpr_loan(&ke), z_slice_move(&reply_payload), NULL); + z_query_reply(query, z_view_keyexpr_loan(&ke), z_bytes_move(&reply_payload), NULL); z_string_drop(z_string_move(&keystr)); } diff --git a/examples/arduino/z_sub.ino b/examples/arduino/z_sub.ino index 5f364982d..8104e574e 100644 --- a/examples/arduino/z_sub.ino +++ b/examples/arduino/z_sub.ino @@ -37,8 +37,8 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) { z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t *slice = z_sample_payload(sample); - std::string val((const char *)z_slice_data(slice), z_slice_len(slice)); + const z_loaned_bytes_t *payload = z_sample_payload(sample); + std::string val((const char *)z_bytes_data(payload), z_bytes_len(payload)); Serial.print(" >> [Subscription listener] Received ("); Serial.print(z_string_data(z_string_loan(&keystr))); diff --git a/examples/espidf/z_get.c b/examples/espidf/z_get.c index 92369753a..7c53b86b5 100644 --- a/examples/espidf/z_get.c +++ b/examples/espidf/z_get.c @@ -166,7 +166,7 @@ void app_main() { if (strcmp(VALUE, "") != 0) { z_view_string_t value_str; z_view_string_wrap(&value_str, VALUE); - z_owned_slice_t payload; + z_owned_bytes_t payload; z_bytes_encode_from_string(&payload, z_loan(value_str)); opts.payload = &payload; } diff --git a/examples/espidf/z_queryable.c b/examples/espidf/z_queryable.c index 59f63968f..d10e25f57 100644 --- a/examples/espidf/z_queryable.c +++ b/examples/espidf/z_queryable.c @@ -110,8 +110,8 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_string_data(z_loan(keystr)), (int)z_loan(params)->len, z_loan(params)->val); // Process value - const z_loaned_slice_t *payload = z_value_payload(z_query_value(query)); - if (z_slice_len(payload) > 0) { + const z_loaned_bytes_t *payload = z_value_payload(z_query_value(query)); + if (z_bytes_len(payload) > 0) { z_owned_string_t payload_string; z_bytes_decode_into_string(payload, &payload_string); printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); @@ -122,7 +122,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { // Reply value encoding z_view_string_t reply_str; z_view_string_wrap(&reply_str, VALUE); - z_owned_slice_t reply_payload; + z_owned_bytes_t reply_payload; z_bytes_encode_from_string(&reply_payload, z_loan(reply_str)); z_query_reply(query, z_loan(ke), z_move(reply_payload), NULL); diff --git a/examples/espidf/z_sub.c b/examples/espidf/z_sub.c index 20760782b..07e2efec8 100644 --- a/examples/espidf/z_sub.c +++ b/examples/espidf/z_sub.c @@ -103,9 +103,9 @@ void wifi_init_sta(void) { void data_handler(const z_loaned_sample_t* sample, void* arg) { z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t* payload = z_sample_payload(sample); + const z_loaned_bytes_t* payload = z_sample_payload(sample); printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_string_data(z_string_loan(&keystr)), - (int)z_slice_len(payload), z_slice_data(payload)); + (int)z_bytes_len(payload), z_bytes_data(payload)); z_string_drop(z_string_move(&keystr)); } diff --git a/examples/freertos_plus_tcp/z_get.c b/examples/freertos_plus_tcp/z_get.c index 80d0c6603..d91bb6065 100644 --- a/examples/freertos_plus_tcp/z_get.c +++ b/examples/freertos_plus_tcp/z_get.c @@ -90,7 +90,7 @@ void app_main(void) { if (strcmp(VALUE, "") != 0) { z_view_string_t value_str; z_view_string_wrap(&value_str, VALUE); - z_owned_slice_t payload; + z_owned_bytes_t payload; z_bytes_encode_from_string(&payload, z_loan(value_str)); opts.payload = &payload; } diff --git a/examples/freertos_plus_tcp/z_queryable.c b/examples/freertos_plus_tcp/z_queryable.c index eff0b376c..ca3444034 100644 --- a/examples/freertos_plus_tcp/z_queryable.c +++ b/examples/freertos_plus_tcp/z_queryable.c @@ -38,8 +38,8 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_string_data(z_loan(keystr)), (int)z_loan(params)->len, z_loan(params)->val); // Process value - const z_loaned_slice_t *payload = z_value_payload(z_query_value(query)); - if (z_slice_len(payload) > 0) { + const z_loaned_bytes_t *payload = z_value_payload(z_query_value(query)); + if (z_bytes_len(payload) > 0) { z_owned_string_t payload_string; z_bytes_decode_into_string(payload, &payload_string); printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); @@ -50,7 +50,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { // Reply value encoding z_view_string_t reply_str; z_view_string_wrap(&reply_str, VALUE); - z_owned_slice_t reply_payload; + z_owned_bytes_t reply_payload; z_bytes_encode_from_string(&reply_payload, z_loan(reply_str)); z_query_reply(query, z_query_keyexpr(query), z_move(reply_payload), &options); diff --git a/examples/freertos_plus_tcp/z_sub.c b/examples/freertos_plus_tcp/z_sub.c index 0cbe58085..e44b27f14 100644 --- a/examples/freertos_plus_tcp/z_sub.c +++ b/examples/freertos_plus_tcp/z_sub.c @@ -32,9 +32,9 @@ void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(sample); - printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_slice_len(payload), - z_slice_data(payload)); + const z_loaned_bytes_t *payload = z_sample_payload(sample); + printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_bytes_len(payload), + z_bytes_data(payload)); z_drop(z_move(keystr)); } diff --git a/examples/freertos_plus_tcp/z_sub_st.c b/examples/freertos_plus_tcp/z_sub_st.c index 07f80fd8a..13212ff1c 100644 --- a/examples/freertos_plus_tcp/z_sub_st.c +++ b/examples/freertos_plus_tcp/z_sub_st.c @@ -35,9 +35,9 @@ void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(sample); - printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_slice_len(payload), - z_slice_data(payload)); + const z_loaned_bytes_t *payload = z_sample_payload(sample); + printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_bytes_len(payload), + z_bytes_data(payload)); z_drop(z_move(keystr)); z_drop(z_move(keystr)); msg_nb++; diff --git a/examples/mbed/z_get.cpp b/examples/mbed/z_get.cpp index ce3f2f530..ec2f2cef5 100644 --- a/examples/mbed/z_get.cpp +++ b/examples/mbed/z_get.cpp @@ -87,7 +87,7 @@ int main(int argc, char **argv) { if (strcmp(VALUE, "") != 0) { z_view_string_t value_str; z_view_string_wrap(&value_str, VALUE); - z_owned_slice_t payload; + z_owned_bytes_t payload; z_bytes_encode_from_string(&payload, z_view_string_loan(&value_str)); opts.payload = &payload; } diff --git a/examples/mbed/z_queryable.cpp b/examples/mbed/z_queryable.cpp index bc8dd3e04..7be7f79da 100644 --- a/examples/mbed/z_queryable.cpp +++ b/examples/mbed/z_queryable.cpp @@ -40,8 +40,8 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_string_data(z_string_loan(&keystr)), (int)z_view_string_loan(&pred)->len, z_view_string_loan(&pred)->val); // Process value - const z_loaned_slice_t *payload = z_value_payload(z_query_value(query)); - if (z_slice_len(payload) > 0) { + const z_loaned_bytes_t *payload = z_value_payload(z_query_value(query)); + if (z_bytes_len(payload) > 0) { z_owned_string_t payload_string; z_bytes_decode_into_string(payload, &payload_string); printf(" with value '%s'\n", z_string_data(z_string_loan(&payload_string))); @@ -50,10 +50,10 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { // Reply value encoding z_view_string_t reply_str; z_view_string_wrap(&reply_str, VALUE); - z_owned_slice_t reply_payload; + z_owned_bytes_t reply_payload; z_bytes_encode_from_string(&reply_payload, z_view_string_loan(&reply_str)); - z_query_reply(query, z_query_keyexpr(query), z_slice_move(&reply_payload), NULL); + z_query_reply(query, z_query_keyexpr(query), z_bytes_move(&reply_payload), NULL); z_string_drop(z_string_move(&keystr)); } diff --git a/examples/mbed/z_sub.cpp b/examples/mbed/z_sub.cpp index 72a24e413..99325653e 100644 --- a/examples/mbed/z_sub.cpp +++ b/examples/mbed/z_sub.cpp @@ -33,9 +33,9 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) { z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(sample); + const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_string_data(z_string_loan(&keystr)), - (int)z_slice_len(payload), z_slice_data(payload)); + (int)z_bytes_len(payload), z_bytes_data(payload)); z_string_drop(z_string_move(&keystr)); } diff --git a/examples/unix/c11/z_get_channel.c b/examples/unix/c11/z_get_channel.c index 0c95a9b78..e2eef163c 100644 --- a/examples/unix/c11/z_get_channel.c +++ b/examples/unix/c11/z_get_channel.c @@ -94,7 +94,7 @@ int main(int argc, char **argv) { if (value != NULL) { z_view_string_t value_str; z_view_string_wrap(&value_str, value); - z_owned_slice_t payload; + z_owned_bytes_t payload; z_bytes_encode_from_string(&payload, z_loan(value_str)); opts.payload = &payload; } diff --git a/examples/unix/c11/z_pong.c b/examples/unix/c11/z_pong.c index c69bf9e74..62b083e14 100644 --- a/examples/unix/c11/z_pong.c +++ b/examples/unix/c11/z_pong.c @@ -18,8 +18,8 @@ #if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 void callback(const z_loaned_sample_t* sample, void* context) { const z_loaned_publisher_t* pub = z_loan(*(z_owned_publisher_t*)context); - const z_loaned_slice_t* payload = z_sample_payload(sample); - z_publisher_put(pub, z_slice_data(payload), z_slice_len(payload), NULL); + const z_loaned_bytes_t* payload = z_sample_payload(sample); + z_publisher_put(pub, z_bytes_data(payload), z_bytes_len(payload), NULL); } void drop(void* context) { z_owned_publisher_t* pub = (z_owned_publisher_t*)context; diff --git a/examples/unix/c11/z_pull.c b/examples/unix/c11/z_pull.c index 61513423d..29bb3f1ef 100644 --- a/examples/unix/c11/z_pull.c +++ b/examples/unix/c11/z_pull.c @@ -90,9 +90,9 @@ int main(int argc, char **argv) { for (z_call(channel.try_recv, &sample); z_check(sample); z_call(channel.try_recv, &sample)) { z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(z_loan(sample)), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(z_loan(sample)); - printf(">> [Subscriber] Pulled ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_slice_len(payload), - z_slice_data(payload)); + const z_loaned_bytes_t *payload = z_sample_payload(z_loan(sample)); + printf(">> [Subscriber] Pulled ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_bytes_len(payload), + z_bytes_data(payload)); z_drop(z_move(keystr)); z_drop(z_move(sample)); } diff --git a/examples/unix/c11/z_queryable.c b/examples/unix/c11/z_queryable.c index 5bf18e5b0..73ee65683 100644 --- a/examples/unix/c11/z_queryable.c +++ b/examples/unix/c11/z_queryable.c @@ -41,7 +41,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { z_loan(params)->val); // Process value const z_loaned_bytes_t *payload = z_value_payload(z_query_value(query)); - if (z_slice_len(payload) > 0) { + if (z_bytes_len(payload) > 0) { z_owned_string_t payload_string; z_bytes_decode_into_string(payload, &payload_string); printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); @@ -73,7 +73,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { // Reply value encoding z_view_string_t reply_str; z_view_string_wrap(&reply_str, value); - z_owned_slice_t reply_payload; + z_owned_bytes_t reply_payload; z_bytes_encode_from_string(&reply_payload, z_loan(reply_str)); z_query_reply(query, z_query_keyexpr(query), z_move(reply_payload), &options); diff --git a/examples/unix/c11/z_queryable_channel.c b/examples/unix/c11/z_queryable_channel.c index b21727c61..05091d334 100644 --- a/examples/unix/c11/z_queryable_channel.c +++ b/examples/unix/c11/z_queryable_channel.c @@ -106,8 +106,8 @@ int main(int argc, char **argv) { z_query_parameters(q, ¶ms); printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_string_data(z_loan(keystr)), (int)z_loan(params)->len, z_loan(params)->val); - const z_loaned_slice_t *payload = z_value_payload(z_query_value(z_loan(query))); - if (z_slice_len(payload) > 0) { + const z_loaned_bytes_t *payload = z_value_payload(z_query_value(z_loan(query))); + if (z_bytes_len(payload) > 0) { z_owned_string_t payload_string; z_bytes_decode_into_string(payload, &payload_string); printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); @@ -118,7 +118,7 @@ int main(int argc, char **argv) { // Reply value encoding z_view_string_t reply_str; z_view_string_wrap(&reply_str, value); - z_owned_slice_t reply_payload; + z_owned_bytes_t reply_payload; z_bytes_encode_from_string(&reply_payload, z_loan(reply_str)); z_query_reply(q, z_query_keyexpr(q), z_move(reply_payload), &options); diff --git a/examples/unix/c11/z_sub.c b/examples/unix/c11/z_sub.c index dc82cb5d9..bfa3838c3 100644 --- a/examples/unix/c11/z_sub.c +++ b/examples/unix/c11/z_sub.c @@ -36,9 +36,9 @@ void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(sample); - printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_slice_len(payload), - z_slice_data(payload)); + const z_loaned_bytes_t *payload = z_sample_payload(sample); + printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_bytes_len(payload), + z_bytes_data(payload)); #if Z_FEATURE_ATTACHMENT == 1 z_attachment_t attachment = z_sample_attachment(sample); if (z_attachment_check(&attachment)) { diff --git a/examples/unix/c11/z_sub_channel.c b/examples/unix/c11/z_sub_channel.c index a0d7f3163..3dcc96b11 100644 --- a/examples/unix/c11/z_sub_channel.c +++ b/examples/unix/c11/z_sub_channel.c @@ -80,9 +80,9 @@ int main(int argc, char **argv) { for (z_call(channel.recv, &sample); z_check(sample); z_call(channel.recv, &sample)) { z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(z_loan(sample)), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(z_loan(sample)); - printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_slice_len(payload), - z_slice_data(payload)); + const z_loaned_bytes_t *payload = z_sample_payload(z_loan(sample)); + printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_bytes_len(payload), + z_bytes_data(payload)); z_drop(z_move(keystr)); z_drop(z_move(sample)); z_null(&sample); diff --git a/examples/unix/c11/z_sub_st.c b/examples/unix/c11/z_sub_st.c index 5b16a9054..168bd20df 100644 --- a/examples/unix/c11/z_sub_st.c +++ b/examples/unix/c11/z_sub_st.c @@ -27,9 +27,9 @@ void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(sample); - printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_slice_len(payload), - z_slice_data(payload)); + const z_loaned_bytes_t *payload = z_sample_payload(sample); + printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_bytes_len(payload), + z_bytes_data(payload)); z_drop(z_move(keystr)); msg_nb++; } diff --git a/examples/unix/c99/z_get.c b/examples/unix/c99/z_get.c index 7d6dda278..e11827800 100644 --- a/examples/unix/c99/z_get.c +++ b/examples/unix/c99/z_get.c @@ -125,7 +125,7 @@ int main(int argc, char **argv) { if (value != NULL) { z_view_string_t value_str; z_view_string_wrap(&value_str, value); - z_owned_slice_t payload; + z_owned_bytes_t payload; z_bytes_encode_from_string(&payload, z_view_string_loan(&value_str)); opts.payload = &payload; } diff --git a/examples/unix/c99/z_pong.c b/examples/unix/c99/z_pong.c index 504343ebb..45cbfaa9f 100644 --- a/examples/unix/c99/z_pong.c +++ b/examples/unix/c99/z_pong.c @@ -19,8 +19,8 @@ #if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 void callback(const z_loaned_sample_t* sample, void* context) { const z_loaned_publisher_t* pub = z_publisher_loan((z_owned_publisher_t*)context); - const z_loaned_slice_t* payload = z_sample_payload(sample); - z_publisher_put(pub, z_slice_data(payload), z_slice_len(payload), NULL); + const z_loaned_bytes_t* payload = z_sample_payload(sample); + z_publisher_put(pub, z_bytes_data(payload), z_bytes_len(payload), NULL); } void drop(void* context) { z_owned_publisher_t* pub = (z_owned_publisher_t*)context; diff --git a/examples/unix/c99/z_queryable.c b/examples/unix/c99/z_queryable.c index 8af57a67f..9bdb4a910 100644 --- a/examples/unix/c99/z_queryable.c +++ b/examples/unix/c99/z_queryable.c @@ -31,8 +31,8 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_string_data(z_string_loan(&keystr)), (int)z_view_string_loan(¶ms)->len, z_view_string_loan(¶ms)->val); // Process value - const z_loaned_slice_t *payload = z_value_payload(z_query_value(query)); - if (z_slice_len(payload) > 0) { + const z_loaned_bytes_t *payload = z_value_payload(z_query_value(query)); + if (z_bytes_len(payload) > 0) { z_owned_string_t payload_string; z_bytes_decode_into_string(payload, &payload_string); printf(" with value '%s'\n", z_string_data(z_string_loan(&payload_string))); @@ -48,10 +48,10 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { // Reply value encoding z_view_string_t reply_str; z_view_string_wrap(&reply_str, value); - z_owned_slice_t reply_payload; + z_owned_bytes_t reply_payload; z_bytes_encode_from_string(&reply_payload, z_view_string_loan(&reply_str)); - z_query_reply(query, z_query_keyexpr(query), z_slice_move(&reply_payload), &options); + z_query_reply(query, z_query_keyexpr(query), z_bytes_move(&reply_payload), &options); z_string_drop(z_string_move(&keystr)); } diff --git a/examples/unix/c99/z_sub.c b/examples/unix/c99/z_sub.c index db7a5232a..992f39219 100644 --- a/examples/unix/c99/z_sub.c +++ b/examples/unix/c99/z_sub.c @@ -24,9 +24,9 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) { (void)(arg); z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(sample); + const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_string_loan(&keystr)), - (int)z_slice_len(payload), z_slice_data(payload)); + (int)z_bytes_len(payload), z_bytes_data(payload)); z_string_drop(z_string_move(&keystr)); } diff --git a/examples/unix/c99/z_sub_st.c b/examples/unix/c99/z_sub_st.c index 2a4213931..745bee1a5 100644 --- a/examples/unix/c99/z_sub_st.c +++ b/examples/unix/c99/z_sub_st.c @@ -27,9 +27,9 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) { (void)(arg); z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(sample); + const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_string_loan(&keystr)), - (int)z_slice_len(payload), z_slice_data(payload)); + (int)z_bytes_len(payload), z_bytes_data(payload)); z_string_drop(z_string_move(&keystr)); msg_nb++; } diff --git a/examples/windows/z_get.c b/examples/windows/z_get.c index 4c30bc768..42fdfea55 100644 --- a/examples/windows/z_get.c +++ b/examples/windows/z_get.c @@ -89,7 +89,7 @@ int main(int argc, char **argv) { if (value != NULL) { z_view_string_t value_str; z_view_string_wrap(&value_str, value); - z_owned_slice_t payload; + z_owned_bytes_t payload; z_bytes_encode_from_string(&payload, z_loan(value_str)); opts.payload = &payload; } diff --git a/examples/windows/z_pong.c b/examples/windows/z_pong.c index c69bf9e74..62b083e14 100644 --- a/examples/windows/z_pong.c +++ b/examples/windows/z_pong.c @@ -18,8 +18,8 @@ #if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 void callback(const z_loaned_sample_t* sample, void* context) { const z_loaned_publisher_t* pub = z_loan(*(z_owned_publisher_t*)context); - const z_loaned_slice_t* payload = z_sample_payload(sample); - z_publisher_put(pub, z_slice_data(payload), z_slice_len(payload), NULL); + const z_loaned_bytes_t* payload = z_sample_payload(sample); + z_publisher_put(pub, z_bytes_data(payload), z_bytes_len(payload), NULL); } void drop(void* context) { z_owned_publisher_t* pub = (z_owned_publisher_t*)context; diff --git a/examples/windows/z_queryable.c b/examples/windows/z_queryable.c index 24d039872..a6130c3b7 100644 --- a/examples/windows/z_queryable.c +++ b/examples/windows/z_queryable.c @@ -31,8 +31,8 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_string_data(z_loan(keystr)), (int)z_loan(params)->len, z_loan(params)->val); // Process value - const z_loaned_slice_t *payload = z_value_payload(z_query_value(query)); - if (z_slice_len(payload) > 0) { + const z_loaned_bytes_t *payload = z_value_payload(z_query_value(query)); + if (z_bytes_len(payload) > 0) { z_owned_string_t payload_string; z_bytes_decode_into_string(payload, &payload_string); printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); @@ -48,7 +48,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { // Reply value encoding z_view_string_t reply_str; z_view_string_wrap(&reply_str, value); - z_owned_slice_t reply_payload; + z_owned_bytes_t reply_payload; z_bytes_encode_from_string(&reply_payload, z_loan(reply_str)); z_query_reply(query, z_query_keyexpr(query), z_move(reply_payload), &options); diff --git a/examples/windows/z_sub.c b/examples/windows/z_sub.c index d27f41113..a6b854f2f 100644 --- a/examples/windows/z_sub.c +++ b/examples/windows/z_sub.c @@ -23,9 +23,9 @@ void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(sample); - printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_slice_len(payload), - z_slice_data(payload)); + const z_loaned_bytes_t *payload = z_sample_payload(sample); + printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_bytes_len(payload), + z_bytes_data(payload)); z_drop(z_move(keystr)); } diff --git a/examples/windows/z_sub_st.c b/examples/windows/z_sub_st.c index 5ac00e19d..76e8ab22a 100644 --- a/examples/windows/z_sub_st.c +++ b/examples/windows/z_sub_st.c @@ -26,9 +26,9 @@ void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(sample); - printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_slice_len(payload), - z_slice_data(payload)); + const z_loaned_bytes_t *payload = z_sample_payload(sample); + printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), (int)z_bytes_len(payload), + z_bytes_data(payload)); z_drop(z_move(keystr)); msg_nb++; diff --git a/examples/zephyr/z_get.c b/examples/zephyr/z_get.c index aadce8872..397b3d340 100644 --- a/examples/zephyr/z_get.c +++ b/examples/zephyr/z_get.c @@ -84,7 +84,7 @@ int main(int argc, char **argv) { if (strcmp(VALUE, "") != 0) { z_view_string_t value_str; z_view_string_wrap(&value_str, VALUE); - z_owned_slice_t payload; + z_owned_bytes_t payload; z_bytes_encode_from_string(&payload, z_loan(value_str)); opts.payload = &payload; } diff --git a/examples/zephyr/z_queryable.c b/examples/zephyr/z_queryable.c index 4b3008c0d..f210cf1b3 100644 --- a/examples/zephyr/z_queryable.c +++ b/examples/zephyr/z_queryable.c @@ -40,8 +40,8 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_string_data(z_loan(keystr)), z_loan(params)->len, z_loan(params)->val); // Process value - const z_loaned_slice_t *payload = z_value_payload(z_query_value(query)); - if (z_slice_len(payload) > 0) { + const z_loaned_bytes_t *payload = z_value_payload(z_query_value(query)); + if (z_bytes_len(payload) > 0) { z_owned_string_t payload_string; z_bytes_decode_into_string(payload, &payload_string); printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); @@ -50,7 +50,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { // Reply value encoding z_view_string_t reply_str; z_view_string_wrap(&reply_str, VALUE); - z_owned_slice_t reply_payload; + z_owned_bytes_t reply_payload; z_bytes_encode_from_string(&reply_payload, z_loan(reply_str)); z_query_reply(query, z_query_keyexpr(query), z_move(reply_payload), NULL); diff --git a/examples/zephyr/z_sub.c b/examples/zephyr/z_sub.c index d01f1e162..ea447d7c3 100644 --- a/examples/zephyr/z_sub.c +++ b/examples/zephyr/z_sub.c @@ -32,9 +32,9 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) { z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_slice_t *payload = z_sample_payload(sample); + const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_string_data(z_loan(keystr)), - (int)z_slice_len(payload), z_slice_data(payload)); + (int)z_bytes_len(payload), z_bytes_data(payload)); z_drop(z_move(keystr)); } diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 167f9481e..1204092f4 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -85,7 +85,7 @@ void query_handler(const z_loaned_query_t *query, void *arg) { // Reply value encoding z_view_string_t reply_str; z_view_string_wrap(&reply_str, value); - z_owned_slice_t reply_payload; + z_owned_bytes_t reply_payload; z_bytes_encode_from_string(&reply_payload, z_loan(reply_str)); z_query_reply(query, query_ke, z_move(reply_payload), &_ret_qreply_opt); diff --git a/tests/z_channels_test.c b/tests/z_channels_test.c index a254b53f6..a749fe163 100644 --- a/tests/z_channels_test.c +++ b/tests/z_channels_test.c @@ -23,16 +23,16 @@ #undef NDEBUG #include -#define SEND(channel, v) \ - do { \ - _z_sample_t s = {.keyexpr = _z_rname("key"), \ - .payload = {.start = (const uint8_t *)v, .len = strlen(v)}, \ - .timestamp = _z_timestamp_null(), \ - .encoding = _z_encoding_null(), \ - .kind = 0, \ - .qos = {0}}; \ - z_loaned_sample_t sample = _z_sample_rc_new_from_val(s); \ - z_call(channel.send, &sample); \ +#define SEND(channel, v) \ + do { \ + _z_sample_t s = {.keyexpr = _z_rname("key"), \ + .payload = {._slice = {.start = (const uint8_t *)v, .len = strlen(v)}}, \ + .timestamp = _z_timestamp_null(), \ + .encoding = _z_encoding_null(), \ + .kind = 0, \ + .qos = {0}}; \ + z_loaned_sample_t sample = _z_sample_rc_new_from_val(s); \ + z_call(channel.send, &sample); \ } while (0); #define _RECV(channel, method, buf) \ @@ -41,9 +41,10 @@ z_sample_null(&sample); \ z_call(channel.method, &sample); \ if (z_check(sample)) { \ - const z_loaned_slice_t *payload = z_sample_payload(z_loan(sample)); \ - strncpy(buf, (const char *)payload->start, (size_t)payload->len); \ - buf[payload->len] = '\0'; \ + const z_loaned_bytes_t *payload = z_sample_payload(z_loan(sample)); \ + size_t payload_len = z_bytes_len(payload); \ + strncpy(buf, (const char *)z_bytes_data(payload), payload_len); \ + buf[payload_len] = '\0'; \ z_drop(z_move(sample)); \ } else { \ buf[0] = '\0'; \ diff --git a/tests/z_client_test.c b/tests/z_client_test.c index 60576010a..edabbea74 100644 --- a/tests/z_client_test.c +++ b/tests/z_client_test.c @@ -64,7 +64,7 @@ void query_handler(const z_loaned_query_t *query, void *arg) { // Reply value encoding z_view_string_t reply_str; z_view_string_wrap(&reply_str, res); - z_owned_slice_t reply_payload; + z_owned_bytes_t reply_payload; z_bytes_encode_from_string(&reply_payload, z_loan(reply_str)); z_query_reply(query, z_query_keyexpr(query), z_move(reply_payload), NULL); @@ -83,9 +83,9 @@ void reply_handler(const z_loaned_reply_t *reply, void *arg) { z_owned_string_t k_str; z_keyexpr_to_string(z_sample_keyexpr(sample), &k_str); - const z_loaned_slice_t *payload = z_sample_payload(sample); - assert(payload->len == strlen(res)); - assert(strncmp(res, (const char *)payload->start, strlen(res)) == 0); + const z_loaned_bytes_t *payload = z_sample_payload(sample); + assert(z_bytes_len(payload) == strlen(res)); + assert(strncmp(res, (const char *)z_bytes_data(payload), strlen(res)) == 0); assert(_z_str_eq(z_loan(k_str)->val, res) == true); replies++; @@ -104,8 +104,9 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) { z_owned_string_t k_str; z_keyexpr_to_string(z_sample_keyexpr(sample), &k_str); - const z_loaned_slice_t *payload = z_sample_payload(sample); - assert((payload->len == MSG_LEN) || (payload->len == FRAGMENT_MSG_LEN)); + const z_loaned_bytes_t *payload = z_sample_payload(sample); + size_t payload_len = z_bytes_len(payload); + assert((payload_len == MSG_LEN) || (payload_len == FRAGMENT_MSG_LEN)); assert(_z_str_eq(z_loan(k_str)->val, res) == true); datas++; diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index 177cfd058..0937f42ac 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -180,7 +180,7 @@ _z_slice_t gen_payload(size_t len) { return pld; } -_z_slice_t gen_bytes(size_t len) { +_z_slice_t gen_slice(size_t len) { _z_slice_t arr; arr._is_alloc = true; arr.len = len; @@ -195,6 +195,12 @@ _z_slice_t gen_bytes(size_t len) { return arr; } +_z_bytes_t gen_bytes(size_t len) { + return (_z_bytes_t){ + ._slice = gen_slice(len), + }; +} + _z_id_t gen_zid(void) { _z_id_t id = _z_id_empty(); uint8_t hash = 55; @@ -244,7 +250,7 @@ _z_encoding_t gen_encoding(void) { _z_encoding_t en; en.id = gen_uint16(); if (gen_bool()) { - en.schema = gen_bytes(16); + en.schema = gen_slice(16); } else { en.schema = _z_slice_empty(); } @@ -255,7 +261,7 @@ _z_value_t gen_value(void) { _z_value_t val; val.encoding = gen_encoding(); if (gen_bool()) { - val.payload = _z_slice_empty(); + val.payload = _z_bytes_null(); } else { val.payload = gen_bytes(16); } @@ -456,7 +462,7 @@ void zint_extension(void) { /*------------------ Unit extension ------------------*/ _z_msg_ext_t gen_zbuf_extension(void) { - _z_slice_t val = gen_bytes(gen_uint8()); + _z_slice_t val = gen_slice(gen_uint8()); return _z_msg_ext_make_zbuf(_Z_MOCK_EXTENSION_ZBUF, val); } @@ -500,7 +506,11 @@ void zbuf_extension(void) { /* Message Fields */ /*=============================*/ /*------------------ Payload field ------------------*/ -void assert_eq_bytes(const _z_slice_t *left, const _z_slice_t *right) { assert_eq_uint8_array(left, right); } +void assert_eq_slice(const _z_slice_t *left, const _z_slice_t *right) { assert_eq_uint8_array(left, right); } + +void assert_eq_bytes(const _z_bytes_t *left, const _z_bytes_t *right) { + assert_eq_slice(&left->_slice, &right->_slice); +} void payload_field(void) { printf("\n>> Payload field\n"); @@ -521,7 +531,7 @@ void payload_field(void) { res = _z_slice_decode(&d_pld, &zbf); assert(res == _Z_RES_OK); printf(" "); - assert_eq_bytes(&e_pld, &d_pld); + assert_eq_slice(&e_pld, &d_pld); printf("\n"); // Free @@ -543,7 +553,7 @@ void assert_eq_source_info(const _z_source_info_t *left, const _z_source_info_t } void assert_eq_encoding(const _z_encoding_t *left, const _z_encoding_t *right) { assert(left->id == right->id); - assert_eq_bytes(&left->schema, &right->schema); + assert_eq_slice(&left->schema, &right->schema); } void assert_eq_value(const _z_value_t *left, const _z_value_t *right) { assert_eq_encoding(&left->encoding, &right->encoding); @@ -1143,7 +1153,7 @@ _z_push_body_t gen_push_body(void) { return (_z_push_body_t){._is_put = true, ._body._put = { ._commons = commons, - ._payload = gen_bytes(64), + ._payload = gen_slice(64), ._encoding = gen_encoding(), }}; } else { @@ -1154,7 +1164,7 @@ _z_push_body_t gen_push_body(void) { void assert_eq_push_body(const _z_push_body_t *left, const _z_push_body_t *right) { assert(left->_is_put == right->_is_put); if (left->_is_put) { - assert_eq_bytes(&left->_body._put._payload, &right->_body._put._payload); + assert_eq_slice(&left->_body._put._payload, &right->_body._put._payload); assert_eq_encoding(&left->_body._put._encoding, &right->_body._put._encoding); assert_eq_timestamp(&left->_body._put._commons._timestamp, &right->_body._put._commons._timestamp); assert_eq_source_info(&left->_body._put._commons._source_info, &right->_body._put._commons._source_info); @@ -1196,7 +1206,7 @@ _z_msg_query_t gen_query(void) { return (_z_msg_query_t){ ._consolidation = (gen_uint8() % 4) - 1, ._ext_info = gen_source_info(), - ._parameters = gen_bytes(16), + ._parameters = gen_slice(16), ._ext_value = gen_bool() ? gen_value() : _z_value_null(), }; } @@ -1204,7 +1214,7 @@ _z_msg_query_t gen_query(void) { void assert_eq_query(const _z_msg_query_t *left, const _z_msg_query_t *right) { assert(left->_consolidation == right->_consolidation); assert_eq_source_info(&left->_ext_info, &right->_ext_info); - assert_eq_bytes(&left->_parameters, &right->_parameters); + assert_eq_slice(&left->_parameters, &right->_parameters); assert_eq_value(&left->_ext_value, &right->_ext_value); } @@ -1237,7 +1247,7 @@ _z_msg_err_t gen_err(void) { void assert_eq_err(const _z_msg_err_t *left, const _z_msg_err_t *right) { assert_eq_encoding(&left->encoding, &right->encoding); assert_eq_source_info(&left->_ext_source_info, &right->_ext_source_info); - assert_eq_bytes(&left->_payload, &right->_payload); + assert_eq_slice(&left->_payload, &right->_payload); } void err_message(void) { @@ -1518,14 +1528,14 @@ _z_transport_message_t gen_init(void) { if (gen_bool()) { return _z_t_msg_make_init_syn(gen_uint8() % 3, gen_zid()); } else { - return _z_t_msg_make_init_ack(gen_uint8() % 3, gen_zid(), gen_bytes(16)); + return _z_t_msg_make_init_ack(gen_uint8() % 3, gen_zid(), gen_slice(16)); } } void assert_eq_init(const _z_t_msg_init_t *left, const _z_t_msg_init_t *right) { assert(left->_batch_size == right->_batch_size); assert(left->_req_id_res == right->_req_id_res); assert(left->_seq_num_res == right->_seq_num_res); - assert_eq_bytes(&left->_cookie, &right->_cookie); + assert_eq_slice(&left->_cookie, &right->_cookie); assert(memcmp(left->_zid.id, right->_zid.id, 16) == 0); assert(left->_version == right->_version); assert(left->_whatami == right->_whatami); @@ -1548,13 +1558,13 @@ void init_message(void) { _z_transport_message_t gen_open(void) { if (gen_bool()) { - return _z_t_msg_make_open_syn(gen_uint32(), gen_uint32(), gen_bytes(16)); + return _z_t_msg_make_open_syn(gen_uint32(), gen_uint32(), gen_slice(16)); } else { return _z_t_msg_make_open_ack(gen_uint32(), gen_uint32()); } } void assert_eq_open(const _z_t_msg_open_t *left, const _z_t_msg_open_t *right) { - assert_eq_bytes(&left->_cookie, &right->_cookie); + assert_eq_slice(&left->_cookie, &right->_cookie); assert(left->_initial_sn == right->_initial_sn); assert(left->_lease == right->_lease); } @@ -1703,11 +1713,11 @@ void frame_message(void) { } _z_transport_message_t gen_fragment(void) { - return _z_t_msg_make_fragment(gen_uint32(), gen_bytes(gen_uint8()), gen_bool(), gen_bool()); + return _z_t_msg_make_fragment(gen_uint32(), gen_slice(gen_uint8()), gen_bool(), gen_bool()); } void assert_eq_fragment(const _z_t_msg_fragment_t *left, const _z_t_msg_fragment_t *right) { assert(left->_sn == right->_sn); - assert_eq_bytes(&left->_payload, &right->_payload); + assert_eq_slice(&left->_payload, &right->_payload); } void fragment_message(void) { printf("\n>> fragment message\n"); diff --git a/tests/z_peer_multicast_test.c b/tests/z_peer_multicast_test.c index c5b84c566..7ead51b64 100644 --- a/tests/z_peer_multicast_test.c +++ b/tests/z_peer_multicast_test.c @@ -48,8 +48,8 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) { z_owned_string_t k_str; z_keyexpr_to_string(z_sample_keyexpr(sample), &k_str); - const z_loaned_slice_t *payload = z_sample_payload(sample); - assert(payload->len == MSG_LEN); + const z_loaned_bytes_t *payload = z_sample_payload(sample); + assert(z_bytes_len(payload) == MSG_LEN); assert(z_loan(k_str)->len == strlen(res)); assert(strncmp(res, z_loan(k_str)->val, strlen(res)) == 0); (void)(sample); diff --git a/tests/z_perf_rx.c b/tests/z_perf_rx.c index 6be977499..e9ac3ebdd 100644 --- a/tests/z_perf_rx.c +++ b/tests/z_perf_rx.c @@ -41,14 +41,15 @@ void z_stats_stop(z_stats_t *stats) { void on_sample(const z_loaned_sample_t *sample, void *context) { z_stats_t *stats = (z_stats_t *)context; - const z_loaned_slice_t *payload = z_sample_payload(sample); + const z_loaned_bytes_t *payload = z_sample_payload(sample); + unsigned long data_len = (unsigned long)z_bytes_len(payload); - if (stats->curr_len != payload->len) { + if (stats->curr_len != data_len) { // End previous measurement z_stats_stop(stats); // Check for end packet - stats->curr_len = (unsigned long)payload->len; - if (payload->len == 1) { + stats->curr_len = data_len; + if (data_len == 1) { test_end = true; return; } diff --git a/tests/z_test_fragment_rx.c b/tests/z_test_fragment_rx.c index 71800c240..f4b2d0395 100644 --- a/tests/z_test_fragment_rx.c +++ b/tests/z_test_fragment_rx.c @@ -23,16 +23,17 @@ void data_handler(const z_loaned_sample_t *sample, void *ctx) { z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); bool is_valid = true; - const z_loaned_slice_t *payload = z_sample_payload(sample); - const uint8_t *data = payload->start; - for (size_t i = 0; i < payload->len; i++) { + const z_loaned_bytes_t *payload = z_sample_payload(sample); + const uint8_t *data = z_bytes_data(payload); + size_t data_len = z_bytes_len(payload); + for (size_t i = 0; i < data_len; i++) { if (data[i] != (uint8_t)i) { is_valid = false; break; } } - printf("[rx]: Received packet on %s, len: %d, validity: %d\n", z_string_data(z_loan(keystr)), - (int)z_sample_payload(sample)->len, is_valid); + printf("[rx]: Received packet on %s, len: %d, validity: %d\n", z_string_data(z_loan(keystr)), (int)data_len, + is_valid); z_drop(z_move(keystr)); }