diff --git a/examples/arduino/z_get.ino b/examples/arduino/z_get.ino index 73773cd75..f5853253e 100644 --- a/examples/arduino/z_get.ino +++ b/examples/arduino/z_get.ino @@ -46,17 +46,17 @@ void reply_handler(const z_loaned_reply_t *oreply, void *ctx) { (void)(ctx); if (z_reply_is_ok(oreply)) { const z_loaned_sample_t *sample = z_reply_ok(oreply); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); std::string val((const char *)z_sample_payload(sample)->start, z_sample_payload(sample)->len); Serial.print(" >> [Get listener] Received ("); - Serial.print(z_str_data(z_str_loan(&keystr))); + Serial.print(z_str_data(z_string_loan(&keystr))); Serial.print(", "); Serial.print(val.c_str()); Serial.println(")"); - z_str_drop(z_str_move(&keystr)); + z_string_drop(z_string_move(&keystr)); } else { Serial.println(" >> Received an error"); } @@ -114,7 +114,8 @@ void loop() { z_get_options_t opts; z_get_options_default(&opts); if (strcmp(VALUE, "") != 0) { - opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); + // TODO(sashacmc): encoding + // opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); } z_owned_closure_reply_t callback; z_closure_reply(&callback, reply_handler, reply_dropper, NULL); diff --git a/examples/arduino/z_pull.ino b/examples/arduino/z_pull.ino index bf75d2412..dd8a271db 100644 --- a/examples/arduino/z_pull.ino +++ b/examples/arduino/z_pull.ino @@ -39,17 +39,17 @@ // @TODO // void data_handler(const z_loaned_sample_t *sample, void *arg) { -// z_owned_str_t keystr; +// z_owned_string_t keystr; // z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); // std::string val((const char *)sample->payload.start, sample->payload.len); // Serial.print(" >> [Subscription listener] Received ("); -// Serial.print(z_str_data(z_str_loan(&keystr))); +// Serial.print(z_str_data(z_string_loan(&keystr))); // Serial.print(", "); // Serial.print(val.c_str()); // Serial.println(")"); -// z_str_drop(z_str_move(&keystr)); +// z_string_drop(z_string_move(&keystr)); // } void setup() { diff --git a/examples/arduino/z_queryable.ino b/examples/arduino/z_queryable.ino index 1463e4af7..c3c022ce6 100644 --- a/examples/arduino/z_queryable.ino +++ b/examples/arduino/z_queryable.ino @@ -36,20 +36,22 @@ #define VALUE "[ARDUINO]{ESP32} Queryable from Zenoh-Pico!" void query_handler(const z_loaned_query_t *query, void *arg) { - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_query_keyexpr(query), &keystr); Serial.print(" >> [Queryable handler] Replying Data ('"); - Serial.print(z_str_data(z_str_loan(&keystr))); + Serial.print(z_str_data(z_string_loan(&keystr))); Serial.print("': '"); Serial.print(VALUE); Serial.println("')"); z_view_keyexpr_t ke; z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); - z_query_reply(query, z_view_keyexpr_loan(&ke), (const unsigned char *)VALUE, strlen(VALUE), NULL); + z_owned_bytes_t reply_payload; + // TODO(sashacmc): VALUE encoding + z_query_reply(query, z_view_keyexpr_loan(&ke), z_bytes_move(&reply_payload), NULL); - z_str_drop(z_str_move(&keystr)); + z_string_drop(z_string_move(&keystr)); } void setup() { diff --git a/examples/arduino/z_scout.ino b/examples/arduino/z_scout.ino index a3b78bb46..2d168225c 100644 --- a/examples/arduino/z_scout.ino +++ b/examples/arduino/z_scout.ino @@ -54,19 +54,18 @@ void fprintwhatami(unsigned int whatami) { } } -void fprintlocators(const z_str_array_t *locs) { +void fprintlocators(const z_loaned_string_array_t *locs) { Serial.print("["); - (void)locs; - // TODO(sashacmc): z_str_array_t - // size_t len = z_str_array_len(locs); - // for (unsigned int i = 0; i < len; i++) { - // Serial.print("'"); - // Serial.print(*z_str_array_get(locs, i)); - // Serial.print("'"); - // if (i < len - 1) { - // Serial.print(", "); - // } - //} + size_t len = z_string_array_len(locs); + for (unsigned int i = 0; i < len; i++) { + Serial.print("'"); + const z_loaned_string_t *str = z_string_array_get(locs, i); + Serial.print(str->val); + Serial.print("'"); + if (i < len - 1) { + Serial.print(", "); + } + } Serial.print("]"); } diff --git a/examples/arduino/z_sub.ino b/examples/arduino/z_sub.ino index 683e6acf5..5336932e1 100644 --- a/examples/arduino/z_sub.ino +++ b/examples/arduino/z_sub.ino @@ -35,17 +35,17 @@ #define KEYEXPR "demo/example/**" void data_handler(const z_loaned_sample_t *sample, void *arg) { - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); std::string val((const char *)z_sample_payload(sample)->start, z_sample_payload(sample)->len); Serial.print(" >> [Subscription listener] Received ("); - Serial.print(z_str_data(z_str_loan(&keystr))); + Serial.print(z_str_data(z_string_loan(&keystr))); Serial.print(", "); Serial.print(val.c_str()); Serial.println(")"); - z_str_drop(z_str_move(&keystr)); + z_string_drop(z_string_move(&keystr)); } void setup() { diff --git a/examples/espidf/z_get.c b/examples/espidf/z_get.c index 1dae905c0..d42474e8d 100644 --- a/examples/espidf/z_get.c +++ b/examples/espidf/z_get.c @@ -106,7 +106,7 @@ void reply_dropper(void *ctx) { printf(" >> Received query final notification\n" void reply_handler(const z_loaned_reply_t *oreply, void *ctx) { if (z_reply_is_ok(oreply)) { const z_loaned_sample_t *sample = z_reply_ok(oreply); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); printf(" >> Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)z_sample_payload(sample)->len, @@ -161,7 +161,8 @@ void app_main() { z_get_options_t opts; z_get_options_default(&opts); if (strcmp(VALUE, "") != 0) { - opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); + // TODO(sashacmc): encoding + // opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); } z_owned_closure_reply_t callback; z_closure(&callback, reply_handler, reply_dropper); diff --git a/examples/espidf/z_pull.c b/examples/espidf/z_pull.c index 9f6a2d11f..8efd04a29 100644 --- a/examples/espidf/z_pull.c +++ b/examples/espidf/z_pull.c @@ -102,7 +102,7 @@ void wifi_init_sta(void) { // @TODO // void data_handler(const z_loaned_sample_t* sample, void* arg) { -// z_owned_str_t keystr; +// z_owned_string_t keystr; // z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); // printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), // (int)sample->payload.len, diff --git a/examples/espidf/z_queryable.c b/examples/espidf/z_queryable.c index 6bd3d88b7..8c8da8896 100644 --- a/examples/espidf/z_queryable.c +++ b/examples/espidf/z_queryable.c @@ -103,15 +103,17 @@ void wifi_init_sta(void) { void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); - z_owned_str_t keystr; - // TODO(sashacmc): z_query_parameters - // z_keyexpr_to_string(z_query_keyexpr(query), &keystr); - // z_bytes_t pred = z_query_parameters(query); - // printf(">> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_loan(keystr)), (int)pred.len, - // pred.start); + z_owned_string_t keystr; + z_keyexpr_to_string(z_query_keyexpr(query), &keystr); + z_view_string_t params; + z_query_parameters(query, ¶ms); + printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_loan(keystr)), (int)z_loan(params)->len, + z_loan(params)->val); z_view_keyexpr_t ke; z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); - z_query_reply(query, z_loan(ke), (const unsigned char *)VALUE, strlen(VALUE), NULL); + z_owned_bytes_t reply_payload; + // TODO(sashacmc): VALUE encoding + z_query_reply(query, z_loan(ke), z_move(reply_payload), NULL); z_drop(z_move(keystr)); } diff --git a/examples/espidf/z_scout.c b/examples/espidf/z_scout.c index 99ca0b026..e569d81ea 100644 --- a/examples/espidf/z_scout.c +++ b/examples/espidf/z_scout.c @@ -109,18 +109,17 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { } } -void fprintlocators(FILE *stream, const z_str_array_t *locs) { +void fprintlocators(FILE *stream, const z_loaned_string_array_t *locs) { fprintf(stream, "["); - (void)locs; - // TODO(sashacmc): z_str_array missed - // for (unsigned int i = 0; i < z_str_array_len(locs); i++) { - // fprintf(stream, "\""); - // fprintf(stream, "%s", *z_str_array_get(locs, i)); - // fprintf(stream, "\""); - // if (i < z_str_array_len(locs) - 1) { - // fprintf(stream, ", "); - // } - //} + for (unsigned int i = 0; i < z_string_array_len(locs); i++) { + fprintf(stream, "\""); + const z_loaned_string_t *str = z_string_array_get(locs, i); + fprintf(stream, "%.*s", (int)str->len, str->val); + fprintf(stream, "\""); + if (i < z_string_array_len(locs) - 1) { + fprintf(stream, ", "); + } + } fprintf(stream, "]"); } diff --git a/examples/espidf/z_sub.c b/examples/espidf/z_sub.c index 76e93927f..45e1b8ed9 100644 --- a/examples/espidf/z_sub.c +++ b/examples/espidf/z_sub.c @@ -101,12 +101,12 @@ void wifi_init_sta(void) { } void data_handler(const z_loaned_sample_t* sample, void* arg) { - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t* payload = z_sample_payload(sample); - printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_str_data(z_str_loan(&keystr)), (int)payload->len, + printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_str_data(z_string_loan(&keystr)), (int)payload->len, payload->start); - z_str_drop(z_str_move(&keystr)); + z_string_drop(z_string_move(&keystr)); } void app_main() { diff --git a/examples/freertos_plus_tcp/z_get.c b/examples/freertos_plus_tcp/z_get.c index 6e3145748..efe049411 100644 --- a/examples/freertos_plus_tcp/z_get.c +++ b/examples/freertos_plus_tcp/z_get.c @@ -40,7 +40,7 @@ void reply_handler(const z_loaned_reply_t *reply, void *ctx) { (void)(ctx); if (z_reply_is_ok(reply)) { const z_loaned_sample_t *sample = z_reply_ok(reply); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(">> Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)payload->len, payload->start); @@ -84,7 +84,8 @@ void app_main(void) { z_get_options_t opts; z_get_options_default(&opts); if (strcmp(VALUE, "") != 0) { - opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); + // TODO(sashacmc): encoding + // opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); } z_owned_closure_reply_t callback; z_closure(&callback, reply_handler, reply_dropper); diff --git a/examples/freertos_plus_tcp/z_pull.c b/examples/freertos_plus_tcp/z_pull.c index 2c6ed1014..6f1273b70 100644 --- a/examples/freertos_plus_tcp/z_pull.c +++ b/examples/freertos_plus_tcp/z_pull.c @@ -31,7 +31,7 @@ // @TODO // void data_handler(const z_loaned_sample_t *sample, void *ctx) { // (void)(ctx); -// z_owned_str_t keystr; +// z_owned_string_t keystr; // z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); // printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)sample->payload.len, // sample->payload.start); diff --git a/examples/freertos_plus_tcp/z_queryable.c b/examples/freertos_plus_tcp/z_queryable.c index 02251adc3..95eb3813c 100644 --- a/examples/freertos_plus_tcp/z_queryable.c +++ b/examples/freertos_plus_tcp/z_queryable.c @@ -31,19 +31,21 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_query_keyexpr(query), &keystr); - // TODO(sashacmc): z_query_parameters - // z_bytes_t pred = z_query_parameters(query); - // z_value_t payload_value = z_query_value(query); - // printf(" >> [Queryable handler] Received Query '%s?%.*s'\n", z_str_data(z_loan(keystr)), (int)pred.len, - // pred.start); if (payload_value.payload.len > 0) { - // printf(" with value '%.*s'\n", (int)payload_value.payload.len, payload_value.payload.start); - // } + z_view_string_t params; + z_query_parameters(query, ¶ms); + printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_loan(keystr)), (int)z_loan(params)->len, + z_loan(params)->val); + const z_loaned_value_t *payload_value = z_query_value(query); + if (payload_value->payload.len > 0) { + printf(" with value '%.*s'\n", (int)payload_value->payload.len, payload_value->payload.start); + } z_query_reply_options_t options; z_query_reply_options_default(&options); - options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); - z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)VALUE, strlen(VALUE), &options); + z_owned_bytes_t reply_payload; + // TODO(sashacmc): VALUE encoding + z_query_reply(query, z_query_keyexpr(query), z_move(reply_payload), &options); z_drop(z_move(keystr)); } diff --git a/examples/freertos_plus_tcp/z_scout.c b/examples/freertos_plus_tcp/z_scout.c index 777ef2b2c..4b62c1301 100644 --- a/examples/freertos_plus_tcp/z_scout.c +++ b/examples/freertos_plus_tcp/z_scout.c @@ -43,18 +43,17 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { } } -void fprintlocators(FILE *stream, const z_str_array_t *locs) { +void fprintlocators(FILE *stream, const z_loaned_string_array_t *locs) { fprintf(stream, "["); - (void)locs; - // TODO(sashacmc): z_str_array missed - // for (unsigned int i = 0; i < z_str_array_len(locs); i++) { - // fprintf(stream, "\""); - // fprintf(stream, "%s", *z_str_array_get(locs, i)); - // fprintf(stream, "\""); - // if (i < z_str_array_len(locs) - 1) { - // fprintf(stream, ", "); - // } - //} + for (unsigned int i = 0; i < z_string_array_len(locs); i++) { + fprintf(stream, "\""); + const z_loaned_string_t *str = z_string_array_get(locs, i); + fprintf(stream, "%.*s", (int)str->len, str->val); + fprintf(stream, "\""); + if (i < z_string_array_len(locs) - 1) { + fprintf(stream, ", "); + } + } fprintf(stream, "]"); } diff --git a/examples/freertos_plus_tcp/z_sub.c b/examples/freertos_plus_tcp/z_sub.c index b59d85972..dbf7e79f9 100644 --- a/examples/freertos_plus_tcp/z_sub.c +++ b/examples/freertos_plus_tcp/z_sub.c @@ -30,7 +30,7 @@ void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)payload->len, payload->start); diff --git a/examples/freertos_plus_tcp/z_sub_st.c b/examples/freertos_plus_tcp/z_sub_st.c index 53f81f2a8..151e078a6 100644 --- a/examples/freertos_plus_tcp/z_sub_st.c +++ b/examples/freertos_plus_tcp/z_sub_st.c @@ -33,7 +33,7 @@ int msg_nb = 0; void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)payload->len, payload->start); diff --git a/examples/mbed/z_get.cpp b/examples/mbed/z_get.cpp index e16387948..12340b094 100644 --- a/examples/mbed/z_get.cpp +++ b/examples/mbed/z_get.cpp @@ -36,11 +36,11 @@ void reply_dropper(void *ctx) { printf(" >> Received query final notification\n" void reply_handler(const z_loaned_reply_t *oreply, void *ctx) { if (z_reply_is_ok(oreply)) { const z_loaned_sample_t *sample = z_reply_ok(oreply); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); - printf(" >> Received ('%s': '%.*s')\n", z_str_data(z_str_loan(&keystr)), (int)payload->len, payload->start); - z_str_drop(z_str_move(&keystr)); + printf(" >> Received ('%s': '%.*s')\n", z_str_data(z_string_loan(&keystr)), (int)payload->len, payload->start); + z_string_drop(z_string_move(&keystr)); } else { printf(" >> Received an error\n"); } @@ -80,7 +80,8 @@ int main(int argc, char **argv) { z_get_options_t opts; z_get_options_default(&opts); if (strcmp(VALUE, "") != 0) { - opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); + // TODO(sashacmc): encoding + // opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); } z_owned_closure_reply_t callback; z_closure_reply(&callback, reply_handler, reply_dropper, NULL); diff --git a/examples/mbed/z_pull.cpp b/examples/mbed/z_pull.cpp index f011a4643..d01f2978c 100644 --- a/examples/mbed/z_pull.cpp +++ b/examples/mbed/z_pull.cpp @@ -32,12 +32,12 @@ // @TODO // void data_handler(const z_loaned_sample_t *sample, void *arg) { -// z_owned_str_t keystr; +// z_owned_string_t keystr; // z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); -// printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_str_data(z_str_loan(&keystr)), +// printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_str_data(z_string_loan(&keystr)), // (int)sample->payload.len, // sample->payload.start); -// z_str_drop(z_str_move(&keystr)); +// z_string_drop(z_string_move(&keystr)); // } int main(int argc, char **argv) { diff --git a/examples/mbed/z_queryable.cpp b/examples/mbed/z_queryable.cpp index 505da93e5..bf271d92d 100644 --- a/examples/mbed/z_queryable.cpp +++ b/examples/mbed/z_queryable.cpp @@ -33,14 +33,17 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_query_keyexpr(query), &keystr); - z_view_str_t pred; + z_view_string_t pred; z_query_parameters(query, &pred); - printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_str_loan(&keystr)), - (int)z_view_str_loan(&pred)->len, z_view_str_loan(&pred)->val); - z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)VALUE, strlen(VALUE), NULL); - z_str_drop(z_str_move(&keystr)); + printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_string_loan(&keystr)), + (int)z_view_string_loan(&pred)->len, z_view_string_loan(&pred)->val); + + z_owned_bytes_t reply_payload; + // TODO(sashacmc): VALUE encoding + z_query_reply(query, z_query_keyexpr(query), z_bytes_move(&reply_payload), NULL); + z_string_drop(z_string_move(&keystr)); } int main(int argc, char **argv) { diff --git a/examples/mbed/z_scout.cpp b/examples/mbed/z_scout.cpp index 6940f284b..9f78c6be4 100644 --- a/examples/mbed/z_scout.cpp +++ b/examples/mbed/z_scout.cpp @@ -51,18 +51,17 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { } } -void fprintlocators(FILE *stream, const z_str_array_t *locs) { +void fprintlocators(FILE *stream, const z_loaned_string_array_t *locs) { fprintf(stream, "["); - (void)locs; - // TODO(sashacmc): z_str_array_t - // for (unsigned int i = 0; i < z_str_array_len(locs); i++) { - // fprintf(stream, "\""); - // fprintf(stream, "%s", *z_str_array_get(locs, i)); - // fprintf(stream, "\""); - // if (i < z_str_array_len(locs) - 1) { - // fprintf(stream, ", "); - // } - //} + for (unsigned int i = 0; i < z_string_array_len(locs); i++) { + fprintf(stream, "\""); + const z_loaned_string_t *str = z_string_array_get(locs, i); + fprintf(stream, "%.*s", (int)str->len, str->val); + fprintf(stream, "\""); + if (i < z_string_array_len(locs) - 1) { + fprintf(stream, ", "); + } + } fprintf(stream, "]"); } diff --git a/examples/mbed/z_sub.cpp b/examples/mbed/z_sub.cpp index 5b8a56716..537630d6a 100644 --- a/examples/mbed/z_sub.cpp +++ b/examples/mbed/z_sub.cpp @@ -31,12 +31,12 @@ #define KEYEXPR "demo/example/**" void data_handler(const z_loaned_sample_t *sample, void *arg) { - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); - printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_str_data(z_str_loan(&keystr)), (int)payload->len, + printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_str_data(z_string_loan(&keystr)), (int)payload->len, payload->start); - z_str_drop(z_str_move(&keystr)); + z_string_drop(z_string_move(&keystr)); } int main(int argc, char **argv) { diff --git a/examples/unix/c11/z_get.c b/examples/unix/c11/z_get.c index f810adfbf..132f566f2 100644 --- a/examples/unix/c11/z_get.c +++ b/examples/unix/c11/z_get.c @@ -41,7 +41,7 @@ void reply_handler(const z_loaned_reply_t *reply, void *ctx) { (void)(ctx); if (z_reply_is_ok(reply)) { const z_loaned_sample_t *sample = z_reply_ok(reply); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); printf(">> Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)z_sample_payload(sample)->len, z_sample_payload(sample)->start); @@ -132,7 +132,8 @@ int main(int argc, char **argv) { z_get_options_t opts; z_get_options_default(&opts); if (value != NULL) { - opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); + // TODO(sashacmc): encoding + // opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); } #if Z_FEATURE_ATTACHMENT == 1 z_owned_bytes_map_t map = z_bytes_map_new(); diff --git a/examples/unix/c11/z_get_channel.c b/examples/unix/c11/z_get_channel.c index ed96149fc..d2f4c0a41 100644 --- a/examples/unix/c11/z_get_channel.c +++ b/examples/unix/c11/z_get_channel.c @@ -91,7 +91,8 @@ int main(int argc, char **argv) { z_get_options_t opts; z_get_options_default(&opts); if (value != NULL) { - opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); + // TODO(sashacmc): encoding + // opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); } z_owned_reply_ring_channel_t channel; z_reply_ring_channel_new(&channel, 1); @@ -105,7 +106,7 @@ int main(int argc, char **argv) { for (z_call(channel.recv, &reply); z_check(reply); z_call(channel.recv, &reply)) { if (z_reply_is_ok(z_loan(reply))) { const z_loaned_sample_t *sample = z_reply_ok(z_loan(reply)); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); printf(">> Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)z_sample_payload(sample)->len, z_sample_payload(sample)->start); diff --git a/examples/unix/c11/z_pull.c b/examples/unix/c11/z_pull.c index 61a0f283a..5b396c265 100644 --- a/examples/unix/c11/z_pull.c +++ b/examples/unix/c11/z_pull.c @@ -88,7 +88,7 @@ int main(int argc, char **argv) { z_null(&sample); while (true) { for (z_call(channel.try_recv, &sample); z_check(sample); z_call(channel.try_recv, &sample)) { - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(z_loan(sample)), &keystr); printf(">> [Subscriber] Pulled ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)z_sample_payload(z_loan(sample))->len, z_sample_payload(z_loan(sample))->start); diff --git a/examples/unix/c11/z_queryable.c b/examples/unix/c11/z_queryable.c index 27d1c69d4..08ced0e1f 100644 --- a/examples/unix/c11/z_queryable.c +++ b/examples/unix/c11/z_queryable.c @@ -33,15 +33,16 @@ int8_t attachment_handler(z_bytes_t key, z_bytes_t att_value, void *ctx) { void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_query_keyexpr(query), &keystr); - // TODO(sashacmc): z_query_parameters - // z_bytes_t pred = z_query_parameters(query); - // z_value_t payload_value = z_query_value(query); - // printf(">> [Queryable handler] Received Query '%s?%.*s'\n", z_str_data(z_loan(keystr)), (int)pred.len, - // pred.start); if (payload_value.payload.len > 0) { - // printf(" with value '%.*s'\n", (int)payload_value.payload.len, payload_value.payload.start); - // } + z_view_string_t params; + z_query_parameters(query, ¶ms); + printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_loan(keystr)), (int)z_loan(params)->len, + z_loan(params)->val); + const z_loaned_value_t *payload_value = z_query_value(query); + if (payload_value->payload.len > 0) { + printf(" with value '%.*s'\n", (int)payload_value->payload.len, payload_value->payload.start); + } #if Z_FEATURE_ATTACHMENT == 1 z_attachment_t attachment = z_query_attachment(query); if (z_attachment_check(&attachment)) { @@ -61,7 +62,9 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { options.attachment = z_bytes_map_as_attachment(&map); #endif - z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)value, strlen(value), &options); + z_owned_bytes_t reply_payload; + // TODO(sashacmc): value encoding + z_query_reply(query, z_query_keyexpr(query), z_move(reply_payload), &options); z_drop(z_move(keystr)); msg_nb++; diff --git a/examples/unix/c11/z_queryable_channel.c b/examples/unix/c11/z_queryable_channel.c index 8487afab6..ce128023a 100644 --- a/examples/unix/c11/z_queryable_channel.c +++ b/examples/unix/c11/z_queryable_channel.c @@ -100,19 +100,21 @@ int main(int argc, char **argv) { z_null(&query); for (z_call(channel.recv, &query); z_check(query); z_call(channel.recv, &query)) { const z_loaned_query_t *q = z_loan(query); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_query_keyexpr(q), &keystr); - // TODO(sashacmc): - // z_bytes_t pred = z_query_parameters(&q); - // z_value_t payload_value = z_query_value(&q); - // printf(" >> [Queryable handler] Received Query '%s?%.*s'\n", z_str_data(z_loan(keystr)), (int)pred.len, - // pred.start); if (payload_value.payload.len > 0) { - // printf(" with value '%.*s'\n", (int)payload_value.payload.len, payload_value.payload.start); - //} + z_view_string_t params; + z_query_parameters(q, ¶ms); + printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_loan(keystr)), + (int)z_loan(params)->len, z_loan(params)->val); + const z_loaned_value_t *payload_value = z_query_value(q); + if (payload_value->payload.len > 0) { + printf(" with value '%.*s'\n", (int)payload_value->payload.len, payload_value->payload.start); + } z_query_reply_options_t options; z_query_reply_options_default(&options); - options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); - z_query_reply(q, z_loan(ke), (const unsigned char *)value, strlen(value), &options); + z_owned_bytes_t reply_payload; + // TODO(sashacmc): value encoding + z_query_reply(q, z_query_keyexpr(q), z_move(reply_payload), &options); z_drop(z_move(keystr)); z_drop(z_move(query)); } diff --git a/examples/unix/c11/z_scout.c b/examples/unix/c11/z_scout.c index beba299ee..a39bd2226 100644 --- a/examples/unix/c11/z_scout.c +++ b/examples/unix/c11/z_scout.c @@ -41,18 +41,17 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { } } -void fprintlocators(FILE *stream, const z_str_array_t *locs) { +void fprintlocators(FILE *stream, const z_loaned_string_array_t *locs) { fprintf(stream, "["); - (void)locs; - // TODO(sashacmc): - // for (unsigned int i = 0; i < z_str_array_len(locs); i++) { - // fprintf(stream, "\""); - // fprintf(stream, "%s", *z_str_array_get(locs, i)); - // fprintf(stream, "\""); - // if (i < z_str_array_len(locs) - 1) { - // fprintf(stream, ", "); - // } - //} + for (unsigned int i = 0; i < z_string_array_len(locs); i++) { + fprintf(stream, "\""); + const z_loaned_string_t *str = z_string_array_get(locs, i); + fprintf(stream, "%.*s", (int)str->len, str->val); + fprintf(stream, "\""); + if (i < z_string_array_len(locs) - 1) { + fprintf(stream, ", "); + } + } fprintf(stream, "]"); } diff --git a/examples/unix/c11/z_sub.c b/examples/unix/c11/z_sub.c index 3b1e0865d..df6bf9e07 100644 --- a/examples/unix/c11/z_sub.c +++ b/examples/unix/c11/z_sub.c @@ -34,7 +34,7 @@ int8_t attachment_handler(z_bytes_t key, z_bytes_t value, void *ctx) { void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)payload->len, payload->start); diff --git a/examples/unix/c11/z_sub_channel.c b/examples/unix/c11/z_sub_channel.c index 83985a7c6..1067a475f 100644 --- a/examples/unix/c11/z_sub_channel.c +++ b/examples/unix/c11/z_sub_channel.c @@ -78,7 +78,7 @@ int main(int argc, char **argv) { z_owned_sample_t sample; z_null(&sample); for (z_call(channel.recv, &sample); z_check(sample); z_call(channel.recv, &sample)) { - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(z_loan(sample)), &keystr); printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)z_sample_payload(z_loan(sample))->len, z_sample_payload(z_loan(sample))->start); diff --git a/examples/unix/c11/z_sub_st.c b/examples/unix/c11/z_sub_st.c index 0deee874f..852011459 100644 --- a/examples/unix/c11/z_sub_st.c +++ b/examples/unix/c11/z_sub_st.c @@ -25,7 +25,7 @@ static int msg_nb = 0; void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)payload->len, payload->start); diff --git a/examples/unix/c99/z_get.c b/examples/unix/c99/z_get.c index 457b5ecc4..38a6339c7 100644 --- a/examples/unix/c99/z_get.c +++ b/examples/unix/c99/z_get.c @@ -33,11 +33,11 @@ void reply_handler(const z_loaned_reply_t *reply, void *ctx) { (void)(ctx); if (z_reply_is_ok(reply)) { const z_loaned_sample_t *sample = z_reply_ok(reply); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); - printf(">> Received ('%s': '%.*s')\n", z_str_data(z_str_loan(&keystr)), (int)payload->len, payload->start); - z_str_drop(z_str_move(&keystr)); + printf(">> Received ('%s': '%.*s')\n", z_str_data(z_string_loan(&keystr)), (int)payload->len, payload->start); + z_string_drop(z_string_move(&keystr)); } else { printf(">> Received an error\n"); } @@ -118,7 +118,8 @@ int main(int argc, char **argv) { z_get_options_t opts; z_get_options_default(&opts); if (value != NULL) { - opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); + // TODO(sashacmc): encoding + // opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); } z_owned_closure_reply_t callback; z_closure_reply(&callback, reply_handler, reply_dropper, NULL); diff --git a/examples/unix/c99/z_pull.c b/examples/unix/c99/z_pull.c index e93bd9db6..0760264de 100644 --- a/examples/unix/c99/z_pull.c +++ b/examples/unix/c99/z_pull.c @@ -22,11 +22,11 @@ // @TODO // void data_handler(const z_loaned_sample_t *sample, void *ctx) { // (void)(ctx); -// z_owned_str_t keystr; +// z_owned_string_t keystr; // z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); -// printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_str_loan(&keystr)), (int)sample->payload.len, +// printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_string_loan(&keystr)), (int)sample->payload.len, // sample->payload.start); -// z_str_drop(z_str_move(&keystr)); +// z_string_drop(z_string_move(&keystr)); // } int main(int argc, char **argv) { diff --git a/examples/unix/c99/z_queryable.c b/examples/unix/c99/z_queryable.c index 7f2b4adc9..df3a8a6e2 100644 --- a/examples/unix/c99/z_queryable.c +++ b/examples/unix/c99/z_queryable.c @@ -24,17 +24,19 @@ const char *value = "Queryable from Pico!"; void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_query_keyexpr(query), &keystr); - z_view_str_t pred; - z_query_parameters(query, &pred); - printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_str_loan(&keystr)), - (int)z_view_str_loan(&pred)->len, z_view_str_loan(&pred)->val); + z_view_string_t params; + z_query_parameters(query, ¶ms); + printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_string_loan(&keystr)), + (int)z_view_string_loan(¶ms)->len, z_view_string_loan(¶ms)->val); z_query_reply_options_t options; z_query_reply_options_default(&options); options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); - z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)value, strlen(value), &options); - z_str_drop(z_str_move(&keystr)); + z_owned_bytes_t reply_payload; + // TODO(sashacmc): value encoding + z_query_reply(query, z_query_keyexpr(query), z_bytes_move(&reply_payload), &options); + z_string_drop(z_string_move(&keystr)); } int main(int argc, char **argv) { diff --git a/examples/unix/c99/z_scout.c b/examples/unix/c99/z_scout.c index cd07d9778..d94c278f4 100644 --- a/examples/unix/c99/z_scout.c +++ b/examples/unix/c99/z_scout.c @@ -40,18 +40,17 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { } } -void fprintlocators(FILE *stream, const z_str_array_t *locs) { +void fprintlocators(FILE *stream, const z_loaned_string_array_t *locs) { fprintf(stream, "["); - (void)locs; - // TODO(sashacmc): z_str_array_t - // for (unsigned int i = 0; i < z_str_array_len(locs); i++) { - // fprintf(stream, "\""); - // fprintf(stream, "%s", *z_str_array_get(locs, i)); - // fprintf(stream, "\""); - // if (i < z_str_array_len(locs) - 1) { - // fprintf(stream, ", "); - // } - //} + for (unsigned int i = 0; i < z_string_array_len(locs); i++) { + fprintf(stream, "\""); + const z_loaned_string_t *str = z_string_array_get(locs, i); + fprintf(stream, "%.*s", (int)str->len, str->val); + fprintf(stream, "\""); + if (i < z_string_array_len(locs) - 1) { + fprintf(stream, ", "); + } + } fprintf(stream, "]"); } diff --git a/examples/unix/c99/z_sub.c b/examples/unix/c99/z_sub.c index 4276819ea..fa05fc001 100644 --- a/examples/unix/c99/z_sub.c +++ b/examples/unix/c99/z_sub.c @@ -22,12 +22,12 @@ #if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_loaned_sample_t *sample, void *arg) { (void)(arg); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); - printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_str_loan(&keystr)), (int)payload->len, + printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_string_loan(&keystr)), (int)payload->len, payload->start); - z_str_drop(z_str_move(&keystr)); + z_string_drop(z_string_move(&keystr)); } int main(int argc, char **argv) { diff --git a/examples/unix/c99/z_sub_st.c b/examples/unix/c99/z_sub_st.c index 5a3e83e02..f97540233 100644 --- a/examples/unix/c99/z_sub_st.c +++ b/examples/unix/c99/z_sub_st.c @@ -25,12 +25,12 @@ static int msg_nb = 0; void data_handler(const z_loaned_sample_t *sample, void *arg) { (void)(arg); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); - printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_str_loan(&keystr)), (int)payload->len, + printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_string_loan(&keystr)), (int)payload->len, payload->start); - z_str_drop(z_str_move(&keystr)); + z_string_drop(z_string_move(&keystr)); msg_nb++; } diff --git a/examples/windows/z_get.c b/examples/windows/z_get.c index e614f4f77..405b1a279 100644 --- a/examples/windows/z_get.c +++ b/examples/windows/z_get.c @@ -32,7 +32,7 @@ void reply_handler(const z_loaned_reply_t *reply, void *ctx) { (void)(ctx); if (z_reply_is_ok(reply)) { const z_loaned_sample_t *sample = z_reply_ok(reply); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(">> Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)payload->len, payload->start); @@ -83,7 +83,8 @@ int main(int argc, char **argv) { z_get_options_t opts; z_get_options_default(&opts); if (value != NULL) { - opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); + // TODO(sashacmc): encoding + // opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); } z_owned_closure_reply_t callback; z_closure(&callback, reply_handler, reply_dropper); diff --git a/examples/windows/z_pull.c b/examples/windows/z_pull.c index 5cc5be9ce..5dd66e558 100644 --- a/examples/windows/z_pull.c +++ b/examples/windows/z_pull.c @@ -21,7 +21,7 @@ // @TODO // void data_handler(const z_loaned_sample_t *sample, void *ctx) { // (void)(ctx); -// z_owned_str_t keystr; +// z_owned_string_t keystr; // z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); // printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)sample->payload.len, // sample->payload.start); diff --git a/examples/windows/z_queryable.c b/examples/windows/z_queryable.c index 0c409b597..d810c0926 100644 --- a/examples/windows/z_queryable.c +++ b/examples/windows/z_queryable.c @@ -23,20 +23,24 @@ const char *value = "Queryable from Pico!"; void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_query_keyexpr(query), &keystr); - // TODO(sashacmc): - // z_bytes_t pred = z_query_parameters(query); - // z_value_t payload_value = z_query_value(query); - // printf(" >> [Queryable handler] Received Query '%s?%.*s'\n", z_str_data(z_loan(keystr)), (int)pred.len, - // pred.start); - // if (payload_value.payload.len > 0) { - // printf(" with value '%.*s'\n", (int)payload_value.payload.len, payload_value.payload.start); - // } + + z_view_string_t params; + z_query_parameters(query, ¶ms); + printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_loan(keystr)), (int)z_loan(params)->len, + z_loan(params)->val); + const z_loaned_value_t *payload_value = z_query_value(query); + if (payload_value->payload.len > 0) { + printf(" with value '%.*s'\n", (int)payload_value->payload.len, payload_value->payload.start); + } + z_query_reply_options_t options; z_query_reply_options_default(&options); - options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); - z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)value, strlen(value), &options); + z_owned_bytes_t reply_payload; + // TODO(sashacmc): value encoding + z_query_reply(query, z_query_keyexpr(query), z_move(reply_payload), &options); + z_drop(z_move(keystr)); } diff --git a/examples/windows/z_scout.c b/examples/windows/z_scout.c index a89ddd038..dfd993637 100644 --- a/examples/windows/z_scout.c +++ b/examples/windows/z_scout.c @@ -40,18 +40,17 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { } } -void fprintlocators(FILE *stream, const z_str_array_t *locs) { +void fprintlocators(FILE *stream, const z_loaned_string_array_t *locs) { fprintf(stream, "["); - (void)locs; - // TODO(sashacmc): z_str_array missed - // for (unsigned int i = 0; i < z_str_array_len(locs); i++) { - // fprintf(stream, "\""); - // fprintf(stream, "%s", *z_str_array_get(locs, i)); - // fprintf(stream, "\""); - // if (i < z_str_array_len(locs) - 1) { - // fprintf(stream, ", "); - // } - //} + for (unsigned int i = 0; i < z_string_array_len(locs); i++) { + fprintf(stream, "\""); + const z_loaned_string_t *str = z_string_array_get(locs, i); + fprintf(stream, "%.*s", (int)str->len, str->val); + fprintf(stream, "\""); + if (i < z_string_array_len(locs) - 1) { + fprintf(stream, ", "); + } + } fprintf(stream, "]"); } diff --git a/examples/windows/z_sub.c b/examples/windows/z_sub.c index 298d54b4f..e908f2534 100644 --- a/examples/windows/z_sub.c +++ b/examples/windows/z_sub.c @@ -21,7 +21,7 @@ #if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)payload->len, payload->start); diff --git a/examples/windows/z_sub_st.c b/examples/windows/z_sub_st.c index 4276a4ecb..fed96e89c 100644 --- a/examples/windows/z_sub_st.c +++ b/examples/windows/z_sub_st.c @@ -24,7 +24,7 @@ int msg_nb = 0; #if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)payload->len, payload->start); diff --git a/examples/zephyr/z_get.c b/examples/zephyr/z_get.c index 0a0d8cf1b..58b0d9221 100644 --- a/examples/zephyr/z_get.c +++ b/examples/zephyr/z_get.c @@ -36,7 +36,7 @@ void reply_dropper(void *ctx) { printf(" >> Received query final notification\n" void reply_handler(const z_loaned_reply_t *oreply, void *ctx) { if (z_reply_is_ok(oreply)) { const z_loaned_sample_t *sample = z_reply_ok(oreply); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(" >> Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)payload->len, payload->start); diff --git a/examples/zephyr/z_pull.c b/examples/zephyr/z_pull.c index cdab228bf..374c6e8d3 100644 --- a/examples/zephyr/z_pull.c +++ b/examples/zephyr/z_pull.c @@ -31,7 +31,7 @@ // @TODO // void data_handler(const z_loaned_sample_t *sample, void *arg) { -// z_owned_str_t keystr; +// z_owned_string_t keystr; // z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); // printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), // (int)sample->payload.len, diff --git a/examples/zephyr/z_queryable.c b/examples/zephyr/z_queryable.c index 3950bc1b8..68fc5d4d8 100644 --- a/examples/zephyr/z_queryable.c +++ b/examples/zephyr/z_queryable.c @@ -33,13 +33,16 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_query_keyexpr(query), &keystr); - // TODO(sashacmc): z_query_parameters - // z_bytes_t pred = z_query_parameters(query); - // printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_loan(keystr)), (int)pred.len, - // pred.start); - z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)VALUE, strlen(VALUE), NULL); + z_view_string_t params; + z_query_parameters(query, ¶ms); + printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_loan(keystr)), z_loan(params)->len, + z_loan(params)->val); + + z_owned_bytes_t reply_payload; + // TODO(sashacmc): VALUE encoding + z_query_reply(query, z_query_keyexpr(query), z_move(reply_payload), NULL); z_drop(z_move(keystr)); } diff --git a/examples/zephyr/z_scout.c b/examples/zephyr/z_scout.c index 3f1c9c93e..06c8277b5 100644 --- a/examples/zephyr/z_scout.c +++ b/examples/zephyr/z_scout.c @@ -37,18 +37,17 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { } } -void fprintlocators(FILE *stream, const z_str_array_t *locs) { +void fprintlocators(FILE *stream, const z_loaned_string_array_t *locs) { fprintf(stream, "["); - (void)locs; - // TODO(sashacmc): z_str_array missed - // for (unsigned int i = 0; i < z_str_array_len(locs); i++) { - // fprintf(stream, "\""); - // fprintf(stream, "%s", *z_str_array_get(locs, i)); - // fprintf(stream, "\""); - // if (i < z_str_array_len(locs) - 1) { - // fprintf(stream, ", "); - // } - //} + for (unsigned int i = 0; i < z_string_array_len(locs); i++) { + fprintf(stream, "\""); + const z_loaned_string_t *str = z_string_array_get(locs, i); + fprintf(stream, "%.*s", (int)str->len, str->val); + fprintf(stream, "\""); + if (i < z_string_array_len(locs) - 1) { + fprintf(stream, ", "); + } + } fprintf(stream, "]"); } diff --git a/examples/zephyr/z_sub.c b/examples/zephyr/z_sub.c index 362b249a2..81b97ad01 100644 --- a/examples/zephyr/z_sub.c +++ b/examples/zephyr/z_sub.c @@ -30,7 +30,7 @@ #define KEYEXPR "demo/example/**" void data_handler(const z_loaned_sample_t *sample, void *arg) { - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); const z_loaned_bytes_t *payload = z_sample_payload(sample); printf(" >> [Subscriber handler] Received ('%s': '%.*s')\n", z_str_data(z_loan(keystr)), (int)payload->len, diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index 18ea8acc4..bf5cf8c96 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -42,11 +42,12 @@ z_owned_publisher_t : z_publisher_loan, \ z_owned_reply_t : z_reply_loan, \ z_owned_hello_t : z_hello_loan, \ - z_owned_str_t : z_str_loan, \ - z_view_str_t : z_view_str_loan, \ - z_owned_str_array_t : z_str_array_loan, \ + z_owned_string_t : z_string_loan, \ + z_view_string_t : z_view_string_loan, \ + z_owned_string_array_t : z_string_array_loan, \ z_owned_sample_t : z_sample_loan, \ - z_owned_query_t : z_query_loan \ + z_owned_query_t : z_query_loan, \ + z_owned_bytes_t : z_bytes_loan \ )(&x) #define z_loan_mut(x) _Generic((x), \ @@ -57,10 +58,12 @@ z_owned_publisher_t : z_publisher_loan_mut, \ z_owned_reply_t : z_reply_loan_mut, \ z_owned_hello_t : z_hello_loan_mut, \ - z_owned_str_t : z_str_loan_mut, \ - z_owned_str_array_t : z_str_array_loan_mut, \ + z_owned_string_t : z_string_loan_mut, \ + z_view_string_t : z_view_string_loan_mut, \ + z_owned_string_array_t : z_string_array_loan_mut, \ z_owned_sample_t : z_sample_loan_mut, \ - z_owned_query_t : z_query_loan_mut \ + z_owned_query_t : z_query_loan_mut, \ + z_owned_bytes_t : z_bytes_loan_mut \ )(&x) /** * Defines a generic function for dropping any of the ``z_owned_X_t`` types. @@ -78,8 +81,8 @@ z_owned_queryable_t * : z_queryable_drop, \ z_owned_reply_t * : z_reply_drop, \ z_owned_hello_t * : z_hello_drop, \ - z_owned_str_t * : z_str_drop, \ - z_owned_str_array_t * : z_str_array_drop, \ + z_owned_string_t * : z_string_drop, \ + z_owned_string_array_t * : z_string_array_drop, \ z_owned_sample_t * : z_sample_drop, \ z_owned_query_t * : z_query_drop, \ z_owned_closure_sample_t * : z_closure_sample_drop, \ @@ -109,7 +112,7 @@ #define z_check(x) _Generic((x), \ z_owned_keyexpr_t : z_keyexpr_check, \ z_view_keyexpr_t : z_keyexpr_is_initialized, \ - z_value_t : z_value_is_initialized, \ + z_owned_value_t : z_value_check, \ z_owned_config_t : z_config_check, \ z_owned_scouting_config_t : z_scouting_config_check, \ z_owned_session_t : z_session_check, \ @@ -118,8 +121,8 @@ z_owned_queryable_t : z_queryable_check, \ z_owned_reply_t : z_reply_check, \ z_owned_hello_t : z_hello_check, \ - z_owned_str_t : z_str_check, \ - z_owned_str_array_t : z_str_array_check, \ + z_owned_string_t : z_string_check, \ + z_owned_string_array_t : z_string_array_check, \ z_owned_bytes_t : z_bytes_check, \ z_owned_sample_t : z_sample_check, \ z_owned_query_t : z_query_check \ @@ -161,8 +164,8 @@ z_owned_queryable_t : z_queryable_move, \ z_owned_reply_t : z_reply_move, \ z_owned_hello_t : z_hello_move, \ - z_owned_str_t : z_str_move, \ - z_owned_str_array_t : z_str_array_move, \ + z_owned_string_t : z_string_move, \ + z_owned_string_array_t : z_string_array_move, \ z_owned_closure_sample_t : z_closure_sample_move, \ z_owned_closure_owned_sample_t : z_closure_owned_sample_move, \ z_owned_closure_query_t : z_closure_query_move, \ @@ -172,6 +175,7 @@ z_owned_closure_zid_t : z_closure_zid_move, \ z_owned_sample_t : z_sample_move, \ z_owned_query_t : z_query_move, \ + z_owned_bytes_t : z_bytes_move, \ z_owned_sample_ring_channel_t : z_sample_ring_channel_move, \ z_owned_sample_fifo_channel_t : z_sample_fifo_channel_move, \ z_owned_query_ring_channel_t : z_query_ring_channel_move, \ @@ -198,8 +202,8 @@ z_owned_queryable_t : z_queryable_clone, \ z_owned_reply_t : z_reply_clone, \ z_owned_hello_t : z_hello_clone, \ - z_owned_str_t : z_str_clone, \ - z_owned_str_array_t : z_str_array_clone \ + z_owned_string_t : z_string_clone, \ + z_owned_string_array_t : z_string_array_clone \ )(&x) /** @@ -219,7 +223,7 @@ z_owned_query_t * : z_query_null, \ z_owned_reply_t * : z_reply_null, \ z_owned_hello_t * : z_hello_null, \ - z_owned_str_t * : z_str_null, \ + z_owned_string_t * : z_string_null, \ z_owned_closure_sample_t * : z_closure_sample_null, \ z_owned_closure_owned_sample_t * : z_closure_owned_sample_null, \ z_owned_closure_query_t * : z_closure_query_null, \ @@ -265,14 +269,14 @@ template<> struct zenoh_loan_type{ typedef z_keyexpr_t type; template<> struct zenoh_loan_type{ typedef z_config_t type; }; template<> struct zenoh_loan_type{ typedef z_publisher_t type; }; template<> struct zenoh_loan_type{ typedef z_hello_t type; }; -template<> struct zenoh_loan_type{ typedef const char* type; }; +template<> struct zenoh_loan_type{ typedef const char* type; }; template<> inline z_session_t z_loan(const z_owned_session_t& x) { return z_session_loan(&x); } template<> inline z_keyexpr_t z_loan(const z_owned_keyexpr_t& x) { return z_keyexpr_loan(&x); } template<> inline z_config_t z_loan(const z_owned_config_t& x) { return z_config_loan(&x); } template<> inline z_publisher_t z_loan(const z_owned_publisher_t& x) { return z_publisher_loan(&x); } template<> inline z_hello_t z_loan(const z_owned_hello_t& x) { return z_hello_loan(&x); } -template<> inline const char* z_loan(const z_owned_str_t& x) { return z_str_loan(&x); } +template<> inline const char* z_loan(const z_owned_string_t& x) { return z_string_loan(&x); } template struct zenoh_drop_type { typedef T type; }; template inline typename zenoh_drop_type::type z_drop(T*); @@ -286,7 +290,7 @@ template<> struct zenoh_drop_type { typedef int8_t type; } template<> struct zenoh_drop_type { typedef int8_t type; }; template<> struct zenoh_drop_type { typedef void type; }; template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; +template<> struct zenoh_drop_type { typedef void type; }; template<> struct zenoh_drop_type { typedef void type; }; template<> struct zenoh_drop_type { typedef void type; }; template<> struct zenoh_drop_type { typedef void type; }; @@ -305,7 +309,7 @@ template<> inline int8_t z_drop(z_owned_subscriber_t* v) { return z_undeclare_su template<> inline int8_t z_drop(z_owned_queryable_t* v) { return z_undeclare_queryable(v); } template<> inline void z_drop(z_owned_reply_t* v) { z_reply_drop(v); } template<> inline void z_drop(z_owned_hello_t* v) { z_hello_drop(v); } -template<> inline void z_drop(z_owned_str_t* v) { z_str_drop(v); } +template<> inline void z_drop(z_owned_string_t* v) { z_string_drop(v); } template<> inline void z_drop(z_owned_closure_sample_t* v) { z_closure_sample_drop(v); } template<> inline void z_drop(z_owned_closure_owned_sample_t* v) { z_closure_owned_sample_drop(v); } template<> inline void z_drop(z_owned_closure_query_t* v) { z_closure_query_drop(v); } @@ -328,7 +332,7 @@ inline void z_null(z_owned_subscriber_t* v) { z_subscriber_null(v); } inline void z_null(z_owned_queryable_t* v) { z_queryable_null(v); } inline void z_null(z_owned_reply_t* v) { z_reply_null(v); } inline void z_null(z_owned_hello_t* v) { z_hello_null(v); } -inline void z_null(z_owned_str_t* v) { z_str_null(v); } +inline void z_null(z_owned_string_t* v) { z_string_null(v); } inline void z_null(z_owned_closure_sample_t* v) { z_closure_sample_null(v); } inline void z_null(z_owned_clusure_owned_sample_t* v) { z_closure_owned_sample_null(v); } inline void z_null(z_owned_closure_query_t* v) { z_closure_query_null(v); } @@ -348,8 +352,8 @@ inline bool z_check(const z_owned_subscriber_t& v) { return z_subscriber_check(& inline bool z_check(const z_owned_queryable_t& v) { return z_queryable_check(&v); } inline bool z_check(const z_owned_reply_t& v) { return z_reply_check(&v); } inline bool z_check(const z_owned_hello_t& v) { return z_hello_check(&v); } -inline bool z_check(const z_owned_str_t& v) { return z_str_check(&v); } -inline bool z_check(const z_owned_str_t& v) { return z_sample_check(&v); } +inline bool z_check(const z_owned_string_t& v) { return z_string_check(&v); } +inline bool z_check(const z_owned_string_t& v) { return z_sample_check(&v); } inline void z_call(const z_owned_closure_sample_t &closure, const z_loaned_sample_t *sample) { z_closure_sample_call(&closure, sample); } diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 622274f5c..6daa41f20 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -45,7 +45,7 @@ extern "C" { * Returns: * The :c:type:`z_string_t` corresponding to the given string. */ -int8_t z_view_str_wrap(z_view_str_t *str, const char *value); +int8_t z_view_str_wrap(z_view_string_t *str, const char *value); /** * Constructs a :c:type:`z_keyexpr_t` departing from a string. @@ -71,9 +71,6 @@ int8_t z_view_keyexpr_from_string(z_view_keyexpr_t *keyexpr, const char *name); * Returns: * The :c:type:`z_keyexpr_t` corresponding to the given string. */ -// TODO(sashacmc): -z_owned_keyexpr_t z_keyexpr_unchecked(const char *name); - int8_t z_view_keyexpr_from_string_unchecked(z_view_keyexpr_t *keyexpr, const char *name); /** @@ -87,9 +84,9 @@ int8_t z_view_keyexpr_from_string_unchecked(z_view_keyexpr_t *keyexpr, const cha * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` * * Returns: - * The :c:type:`z_owned_str_t` containing key expression string representation if it's possible + * The :c:type:`z_owned_string_t` containing key expression string representation if it's possible */ -void z_keyexpr_to_string(const z_loaned_keyexpr_t *keyexpr, z_owned_str_t *s); +void z_keyexpr_to_string(const z_loaned_keyexpr_t *keyexpr, z_owned_string_t *s); /** * Returns the key expression's internal string by aliasing it. @@ -127,7 +124,7 @@ _Bool zp_keyexpr_was_declared(const z_loaned_keyexpr_t *keyexpr); * Returns: * The string representation of a keyexpr for a given session. */ -int8_t zp_keyexpr_resolve(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_owned_str_t *str); +int8_t zp_keyexpr_resolve(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_owned_string_t *str); /** * Checks if a given keyexpr is valid. @@ -519,7 +516,7 @@ z_query_consolidation_t z_query_consolidation_none(void); * Returns the value selector wrapped as a :c:type:`z_loaned_bytes_t*`, since value selector is a user-defined * representation. */ -void z_query_parameters(const z_loaned_query_t *query, z_view_str_t *parameters); +void z_query_parameters(const z_loaned_query_t *query, z_view_string_t *parameters); /** * Get a query's payload value by aliasing it. @@ -531,7 +528,7 @@ void z_query_parameters(const z_loaned_query_t *query, z_view_str_t *parameters) * Returns: * Returns the payload wrapped as a :c:type:`z_value_t`, since payload value is a user-defined representation. */ -z_value_t z_query_value(const z_loaned_query_t *query); +const z_loaned_value_t *z_query_value(const z_loaned_query_t *query); #if Z_FEATURE_ATTACHMENT == 1 /** @@ -784,7 +781,7 @@ int8_t z_closure_zid(z_owned_closure_zid_t *closure, z_id_handler_t call, z_drop void z_##name##_drop(ownedtype *obj); \ void z_##name##_null(ownedtype *obj); -_OWNED_FUNCTIONS(z_loaned_str_t, z_owned_str_t, str) +_OWNED_FUNCTIONS(z_loaned_string_t, z_owned_string_t, string) _OWNED_FUNCTIONS(z_loaned_keyexpr_t, z_owned_keyexpr_t, keyexpr) _OWNED_FUNCTIONS(z_loaned_config_t, z_owned_config_t, config) _OWNED_FUNCTIONS(z_loaned_scouting_config_t, z_owned_scouting_config_t, scouting_config) @@ -794,10 +791,11 @@ _OWNED_FUNCTIONS(z_loaned_publisher_t, z_owned_publisher_t, publisher) _OWNED_FUNCTIONS(z_loaned_queryable_t, z_owned_queryable_t, queryable) _OWNED_FUNCTIONS(z_loaned_hello_t, z_owned_hello_t, hello) _OWNED_FUNCTIONS(z_loaned_reply_t, z_owned_reply_t, reply) -_OWNED_FUNCTIONS(z_loaned_str_array_t, z_owned_str_array_t, str_array) +_OWNED_FUNCTIONS(z_loaned_string_array_t, z_owned_string_array_t, string_array) _OWNED_FUNCTIONS(z_loaned_sample_t, z_owned_sample_t, sample) _OWNED_FUNCTIONS(z_loaned_query_t, z_owned_query_t, query) _OWNED_FUNCTIONS(z_loaned_bytes_t, z_owned_bytes_t, bytes) +_OWNED_FUNCTIONS(z_loaned_value_t, z_owned_value_t, value) #define _OWNED_FUNCTIONS_CLOSURE(ownedtype, name) \ _Bool z_##name##_check(const ownedtype *val); \ @@ -820,7 +818,7 @@ _OWNED_FUNCTIONS_CLOSURE(z_owned_closure_zid_t, closure_zid) void z_view_##name##_null(viewtype *name); _VIEW_FUNCTIONS(z_loaned_keyexpr_t, z_view_keyexpr_t, keyexpr) -_VIEW_FUNCTIONS(z_loaned_str_t, z_view_str_t, str) +_VIEW_FUNCTIONS(z_loaned_string_t, z_view_string_t, string) // Gets internal value from refcountered type (e.g. z_loaned_session_t, z_query_t) #define _Z_RC_IN_VAL(arg) ((arg)->in->val) @@ -830,7 +828,7 @@ _VIEW_FUNCTIONS(z_loaned_str_t, z_view_str_t, str) // TODO(sashacmc): comments, docs, etc. const z_loaned_sample_t *z_sample_loan(const z_owned_sample_t *sample); -const char *z_str_data(const z_loaned_str_t *str); +const char *z_str_data(const z_loaned_string_t *str); /************* Primitives **************/ /** @@ -1174,7 +1172,7 @@ void z_get_options_default(z_get_options_t *options); * Returns ``0`` if the put operation is successful, or a ``negative value`` otherwise. */ int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const char *parameters, - z_owned_closure_reply_t *callback, const z_get_options_t *options); + z_owned_closure_reply_t *callback, z_get_options_t *options); /** * Checks if the queryable answered with an OK, which allows this value to be treated as a sample. * @@ -1214,7 +1212,7 @@ const z_loaned_sample_t *z_reply_ok(const z_loaned_reply_t *reply); * Returns: * Returns the :c:type:`z_value_t` wrapped in the query reply. */ -z_value_t z_reply_err(const z_loaned_reply_t *reply); +const z_loaned_value_t *z_reply_err(const z_loaned_reply_t *reply); #endif #if Z_FEATURE_QUERYABLE == 1 @@ -1297,8 +1295,8 @@ void z_query_reply_options_default(z_query_reply_options_t *options); * Returns: * Returns ``0`` if the send query reply operation is successful, or a ``negative value`` otherwise. */ -int8_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, const uint8_t *payload, - size_t payload_len, const z_query_reply_options_t *options); +int8_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, z_owned_bytes_t *payload, + const z_query_reply_options_t *options); #endif /** @@ -1407,17 +1405,6 @@ int8_t z_undeclare_subscriber(z_owned_subscriber_t *sub); z_owned_keyexpr_t z_subscriber_keyexpr(z_loaned_subscriber_t *sub); #endif -/** - * Checks if a given value is valid. - * - * Parameters: - * value: A loaned instance of :c:type:`z_value_t` to be checked. - * - * Returns: - * Returns ``true`` if the value is valid, or ``false`` otherwise. - */ -_Bool z_value_is_initialized(z_value_t *value); - /************* Multi Thread Tasks helpers **************/ /** * Constructs the default values for the session read task. diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index a9f4b86de..a25577ada 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -18,6 +18,7 @@ #include "zenoh-pico/collections/bytes.h" #include "zenoh-pico/collections/element.h" #include "zenoh-pico/collections/list.h" +#include "zenoh-pico/collections/string.h" #include "zenoh-pico/net/publish.h" #include "zenoh-pico/net/query.h" #include "zenoh-pico/net/reply.h" @@ -87,9 +88,9 @@ typedef _z_id_t z_id_t; * const char *val: A pointer to the string. */ -_OWNED_TYPE_PTR(_z_string_t, str) -_LOANED_TYPE(_z_string_t, str) -_VIEW_TYPE(_z_string_t, str) +_OWNED_TYPE_PTR(_z_string_t, string) +_LOANED_TYPE(_z_string_t, string) +_VIEW_TYPE(_z_string_t, string) /** * Represents a key expression in Zenoh. @@ -207,8 +208,9 @@ typedef _z_timestamp_t z_timestamp_t; * z_encoding_t encoding: The encoding of the `payload`. * z_loaned_bytes_t* payload: The payload of this zenoh value. */ -// TODO(sashacmc): -typedef _z_value_t z_value_t; + +_OWNED_TYPE_PTR(_z_value_t, value) +_LOANED_TYPE(_z_value_t, value) /** * Represents the set of options that can be applied to a (push) subscriber, @@ -329,10 +331,12 @@ typedef struct { * Members: * z_query_target_t target: The queryables that should be targeted by this get. * z_query_consolidation_t consolidation: The replies consolidation strategy to apply on replies. - * z_value_t value: The payload to include in the query. + * z_owned_bytes_t payload: The payload to include in the query. + * z_encoding_t encoding: Payload encoding. */ typedef struct { - z_value_t value; + z_owned_bytes_t *payload; + z_encoding_t encoding; z_query_consolidation_t consolidation; z_query_target_t target; uint32_t timeout_ms; @@ -437,7 +441,7 @@ _LOANED_TYPE(_z_sample_rc_t, sample) * Members: * z_whatami_t whatami: The kind of zenoh entity. * z_loaned_bytes_t* zid: The Zenoh ID of the scouted entity (empty if absent). - * z_str_array_t locators: The locators of the scouted entity. + * z_loaned_string_array_t locators: The locators of the scouted entity. */ _OWNED_TYPE_PTR(_z_hello_t, hello) _LOANED_TYPE(_z_hello_t, hello) @@ -464,21 +468,20 @@ _LOANED_TYPE(_z_reply_rc_t, reply) /** * Represents an array of ``z_str_t``. * - * Operations over :c:type:`z_str_array_t` must be done using the provided functions: + * Operations over :c:type:`z_loaned_string_array_t` must be done using the provided functions: * - * - ``char *z_str_array_get(z_str_array_t *a, size_t k);`` - * - ``size_t z_str_array_len(z_str_array_t *a);`` - * - ``_Bool z_str_array_array_is_empty(z_str_array_t *a);`` + * - ``char *z_string_array_get(z_loaned_string_array_t *a, size_t k);`` + * - ``size_t z_string_array_len(z_loaned_string_array_t *a);`` + * - ``_Bool z_str_array_array_is_empty(z_loaned_string_array_t *a);`` */ -// TODO(sashacmc): -typedef _z_str_array_t z_str_array_t; -z_owned_str_t *z_str_array_get(const z_str_array_t *a, size_t k); -size_t z_str_array_len(const z_str_array_t *a); -_Bool z_str_array_is_empty(const z_str_array_t *a); +_OWNED_TYPE_PTR(_z_string_vec_t, string_array) +_LOANED_TYPE(_z_string_vec_t, string_array) +_VIEW_TYPE(_z_string_vec_t, string_array) -_OWNED_TYPE_PTR(z_str_array_t, str_array) -_LOANED_TYPE(z_str_array_t, str_array) +const z_loaned_string_t *z_string_array_get(const z_loaned_string_array_t *a, size_t k); +size_t z_string_array_len(const z_loaned_string_array_t *a); +_Bool z_string_array_is_empty(const z_loaned_string_array_t *a); typedef void (*z_dropper_handler_t)(void *arg); typedef void (*z_owned_sample_handler_t)(z_owned_sample_t *sample, void *arg); diff --git a/include/zenoh-pico/collections/string.h b/include/zenoh-pico/collections/string.h index cfbc33978..827017145 100644 --- a/include/zenoh-pico/collections/string.h +++ b/include/zenoh-pico/collections/string.h @@ -34,9 +34,6 @@ void _z_str_copy(char *dst, const char *src); void _z_str_n_copy(char *dst, const char *src, size_t size); _Z_ELEM_DEFINE(_z_str, char, _z_str_size, _z_noop_clear, _z_str_copy) -// This is here for reference on why -// the _z_str_array_t was not defined using this macro -// but instead manually as find below _Z_VEC_DEFINE(_z_str, char) _Z_LIST_DEFINE(_z_str, char) _Z_INT_MAP_DEFINE(_z_str, char) @@ -73,6 +70,7 @@ typedef struct { } _z_string_t; _z_string_t _z_string_make(const char *value); +_z_string_t *_z_string_make_as_ptr(const char *value); size_t _z_string_size(const _z_string_t *s); void _z_string_copy(_z_string_t *dst, const _z_string_t *src); @@ -85,28 +83,8 @@ _z_string_t _z_string_from_bytes(const _z_bytes_t *bs); _Z_ELEM_DEFINE(_z_string, _z_string_t, _z_string_size, _z_string_clear, _z_string_copy) -/*-------- str_array --------*/ -/** - * An array of NULL terminated strings. - * - * Members: - * size_t len: The length of the array. - * char **_val: A pointer to the array. - */ -typedef struct { - size_t len; - char **val; -} _z_str_array_t; - -_z_str_array_t _z_str_array_empty(void); -_z_str_array_t _z_str_array_make(size_t len); -void _z_str_array_init(_z_str_array_t *sa, size_t len); -char **_z_str_array_get(const _z_str_array_t *sa, size_t pos); -size_t _z_str_array_len(const _z_str_array_t *sa); -_Bool _z_str_array_is_empty(const _z_str_array_t *sa); -void _z_str_array_copy(_z_str_array_t *dst, const _z_str_array_t *src); -void _z_str_array_move(_z_str_array_t *dst, _z_str_array_t *src); -void _z_str_array_clear(_z_str_array_t *sa); -void _z_str_array_free(_z_str_array_t **sa); +_Z_VEC_DEFINE(_z_string, _z_string_t) +_Z_LIST_DEFINE(_z_string, _z_string_t) +_Z_INT_MAP_DEFINE(_z_string, _z_string_t) #endif /* ZENOH_PICO_COLLECTIONS_STRING_H */ diff --git a/include/zenoh-pico/protocol/core.h b/include/zenoh-pico/protocol/core.h index 4d9453fc2..fd25c4cb5 100644 --- a/include/zenoh-pico/protocol/core.h +++ b/include/zenoh-pico/protocol/core.h @@ -248,12 +248,12 @@ void _z_value_free(_z_value_t **hello); * * Members: * _z_bytes_t zid: The Zenoh ID of the scouted entity (empty if absent). - * _z_str_array_t locators: The locators of the scouted entity. + * _z_string_vec_t locators: The locators of the scouted entity. * z_whatami_t whatami: The kind of zenoh entity. */ typedef struct { _z_id_t zid; - _z_str_array_t locators; + _z_string_vec_t locators; z_whatami_t whatami; uint8_t version; } _z_hello_t; diff --git a/src/api/api.c b/src/api/api.c index d0177b867..1a24ccc81 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -43,15 +43,18 @@ /********* Data Types Handlers *********/ -int8_t z_view_str_wrap(z_view_str_t *str, const char *value) { +int8_t z_view_str_wrap(z_view_string_t *str, const char *value) { str->_val = _z_string_make(value); return _Z_RES_OK; } -// TODO(sashacmc): to z_slice_array_t ??? -// z_str_t *z_str_array_get(const z_str_array_t *a, size_t k) { return _z_str_array_get(a, k); } -// size_t z_str_array_len(const z_str_array_t *a) { return _z_str_array_len(a); } -//_Bool z_str_array_is_empty(const z_str_array_t *a) { return _z_str_array_is_empty(a); } +const z_loaned_string_t *z_string_array_get(const z_loaned_string_array_t *a, size_t k) { + return _z_string_vec_get(a, k); +} + +size_t z_string_array_len(const z_loaned_string_array_t *a) { return _z_string_vec_len(a); } + +_Bool z_string_array_is_empty(const z_loaned_string_array_t *a) { return _z_string_vec_is_empty(a); } int8_t z_view_keyexpr_from_string(z_view_keyexpr_t *keyexpr, const char *name) { keyexpr->_val = _z_rname(name); @@ -63,7 +66,7 @@ int8_t z_view_keyexpr_from_string_unchecked(z_view_keyexpr_t *keyexpr, const cha return _Z_RES_OK; } -void z_keyexpr_to_string(const z_loaned_keyexpr_t *keyexpr, z_owned_str_t *s) { +void z_keyexpr_to_string(const z_loaned_keyexpr_t *keyexpr, z_owned_string_t *s) { if (keyexpr->_id == Z_RESOURCE_ID_NONE) { s->_val = (_z_string_t *)z_malloc(sizeof(_z_string_t)); if (s->_val != NULL) { @@ -90,7 +93,7 @@ _Bool zp_keyexpr_was_declared(const z_keyexpr_t *keyexpr) { return ret; } */ -int8_t zp_keyexpr_resolve(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_owned_str_t *str) { +int8_t zp_keyexpr_resolve(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_owned_string_t *str) { _z_keyexpr_t ekey = _z_get_expanded_key_from_key(&_Z_RC_IN_VAL(zs), keyexpr); *str->_val = _z_string_make((char *)ekey._suffix); // ekey will be out of scope so // - suffix can be safely casted as non-const @@ -265,10 +268,6 @@ z_encoding_t z_encoding_default(void) { return z_encoding(Z_ENCODING_PREFIX_DEFA _Bool z_timestamp_check(z_timestamp_t ts) { return _z_timestamp_check(&ts); } -z_value_t z_value(const char *payload, size_t payload_len, z_encoding_t encoding) { - return (z_value_t){.payload = {.start = (const uint8_t *)payload, .len = payload_len}, .encoding = encoding}; -} - z_query_target_t z_query_target_default(void) { return Z_QUERY_TARGET_DEFAULT; } z_query_consolidation_t z_query_consolidation_auto(void) { @@ -289,12 +288,12 @@ z_query_consolidation_t z_query_consolidation_none(void) { z_query_consolidation_t z_query_consolidation_default(void) { return z_query_consolidation_auto(); } -void z_query_parameters(const z_loaned_query_t *query, z_view_str_t *parameters) { - // TODO(sashacmc) - // *parameters = _z_bytes_wrap((uint8_t *)query->in->val._parameters, strlen(query->in->val._parameters)); +void z_query_parameters(const z_loaned_query_t *query, z_view_string_t *parameters) { + parameters->_val.val = query->in->val._parameters; + parameters->_val.len = strlen(query->in->val._parameters); } -z_value_t z_query_value(const z_loaned_query_t *query) { return query->in->val._value; } +const z_loaned_value_t *z_query_value(const z_loaned_query_t *query) { return &query->in->val._value; } #if Z_FEATURE_ATTACHMENT == 1 z_attachment_t z_query_attachment(const z_loaned_query_t *query) { return query->in->val.attachment; } @@ -302,16 +301,6 @@ z_attachment_t z_query_attachment(const z_loaned_query_t *query) { return query- const z_loaned_keyexpr_t *z_query_keyexpr(const z_loaned_query_t *query) { return &query->in->val._key; } -_Bool z_value_is_initialized(z_value_t *value) { - _Bool ret = false; - - if ((value->payload.start != NULL)) { - ret = true; - } - - return ret; -} - void z_closure_sample_call(const z_owned_closure_sample_t *closure, const z_loaned_sample_t *sample) { if (closure->call != NULL) { (closure->call)(sample, closure->context); @@ -401,18 +390,20 @@ static inline void _z_owner_noop_copy(void *dst, const void *src) { } // TODO(sashacmc): remove -// OWNED_FUNCTIONS_STR(z_str_t, z_owned_str_t, str, _z_str_free, _z_str_n_copy) +// OWNED_FUNCTIONS_STR(z_str_t, z_owned_string_t, str, _z_str_free, _z_str_n_copy) OWNED_FUNCTIONS_PTR(_z_config_t, config, _z_owner_noop_copy, _z_config_free) OWNED_FUNCTIONS_PTR(_z_scouting_config_t, scouting_config, _z_owner_noop_copy, _z_scouting_config_free) -OWNED_FUNCTIONS_PTR(_z_string_t, str, _z_string_copy, _z_string_free) +OWNED_FUNCTIONS_PTR(_z_string_t, string, _z_string_copy, _z_string_free) +OWNED_FUNCTIONS_PTR(_z_value_t, value, _z_value_copy, _z_value_free) OWNED_FUNCTIONS_PTR(_z_keyexpr_t, keyexpr, _z_keyexpr_copy, _z_keyexpr_free) VIEW_FUNCTIONS_PTR(_z_keyexpr_t, keyexpr) -VIEW_FUNCTIONS_PTR(_z_string_t, str) +VIEW_FUNCTIONS_PTR(_z_string_t, string) OWNED_FUNCTIONS_PTR(_z_hello_t, hello, _z_owner_noop_copy, _z_hello_free) -OWNED_FUNCTIONS_PTR(_z_str_array_t, str_array, _z_owner_noop_copy, _z_str_array_free) +OWNED_FUNCTIONS_PTR(_z_string_vec_t, string_array, _z_owner_noop_copy, _z_string_vec_free) +VIEW_FUNCTIONS_PTR(_z_string_vec_t, string_array) OWNED_FUNCTIONS_PTR(_z_bytes_t, bytes, _z_bytes_copy, _z_bytes_free) OWNED_FUNCTIONS_RC(sample) @@ -597,7 +588,7 @@ z_qos_t z_sample_qos(const z_loaned_sample_t *sample) { return _Z_RC_IN_VAL(samp z_attachment_t z_sample_attachment(const z_loaned_sample_t *sample) { return _Z_RC_IN_VAL(sample).attachment; } #endif -const char *z_str_data(const z_loaned_str_t *str) { return str->val; } +const char *z_str_data(const z_loaned_string_t *str) { return str->val; } #if Z_FEATURE_PUBLICATION == 1 int8_t _z_publisher_drop(_z_publisher_t **pub) { @@ -799,8 +790,8 @@ OWNED_FUNCTIONS_RC(reply) void z_get_options_default(z_get_options_t *options) { options->target = z_query_target_default(); options->consolidation = z_query_consolidation_default(); - options->value.encoding = z_encoding_default(); - options->value.payload = _z_bytes_empty(); + options->encoding = z_encoding_default(); + z_bytes_null(options->payload); #if Z_FEATURE_ATTACHMENT == 1 options->attachment = z_attachment_null(); #endif @@ -808,7 +799,7 @@ void z_get_options_default(z_get_options_t *options) { } int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const char *parameters, - z_owned_closure_reply_t *callback, const z_get_options_t *options) { + z_owned_closure_reply_t *callback, z_get_options_t *options) { int8_t ret = _Z_RES_OK; void *ctx = callback->context; @@ -819,7 +810,8 @@ int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, co if (options != NULL) { opt.consolidation = options->consolidation; opt.target = options->target; - opt.value = options->value; + opt.encoding = options->encoding; + opt.payload = z_bytes_move(options->payload); #if Z_FEATURE_ATTACHMENT == 1 opt.attachment = options->attachment; #endif @@ -833,13 +825,16 @@ int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, co opt.consolidation.mode = Z_CONSOLIDATION_MODE_LATEST; } } - ret = _z_query(&_Z_RC_IN_VAL(zs), *keyexpr, parameters, opt.target, opt.consolidation.mode, opt.value, - callback->call, callback->drop, ctx, opt.timeout_ms + z_loaned_bytes_t *payload = z_bytes_loan_mut(opt.payload); + _z_value_t value = {.payload = _z_bytes_wrap(payload->start, payload->len), .encoding = opt.encoding}; + ret = _z_query(&_Z_RC_IN_VAL(zs), *keyexpr, parameters, opt.target, opt.consolidation.mode, value, callback->call, + callback->drop, ctx, opt.timeout_ms #if Z_FEATURE_ATTACHMENT == 1 , opt.attachment #endif ); + z_bytes_drop(opt.payload); return ret; } @@ -852,9 +847,9 @@ _Bool z_reply_is_ok(const z_loaned_reply_t *reply) { const z_loaned_sample_t *z_reply_ok(const z_loaned_reply_t *reply) { return &reply->in->val.data.sample; } -z_value_t z_reply_err(const z_loaned_reply_t *reply) { +const z_loaned_value_t *z_reply_err(const z_loaned_reply_t *reply) { _ZP_UNUSED(reply); - return (z_value_t){.payload = _z_bytes_empty(), .encoding = z_encoding_default()}; + return NULL; } #endif @@ -906,23 +901,21 @@ int8_t z_undeclare_queryable(z_owned_queryable_t *queryable) { return _z_queryab void z_query_reply_options_default(z_query_reply_options_t *options) { options->encoding = z_encoding_default(); } -int8_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, const uint8_t *payload, - size_t payload_len, const z_query_reply_options_t *options) { +// TODO(sashacmc): Why z_owned_bytes_t *payload but not z_view_bytes_t, do we really want clean it up after? +int8_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, z_owned_bytes_t *payload, + const z_query_reply_options_t *options) { z_query_reply_options_t opts; if (options == NULL) { z_query_reply_options_default(&opts); } else { opts = *options; } - _z_value_t value = {.payload = - { - .start = payload, - ._is_alloc = false, - .len = payload_len, - }, + z_loaned_bytes_t *loaned_payload = z_bytes_loan_mut(payload); + _z_value_t value = {.payload = _z_bytes_wrap(loaned_payload->start, loaned_payload->len), .encoding = {.id = opts.encoding.id, .schema = opts.encoding.schema}}; - return _z_send_reply(&query->in->val, *keyexpr, value, Z_SAMPLE_KIND_PUT, opts.attachment); - return _Z_ERR_GENERIC; + int8_t ret = _z_send_reply(&query->in->val, *keyexpr, value, Z_SAMPLE_KIND_PUT, opts.attachment); + z_bytes_drop(payload); + return ret; } #endif diff --git a/src/collections/string.c b/src/collections/string.c index cd55c8546..6985b6baf 100644 --- a/src/collections/string.c +++ b/src/collections/string.c @@ -25,6 +25,13 @@ _z_string_t _z_string_make(const char *value) { return s; } +_z_string_t *_z_string_make_as_ptr(const char *value) { + _z_string_t *s = (_z_string_t *)z_malloc(sizeof(_z_string_t)); + s->val = _z_str_clone(value); + s->len = strlen(value); + return s; +} + size_t _z_string_size(const _z_string_t *s) { return s->len; } void _z_string_copy(_z_string_t *dst, const _z_string_t *src) { @@ -127,59 +134,3 @@ char *_z_str_clone(const char *src) { } _Bool _z_str_eq(const char *left, const char *right) { return strcmp(left, right) == 0; } - -/*-------- str_array --------*/ -void _z_str_array_init(_z_str_array_t *sa, size_t len) { - char **val = (char **)&sa->val; - *val = (char *)z_malloc(len * sizeof(char *)); - if (*val != NULL) { - sa->len = len; - } -} - -_z_str_array_t _z_str_array_empty(void) { return (_z_str_array_t){.val = NULL, .len = 0}; } - -_z_str_array_t _z_str_array_make(size_t len) { - _z_str_array_t sa; - _z_str_array_init(&sa, len); - return sa; -} - -char **_z_str_array_get(const _z_str_array_t *sa, size_t pos) { return &sa->val[pos]; } - -size_t _z_str_array_len(const _z_str_array_t *sa) { return sa->len; } - -_Bool _z_str_array_is_empty(const _z_str_array_t *sa) { return sa->len == 0; } - -void _z_str_array_clear(_z_str_array_t *sa) { - for (size_t i = 0; i < sa->len; i++) { - z_free(sa->val[i]); - } - z_free(sa->val); -} - -void _z_str_array_free(_z_str_array_t **sa) { - _z_str_array_t *ptr = *sa; - if (ptr != NULL) { - _z_str_array_clear(ptr); - - z_free(ptr); - *sa = NULL; - } -} - -void _z_str_array_copy(_z_str_array_t *dst, const _z_str_array_t *src) { - _z_str_array_init(dst, src->len); - for (size_t i = 0; i < src->len; i++) { - dst->val[i] = _z_str_clone(src->val[i]); - } - dst->len = src->len; -} - -void _z_str_array_move(_z_str_array_t *dst, _z_str_array_t *src) { - dst->val = src->val; - dst->len = src->len; - - src->val = NULL; - src->len = 0; -} diff --git a/src/net/memory.c b/src/net/memory.c index dcf095b27..ad2201538 100644 --- a/src/net/memory.c +++ b/src/net/memory.c @@ -17,8 +17,8 @@ #include "zenoh-pico/protocol/core.h" void _z_hello_clear(_z_hello_t *hello) { - if (hello->locators.len > 0) { - _z_str_array_clear(&hello->locators); + if (!_z_string_vec_is_empty(&hello->locators)) { + _z_string_vec_clear(&hello->locators); } } diff --git a/src/net/session.c b/src/net/session.c index 6c708cd38..3419cabda 100644 --- a/src/net/session.c +++ b/src/net/session.c @@ -65,7 +65,7 @@ int8_t _z_open(_z_session_t *zn, _z_config_t *config) { } if (config != NULL) { - _z_str_array_t locators = _z_str_array_empty(); + _z_string_vec_t locators = _z_string_vec_make(0); char *connect = _z_config_get(config, Z_CONFIG_CONNECT_KEY); char *listen = _z_config_get(config, Z_CONFIG_LISTEN_KEY); if (connect == NULL && listen == NULL) { // Scout if peer is not configured @@ -91,7 +91,7 @@ int8_t _z_open(_z_session_t *zn, _z_config_t *config) { _z_hello_list_t *hellos = _z_scout_inner(what, zid, mcast_locator, timeout, true); if (hellos != NULL) { _z_hello_t *hello = _z_hello_list_head(hellos); - _z_str_array_copy(&locators, &hello->locators); + _z_string_vec_copy(&locators, &hello->locators); } _z_hello_list_free(&hellos); } else { @@ -104,15 +104,16 @@ int8_t _z_open(_z_session_t *zn, _z_config_t *config) { return _Z_ERR_GENERIC; } } - locators = _z_str_array_make(1); - locators.val[0] = _z_str_clone(_z_config_get(config, key)); + locators = _z_string_vec_make(1); + _z_string_vec_append(&locators, _z_string_make_as_ptr(_z_config_get(config, key))); } ret = _Z_ERR_SCOUT_NO_RESULTS; - for (size_t i = 0; i < locators.len; i++) { + size_t len = _z_string_vec_len(&locators); + for (size_t i = 0; i < len; i++) { ret = _Z_RES_OK; - char *locator = locators.val[i]; + _z_string_t *locator = _z_string_vec_get(&locators, i); // @TODO: check invalid configurations // For example, client mode in multicast links @@ -130,7 +131,7 @@ int8_t _z_open(_z_session_t *zn, _z_config_t *config) { } if (ret == _Z_RES_OK) { - ret = __z_open_inner(zn, locator, mode); + ret = __z_open_inner(zn, locator->val, mode); if (ret == _Z_RES_OK) { break; } @@ -138,7 +139,7 @@ int8_t _z_open(_z_session_t *zn, _z_config_t *config) { _Z_ERROR("Trying to configure an invalid mode."); } } - _z_str_array_clear(&locators); + _z_string_vec_clear(&locators); } else { _Z_ERROR("A valid config is missing."); ret = _Z_ERR_GENERIC; diff --git a/src/session/scout.c b/src/session/scout.c index b3a8dffb8..a0713d109 100644 --- a/src/session/scout.c +++ b/src/session/scout.c @@ -84,15 +84,15 @@ _z_hello_list_t *__z_scout_loop(const _z_wbuf_t *wbf, const char *locator, unsig size_t n_loc = _z_locator_array_len(&s_msg._body._hello._locators); if (n_loc > 0) { - hello->locators = _z_str_array_make(n_loc); + hello->locators = _z_string_vec_make(n_loc); for (size_t i = 0; i < n_loc; i++) { - hello->locators.val[i] = - _z_locator_to_str(&s_msg._body._hello._locators._val[i]); + _z_string_vec_append(&hello->locators, + _z_string_make_as_ptr(_z_locator_to_str( + &s_msg._body._hello._locators._val[i]))); } } else { // @TODO: construct the locator departing from the sock address - hello->locators.len = 0; - hello->locators.val = NULL; + _z_string_vec_clear(&hello->locators); } ret = _z_hello_list_push(ret, hello); diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index b95d1b8cc..9050138d4 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -67,7 +67,7 @@ void query_handler(const z_loaned_query_t *query, void *arg) { queries++; const z_loaned_keyexpr_t *query_ke = z_query_keyexpr(query); - z_owned_str_t k_str; + z_owned_string_t k_str; z_keyexpr_to_string(query_ke, &k_str); #ifdef ZENOH_PICO if (z_check(k_str) == false) { @@ -75,14 +75,16 @@ void query_handler(const z_loaned_query_t *query, void *arg) { } #endif - z_view_str_t pred; + z_view_string_t pred; z_query_parameters(query, &pred); (void)(pred); - z_value_t payload_value = z_query_value(query); + const z_loaned_value_t *payload_value = z_query_value(query); (void)(payload_value); z_query_reply_options_t _ret_qreply_opt; z_query_reply_options_default(&_ret_qreply_opt); - z_query_reply(query, query_ke, (const uint8_t *)value, strlen(value), &_ret_qreply_opt); + z_owned_bytes_t reply_payload; + // TODO(sashacmc): value encoding + z_query_reply(query, query_ke, z_move(reply_payload), &_ret_qreply_opt); z_drop(z_move(k_str)); } @@ -95,7 +97,7 @@ void reply_handler(const z_loaned_reply_t *reply, void *arg) { if (z_reply_is_ok(reply)) { const z_loaned_sample_t *sample = z_reply_ok(reply); - z_owned_str_t k_str; + z_owned_string_t k_str; z_keyexpr_to_string(z_sample_keyexpr(sample), &k_str); #ifdef ZENOH_PICO if (z_check(k_str) == false) { @@ -104,7 +106,7 @@ void reply_handler(const z_loaned_reply_t *reply, void *arg) { #endif z_drop(z_move(k_str)); } else { - z_value_t _ret_zvalue = z_reply_err(reply); + const z_loaned_value_t *_ret_zvalue = z_reply_err(reply); (void)(_ret_zvalue); } } @@ -114,7 +116,7 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) { printf("%s\n", __func__); datas++; - z_owned_str_t k_str; + z_owned_string_t k_str; z_keyexpr_to_string(z_sample_keyexpr(sample), &k_str); #ifdef ZENOH_PICO if (z_check(k_str) == false) { diff --git a/tests/z_api_null_drop_test.c b/tests/z_api_null_drop_test.c index c958deb4c..5494e283f 100644 --- a/tests/z_api_null_drop_test.c +++ b/tests/z_api_null_drop_test.c @@ -44,8 +44,8 @@ int main(void) { z_closure_hello_null(&closure_hello_null_1); z_owned_closure_zid_t closure_zid_null_1; z_closure_zid_null(&closure_zid_null_1); - z_owned_str_t str_null_1; - z_str_null(&str_null_1); + z_owned_string_t str_null_1; + z_string_null(&str_null_1); // // Test that they actually make invalid value (where applicable) @@ -70,7 +70,7 @@ int main(void) { z_owned_closure_reply_t closure_reply_null_2; z_owned_closure_hello_t closure_hello_null_2; z_owned_closure_zid_t closure_zid_null_2; - z_owned_str_t str_null_2; + z_owned_string_t str_null_2; z_null(&session_null_2); z_null(&keyexpr_null_2); diff --git a/tests/z_client_test.c b/tests/z_client_test.c index 4015f778a..ccc3432c9 100644 --- a/tests/z_client_test.c +++ b/tests/z_client_test.c @@ -52,16 +52,18 @@ void query_handler(const z_loaned_query_t *query, void *arg) { snprintf(res, 64, "%s%u", uri, *(unsigned int *)arg); printf(">> Received query: %s\t(%u/%u)\n", res, queries, total); - z_owned_str_t k_str; + z_owned_string_t k_str; z_keyexpr_to_string(z_query_keyexpr(query), &k_str); assert(_z_str_eq(z_loan(k_str)->val, res) == true); - z_view_str_t pred; + z_view_string_t pred; z_query_parameters(query, &pred); assert(z_loan(pred)->len == strlen("")); assert(strncmp((const char *)z_loan(pred)->val, "", strlen("")) == 0); - z_query_reply(query, z_query_keyexpr(query), (const uint8_t *)res, strlen(res), NULL); + z_owned_bytes_t reply_payload; + // TODO(sashacmc): res encoding + z_query_reply(query, z_query_keyexpr(query), z_move(reply_payload), NULL); queries++; z_drop(z_move(k_str)); @@ -76,7 +78,7 @@ void reply_handler(const z_loaned_reply_t *reply, void *arg) { const z_loaned_sample_t *sample = z_reply_ok(reply); printf(">> Received reply data: %s\t(%u/%u)\n", res, replies, total); - z_owned_str_t k_str; + z_owned_string_t k_str; z_keyexpr_to_string(z_sample_keyexpr(sample), &k_str); const z_loaned_bytes_t *payload = z_sample_payload(sample); assert(payload->len == strlen(res)); @@ -97,7 +99,7 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) { snprintf(res, 64, "%s%u", uri, *(unsigned int *)arg); printf(">> Received data: %s\t(%u/%u)\n", res, datas, total); - z_owned_str_t k_str; + z_owned_string_t k_str; z_keyexpr_to_string(z_sample_keyexpr(sample), &k_str); const z_loaned_bytes_t *payload = z_sample_payload(sample); assert((payload->len == MSG_LEN) || (payload->len == FRAGMENT_MSG_LEN)); diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index 463adc5e0..3ba31e71d 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -219,9 +219,11 @@ char *gen_str(size_t size) { return str; } -_z_str_array_t gen_str_array(size_t size) { - _z_str_array_t sa = _z_str_array_make(size); - for (size_t i = 0; i < size; i++) ((char **)sa.val)[i] = gen_str(16); +_z_string_vec_t gen_str_array(size_t size) { + _z_string_vec_t sa = _z_string_vec_make(size); + for (size_t i = 0; i < size; i++) { + _z_string_vec_append(&sa, _z_string_make_as_ptr(gen_str(16))); + } return sa; } @@ -301,18 +303,18 @@ void assert_eq_uint8_array(const _z_bytes_t *left, const _z_bytes_t *right) { printf(")"); } -void assert_eq_str_array(_z_str_array_t *left, _z_str_array_t *right) { +void assert_eq_str_array(_z_string_vec_t *left, _z_string_vec_t *right) { printf("Array -> "); - printf("Length (%zu:%zu), ", left->len, right->len); + printf("Length (%zu:%zu), ", left->_len, right->_len); - assert(left->len == right->len); + assert(left->_len == right->_len); printf("Content ("); - for (size_t i = 0; i < left->len; i++) { - const char *l = left->val[i]; - const char *r = right->val[i]; + for (size_t i = 0; i < left->_len; i++) { + const char *l = left->_val[i]; + const char *r = right->_val[i]; printf("%s:%s", l, r); - if (i < left->len - 1) printf(" "); + if (i < left->_len - 1) printf(" "); assert(_z_str_eq(l, r) == true); } diff --git a/tests/z_peer_multicast_test.c b/tests/z_peer_multicast_test.c index 01906c594..6808d8f23 100644 --- a/tests/z_peer_multicast_test.c +++ b/tests/z_peer_multicast_test.c @@ -46,7 +46,7 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) { snprintf(res, 64, "%s%u", uri, *(unsigned int *)arg); printf(">> Received data: %s\t(%u/%u)\n", res, datas, total); - z_owned_str_t k_str; + z_owned_string_t k_str; z_keyexpr_to_string(z_sample_keyexpr(sample), &k_str); const z_loaned_bytes_t *payload = z_sample_payload(sample); assert(payload->len == MSG_LEN); diff --git a/tests/z_test_fragment_rx.c b/tests/z_test_fragment_rx.c index 81d6b27c2..55bd8bce2 100644 --- a/tests/z_test_fragment_rx.c +++ b/tests/z_test_fragment_rx.c @@ -20,7 +20,7 @@ #if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_loaned_sample_t *sample, void *ctx) { (void)(ctx); - z_owned_str_t keystr; + z_owned_string_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); bool is_valid = true; const z_loaned_bytes_t *payload = z_sample_payload(sample); diff --git a/zenohpico.pc b/zenohpico.pc index 26ddb1280..642e15247 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -3,6 +3,6 @@ prefix=/usr/local Name: zenohpico Description: URL: -Version: 0.11.20240503dev +Version: 0.11.20240517dev Cflags: -I${prefix}/include Libs: -L${prefix}/lib -lzenohpico