diff --git a/examples/arduino/z_get.ino b/examples/arduino/z_get.ino index b0e78e654..5f86ee450 100644 --- a/examples/arduino/z_get.ino +++ b/examples/arduino/z_get.ino @@ -51,7 +51,7 @@ void reply_handler(z_owned_reply_t *oreply, void *ctx) { std::string val((const char *)z_sample_payload(sample)->start, z_sample_payload(sample)->len); Serial.print(" >> [Get listener] Received ("); - Serial.print(z_str_loan(&keystr)); + Serial.print(z_str_data(z_str_loan(&keystr))); Serial.print(", "); Serial.print(val.c_str()); Serial.println(")"); @@ -118,7 +118,9 @@ void loop() { } z_owned_closure_reply_t callback; z_closure_reply(&callback, reply_handler, reply_dropper, NULL); - if (z_get(z_session_loan(&s), z_keyexpr(KEYEXPR), "", z_closure_reply_move(&callback), &opts) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_get(z_session_loan(&s), z_view_keyexpr_loan(&ke), "", z_closure_reply_move(&callback), &opts) < 0) { Serial.println("Unable to send query."); } } diff --git a/examples/arduino/z_pub.ino b/examples/arduino/z_pub.ino index 6c06e9a8c..df03b0bcf 100644 --- a/examples/arduino/z_pub.ino +++ b/examples/arduino/z_pub.ino @@ -81,7 +81,9 @@ void setup() { Serial.print("Declaring publisher for "); Serial.print(KEYEXPR); Serial.println("..."); - if (z_declare_publisher(&pub, z_session_loan(&s), z_keyexpr(KEYEXPR), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_publisher(&pub, z_session_loan(&s), z_view_keyexpr_loan(&ke), NULL) < 0) { Serial.println("Unable to declare publisher for key expression!"); while (1) { ; diff --git a/examples/arduino/z_pull.ino b/examples/arduino/z_pull.ino index 867d84bdc..bf75d2412 100644 --- a/examples/arduino/z_pull.ino +++ b/examples/arduino/z_pull.ino @@ -44,7 +44,7 @@ // std::string val((const char *)sample->payload.start, sample->payload.len); // Serial.print(" >> [Subscription listener] Received ("); -// Serial.print(z_str_loan(&keystr)); +// Serial.print(z_str_data(z_str_loan(&keystr))); // Serial.print(", "); // Serial.print(val.c_str()); // Serial.println(")"); @@ -99,8 +99,10 @@ void setup() { // z_owned_closure_sample_t callback; // z_closure_sample(&callback, data_handler, NULL, NULL); // @TODO - // sub = z_declare_pull_subscriber(z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL); - // if (!z_pull_subscriber_check(&sub)) { + // z_view_keyexpr_t ke; + // z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + // sub = z_declare_pull_subscriber(z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&callback), + // NULL); if (!z_pull_subscriber_check(&sub)) { // Serial.println("Unable to declare subscriber."); // while (1) { // ; diff --git a/examples/arduino/z_queryable.ino b/examples/arduino/z_queryable.ino index b07ecc17b..1463e4af7 100644 --- a/examples/arduino/z_queryable.ino +++ b/examples/arduino/z_queryable.ino @@ -40,12 +40,14 @@ void query_handler(const z_loaned_query_t *query, void *arg) { z_keyexpr_to_string(z_query_keyexpr(query), &keystr); Serial.print(" >> [Queryable handler] Replying Data ('"); - Serial.print(z_str_loan(&keystr)); + Serial.print(z_str_data(z_str_loan(&keystr))); Serial.print("': '"); Serial.print(VALUE); Serial.println("')"); - z_query_reply(query, z_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), NULL); + 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_str_drop(z_str_move(&keystr)); } @@ -96,8 +98,10 @@ void setup() { z_owned_closure_query_t callback; z_closure_query(&callback, query_handler, NULL, NULL); z_owned_queryable_t qable; - if (z_declare_queryable(&qable, z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_query_move(&callback), NULL) < - 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_queryable(&qable, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_query_move(&callback), + NULL) < 0) { Serial.println("Unable to declare queryable."); while (1) { ; diff --git a/examples/arduino/z_scout.ino b/examples/arduino/z_scout.ino index 05b1770a1..a3b78bb46 100644 --- a/examples/arduino/z_scout.ino +++ b/examples/arduino/z_scout.ino @@ -56,25 +56,27 @@ void fprintwhatami(unsigned int whatami) { void fprintlocators(const z_str_array_t *locs) { Serial.print("["); - 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(", "); - } - } + (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(", "); + // } + //} Serial.print("]"); } -void fprinthello(const z_hello_t hello) { +void fprinthello(const z_loaned_hello_t *hello) { Serial.print(" >> Hello { zid: "); - fprintzid(hello.zid); + fprintzid(hello->zid); Serial.print(", whatami: "); - fprintwhatami(hello.whatami); + fprintwhatami(hello->whatami); Serial.print(", locators: "); - fprintlocators(&hello.locators); + fprintlocators(&hello->locators); Serial.println(" }"); } diff --git a/examples/arduino/z_sub.ino b/examples/arduino/z_sub.ino index c5a79299e..683e6acf5 100644 --- a/examples/arduino/z_sub.ino +++ b/examples/arduino/z_sub.ino @@ -40,7 +40,7 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) { std::string val((const char *)z_sample_payload(sample)->start, z_sample_payload(sample)->len); Serial.print(" >> [Subscription listener] Received ("); - Serial.print(z_str_loan(&keystr)); + Serial.print(z_str_data(z_str_loan(&keystr))); Serial.print(", "); Serial.print(val.c_str()); Serial.println(")"); @@ -94,8 +94,10 @@ void setup() { z_owned_closure_sample_t callback; z_closure_sample(&callback, data_handler, NULL, NULL); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL) < - 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_subscriber(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&callback), + NULL) < 0) { Serial.println("Unable to declare subscriber."); while (1) { ; diff --git a/examples/espidf/z_get.c b/examples/espidf/z_get.c index f2db48257..d45afa073 100644 --- a/examples/espidf/z_get.c +++ b/examples/espidf/z_get.c @@ -165,7 +165,9 @@ void app_main() { } z_owned_closure_reply_t callback; z_closure(&callback, reply_handler, reply_dropper); - if (z_get(z_loan(s), z_keyexpr(KEYEXPR), "", z_move(callback), &opts) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_get(z_loan(s), z_loan(ke), "", z_move(callback), &opts) < 0) { printf("Unable to send query.\n"); exit(-1); } diff --git a/examples/espidf/z_pub.c b/examples/espidf/z_pub.c index 6aad2f139..53cb2be99 100644 --- a/examples/espidf/z_pub.c +++ b/examples/espidf/z_pub.c @@ -141,7 +141,9 @@ void app_main() { printf("Declaring publisher for '%s'...", KEYEXPR); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(KEYEXPR), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); exit(-1); } diff --git a/examples/espidf/z_pull.c b/examples/espidf/z_pull.c index aef49a4b7..9f6a2d11f 100644 --- a/examples/espidf/z_pull.c +++ b/examples/espidf/z_pull.c @@ -153,7 +153,9 @@ void app_main() { // z_closure(&callback, data_handler); printf("Declaring Subscriber on '%s'...", KEYEXPR); // @TODO - // z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL); + // z_view_keyexpr_t ke; + // z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + // z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_loan(ke), z_move(callback), NULL); // if (!z_check(sub)) { // printf("Unable to declare subscriber.\n"); // exit(-1); diff --git a/examples/espidf/z_queryable.c b/examples/espidf/z_queryable.c index dd642a62a..6bd3d88b7 100644 --- a/examples/espidf/z_queryable.c +++ b/examples/espidf/z_queryable.c @@ -101,13 +101,17 @@ void wifi_init_sta(void) { vEventGroupDelete(s_event_group_handler); } -void query_handler(z_query_t *query, void *ctx) { +void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); z_owned_str_t keystr; - 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_query_reply(query, z_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), NULL); + // 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_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_drop(z_move(keystr)); } @@ -154,7 +158,9 @@ void app_main() { z_owned_closure_query_t callback; z_closure(&callback, query_handler); z_owned_queryable_t qable; - if (z_declare_queryable(&qable, z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_queryable(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to declare queryable.\n"); exit(-1); } diff --git a/examples/espidf/z_scout.c b/examples/espidf/z_scout.c index ed2eb44f7..99ca0b026 100644 --- a/examples/espidf/z_scout.c +++ b/examples/espidf/z_scout.c @@ -111,24 +111,26 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { void fprintlocators(FILE *stream, const z_str_array_t *locs) { fprintf(stream, "["); - 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, ", "); - } - } + (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, ", "); + // } + //} fprintf(stream, "]"); } -void fprinthello(FILE *stream, const z_hello_t hello) { +void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, "Hello { zid: "); - fprintzid(stream, hello.zid); + fprintzid(stream, hello->zid); fprintf(stream, ", whatami: "); - fprintwhatami(stream, hello.whatami); + fprintwhatami(stream, hello->whatami); fprintf(stream, ", locators: "); - fprintlocators(stream, &hello.locators); + fprintlocators(stream, &hello->locators); fprintf(stream, " }"); } diff --git a/examples/espidf/z_sub.c b/examples/espidf/z_sub.c index 000bf238e..76e93927f 100644 --- a/examples/espidf/z_sub.c +++ b/examples/espidf/z_sub.c @@ -103,7 +103,7 @@ void wifi_init_sta(void) { void data_handler(const z_loaned_sample_t* sample, void* arg) { z_owned_str_t keystr; z_keyexpr_to_string(z_sample_keyexpr(sample), &keystr); - const z_loaned_payload_t* payload = z_sample_payload(sample); + 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, payload->start); z_str_drop(z_str_move(&keystr)); @@ -151,7 +151,9 @@ void app_main() { z_owned_closure_sample_t callback; z_closure(&callback, data_handler); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to declare subscriber.\n"); exit(-1); } diff --git a/examples/freertos_plus_tcp/z_get.c b/examples/freertos_plus_tcp/z_get.c index bc27664cd..c4177132b 100644 --- a/examples/freertos_plus_tcp/z_get.c +++ b/examples/freertos_plus_tcp/z_get.c @@ -72,10 +72,10 @@ void app_main(void) { return; } - z_keyexpr_t ke = z_keyexpr(KEYEXPR); - if (!z_check(ke)) { - printf("%s is not a valid key expression\n", KEYEXPR); - return; + z_view_keyexpr_t ke; + if (z_view_keyexpr_from_string(&ke, KEYEXPR) < 0) { + printf("%s is not a valid key expression", KEYEXPR); + return -1; } while (1) { @@ -88,7 +88,7 @@ void app_main(void) { } z_owned_closure_reply_t callback; z_closure(&callback, reply_handler, reply_dropper); - if (z_get(z_loan(s), ke, "", z_move(callback), &opts) < 0) { + if (z_get(z_loan(s), z_loan(ke), "", z_move(callback), &opts) < 0) { printf("Unable to send query.\n"); return; } diff --git a/examples/freertos_plus_tcp/z_pub.c b/examples/freertos_plus_tcp/z_pub.c index 73a675427..ab13b8796 100644 --- a/examples/freertos_plus_tcp/z_pub.c +++ b/examples/freertos_plus_tcp/z_pub.c @@ -84,7 +84,9 @@ void app_main(void) { printf("Declaring publisher for '%s'...\n", KEYEXPR); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(KEYEXPR), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return; } diff --git a/examples/freertos_plus_tcp/z_pub_st.c b/examples/freertos_plus_tcp/z_pub_st.c index 0686bf584..bfdd22692 100644 --- a/examples/freertos_plus_tcp/z_pub_st.c +++ b/examples/freertos_plus_tcp/z_pub_st.c @@ -49,7 +49,9 @@ void app_main(void) { printf("Declaring publisher for '%s'...\n", KEYEXPR); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(KEYEXPR), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return; } diff --git a/examples/freertos_plus_tcp/z_pull.c b/examples/freertos_plus_tcp/z_pull.c index 1f2797a31..2c6ed1014 100644 --- a/examples/freertos_plus_tcp/z_pull.c +++ b/examples/freertos_plus_tcp/z_pull.c @@ -65,7 +65,9 @@ void app_main(void) { // z_closure(&callback, data_handler); printf("Declaring Subscriber on '%s'...\n", KEYEXPR); // @TODO - // z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL); + // z_view_keyexpr_t ke; + // z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + // z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_loan(ke), z_move(callback), NULL); // if (!z_check(sub)) { // printf("Unable to declare subscriber.\n"); // return; diff --git a/examples/freertos_plus_tcp/z_put.c b/examples/freertos_plus_tcp/z_put.c index 4459d04a0..b057bb88f 100644 --- a/examples/freertos_plus_tcp/z_put.c +++ b/examples/freertos_plus_tcp/z_put.c @@ -53,7 +53,9 @@ void app_main(void) { printf("Declaring key expression '%s'...\n", KEYEXPR); z_owned_keyexpr_t ke; - if (z_declare_keyexpr(&ke, z_loan(s), z_keyexpr(KEYEXPR)) < 0) { + z_view_keyexpr_t vke; + z_view_keyexpr_from_string_unchecked(&vke, KEYEXPR); + if (z_declare_keyexpr(&ke, z_loan(s), z_loan(vke)) < 0) { printf("Unable to declare key expression!\n"); zp_stop_read_task(z_loan_mut(s)); zp_stop_lease_task(z_loan_mut(s)); diff --git a/examples/freertos_plus_tcp/z_queryable.c b/examples/freertos_plus_tcp/z_queryable.c index 40a730aff..02251adc3 100644 --- a/examples/freertos_plus_tcp/z_queryable.c +++ b/examples/freertos_plus_tcp/z_queryable.c @@ -33,16 +33,17 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); z_owned_str_t keystr; z_keyexpr_to_string(z_query_keyexpr(query), &keystr); - 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); - } + // 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_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_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), &options); + z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)VALUE, strlen(VALUE), &options); z_drop(z_move(keystr)); } @@ -68,17 +69,17 @@ void app_main(void) { return; } - z_keyexpr_t ke = z_keyexpr(KEYEXPR); - if (!z_check(ke)) { - printf("%s is not a valid key expression\n", KEYEXPR); - return; + z_view_keyexpr_t ke; + if (z_view_keyexpr_from_string(&ke, KEYEXPR) < 0) { + printf("%s is not a valid key expression", KEYEXPR); + return -1; } printf("Creating Queryable on '%s'...\n", KEYEXPR); z_owned_closure_query_t callback; z_closure(&callback, query_handler); z_owned_queryable_t qable; - if (z_declare_queryable(&qable, z_loan(s), ke, z_move(callback), NULL) < 0) { + if (z_declare_queryable(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to create queryable.\n"); return; } diff --git a/examples/freertos_plus_tcp/z_scout.c b/examples/freertos_plus_tcp/z_scout.c index 702021b99..777ef2b2c 100644 --- a/examples/freertos_plus_tcp/z_scout.c +++ b/examples/freertos_plus_tcp/z_scout.c @@ -45,24 +45,26 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { void fprintlocators(FILE *stream, const z_str_array_t *locs) { fprintf(stream, "["); - 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, ", "); - } - } + (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, ", "); + // } + //} fprintf(stream, "]"); } -void fprinthello(FILE *stream, const z_hello_t hello) { +void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, "Hello { zid: "); - fprintzid(stream, hello.zid); + fprintzid(stream, hello->zid); fprintf(stream, ", whatami: "); - fprintwhatami(stream, hello.whatami); + fprintwhatami(stream, hello->whatami); fprintf(stream, ", locators: "); - fprintlocators(stream, &hello.locators); + fprintlocators(stream, &hello->locators); fprintf(stream, " }"); } diff --git a/examples/freertos_plus_tcp/z_sub.c b/examples/freertos_plus_tcp/z_sub.c index fd674d66c..b59d85972 100644 --- a/examples/freertos_plus_tcp/z_sub.c +++ b/examples/freertos_plus_tcp/z_sub.c @@ -62,8 +62,10 @@ void app_main(void) { z_owned_closure_sample_t callback; z_closure(&callback, data_handler); printf("Declaring Subscriber on '%s'...\n", KEYEXPR); + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL) < 0) { + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to declare subscriber.\n"); return; } diff --git a/examples/freertos_plus_tcp/z_sub_st.c b/examples/freertos_plus_tcp/z_sub_st.c index 1f89f1518..53f81f2a8 100644 --- a/examples/freertos_plus_tcp/z_sub_st.c +++ b/examples/freertos_plus_tcp/z_sub_st.c @@ -60,8 +60,10 @@ void app_main(void) { z_owned_closure_sample_t callback; z_closure(&callback, data_handler); printf("Declaring Subscriber on '%s'...\n", KEYEXPR); + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL) < 0) { + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to declare subscriber.\n"); return; } diff --git a/examples/mbed/z_get.cpp b/examples/mbed/z_get.cpp index 36052b73c..4c0f47c23 100644 --- a/examples/mbed/z_get.cpp +++ b/examples/mbed/z_get.cpp @@ -84,7 +84,9 @@ int main(int argc, char **argv) { } z_owned_closure_reply_t callback; z_closure_reply(&callback, reply_handler, reply_dropper, NULL); - if (z_get(z_session_loan(&s), z_keyexpr(KEYEXPR), "", z_closure_reply_move(&callback), &opts) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_get(z_session_loan(&s), z_view_keyexpr_loan(&ke), "", z_closure_reply_move(&callback), &opts) < 0) { printf("Unable to send query.\n"); exit(-1); } diff --git a/examples/mbed/z_pub.cpp b/examples/mbed/z_pub.cpp index 4395edcdb..08bfd624b 100644 --- a/examples/mbed/z_pub.cpp +++ b/examples/mbed/z_pub.cpp @@ -61,7 +61,9 @@ int main(int argc, char **argv) { printf("Declaring publisher for '%s'...", KEYEXPR); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_session_loan(&s), z_keyexpr(KEYEXPR), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_publisher(&pub, z_session_loan(&s), z_view_keyexpr_loan(&ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); exit(-1); } diff --git a/examples/mbed/z_pull.cpp b/examples/mbed/z_pull.cpp index 8beda1521..f011a4643 100644 --- a/examples/mbed/z_pull.cpp +++ b/examples/mbed/z_pull.cpp @@ -74,7 +74,7 @@ int main(int argc, char **argv) { printf("Declaring Subscriber on '%s'...", KEYEXPR); // @TODO // z_owned_pull_subscriber_t sub = - // z_declare_pull_subscriber(z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL); + // z_declare_pull_subscriber(z_session_loan(&s), z_loan(ke), z_closure_sample_move(&callback), NULL); // if (!z_pull_subscriber_check(&sub)) { // printf("Unable to declare subscriber.\n"); // exit(-1); diff --git a/examples/mbed/z_queryable.cpp b/examples/mbed/z_queryable.cpp index dd9be6976..1388a3de5 100644 --- a/examples/mbed/z_queryable.cpp +++ b/examples/mbed/z_queryable.cpp @@ -39,7 +39,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { 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_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), NULL); + z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)VALUE, strlen(VALUE), NULL); z_str_drop(z_str_move(&keystr)); } @@ -76,8 +76,10 @@ int main(int argc, char **argv) { z_owned_closure_query_t callback; z_closure_query(&callback, query_handler, NULL, NULL); z_owned_queryable_t qable; - if (z_declare_queryable(&qable, z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_query_move(&callback), NULL) < - 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_queryable(&qable, z_session_loan(&s), z_view_keyepr_loan(&ke), z_closure_query_move(&callback), + NULL) < 0) { printf("Unable to declare queryable.\n"); exit(-1); } diff --git a/examples/mbed/z_scout.cpp b/examples/mbed/z_scout.cpp index 0eeb27084..6940f284b 100644 --- a/examples/mbed/z_scout.cpp +++ b/examples/mbed/z_scout.cpp @@ -53,24 +53,26 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { void fprintlocators(FILE *stream, const z_str_array_t *locs) { fprintf(stream, "["); - 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, ", "); - } - } + (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, ", "); + // } + //} fprintf(stream, "]"); } -void fprinthello(FILE *stream, const z_hello_t hello) { +void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, "Hello { zid: "); - fprintzid(stream, hello.zid); + fprintzid(stream, hello->zid); fprintf(stream, ", whatami: "); - fprintwhatami(stream, hello.whatami); + fprintwhatami(stream, hello->whatami); fprintf(stream, ", locators: "); - fprintlocators(stream, &hello.locators); + fprintlocators(stream, &hello->locators); fprintf(stream, " }"); } diff --git a/examples/mbed/z_sub.cpp b/examples/mbed/z_sub.cpp index 3c750f1c3..5b8a56716 100644 --- a/examples/mbed/z_sub.cpp +++ b/examples/mbed/z_sub.cpp @@ -71,8 +71,10 @@ int main(int argc, char **argv) { z_owned_closure_sample_t callback; z_closure_sample(&callback, data_handler, NULL, NULL); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL) < - 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_subscriber(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&callback), + NULL) < 0) { printf("Unable to declare subscriber.\n"); exit(-1); } diff --git a/examples/unix/c11/z_get.c b/examples/unix/c11/z_get.c index c93a8fb66..16e7a8a2d 100644 --- a/examples/unix/c11/z_get.c +++ b/examples/unix/c11/z_get.c @@ -121,12 +121,11 @@ int main(int argc, char **argv) { return -1; } - // TODO(sashacmc): - // z_keyexpr_t ke = z_keyexpr(keyexpr); - // if (!z_check(ke)) { - // printf("%s is not a valid key expression", keyexpr); - // return -1; - // } + z_view_keyexpr_t ke; + if (z_view_keyexpr_from_string(&ke, keyexpr) < 0) { + printf("%s is not a valid key expression", keyexpr); + return -1; + } z_mutex_lock(&mutex); printf("Sending Query '%s'...\n", keyexpr); @@ -143,7 +142,7 @@ int main(int argc, char **argv) { z_owned_closure_reply_t callback; z_closure(&callback, reply_handler, reply_dropper); - if (z_get(z_loan(s), z_keyexpr(keyexpr), "", z_move(callback), &opts) < 0) { + if (z_get(z_loan(s), z_loan(ke), "", z_move(callback), &opts) < 0) { printf("Unable to send query.\n"); return -1; } diff --git a/examples/unix/c11/z_get_channel.c b/examples/unix/c11/z_get_channel.c index 92a029574..4b85fb55d 100644 --- a/examples/unix/c11/z_get_channel.c +++ b/examples/unix/c11/z_get_channel.c @@ -81,12 +81,11 @@ int main(int argc, char **argv) { return -1; } - // TODO(sashacmc): - // z_keyexpr_t ke = z_keyexpr(keyexpr); - // if (!z_check(ke)) { - // printf("%s is not a valid key expression", keyexpr); - // return -1; - // } + z_view_keyexpr_t ke; + if (z_view_keyexpr_from_string(&ke, keyexpr) < 0) { + printf("%s is not a valid key expression", keyexpr); + return -1; + } printf("Sending Query '%s'...\n", keyexpr); z_get_options_t opts; @@ -96,7 +95,7 @@ int main(int argc, char **argv) { } z_owned_reply_ring_channel_t channel; z_reply_ring_channel_new(&channel, 1); - if (z_get(z_loan(s), z_keyexpr(keyexpr), "", z_move(channel.send), &opts) < 0) { + if (z_get(z_loan(s), z_loan(ke), "", z_move(channel.send), &opts) < 0) { printf("Unable to send query.\n"); return -1; } diff --git a/examples/unix/c11/z_ping.c b/examples/unix/c11/z_ping.c index 8bb0078d6..fa7744d64 100644 --- a/examples/unix/c11/z_ping.c +++ b/examples/unix/c11/z_ping.c @@ -77,12 +77,13 @@ int main(int argc, char** argv) { return -1; } - // TODO(sashacmc): - // z_keyexpr_t ping = z_keyexpr_unchecked("test/ping"); - // z_keyexpr_t pong = z_keyexpr_unchecked("test/pong"); + z_view_keyexpr_t ping; + z_view_keyexpr_from_string_unchecked(&ping, "test/ping"); + z_view_keyexpr_t pong; + z_view_keyexpr_from_string_unchecked(&pong, "test/pong"); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(session), z_keyexpr("test/ping"), NULL) < 0) { + if (z_declare_publisher(&pub, z_loan(session), z_loan(ping), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } @@ -90,7 +91,7 @@ int main(int argc, char** argv) { z_owned_closure_sample_t respond; z_closure(&respond, callback, drop, NULL); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(session), z_keyexpr("test/pong"), z_move(respond), NULL) < 0) { + if (z_declare_subscriber(&sub, z_loan(session), z_loan(pong), z_move(respond), NULL) < 0) { printf("Unable to declare subscriber for key expression.\n"); return -1; } diff --git a/examples/unix/c11/z_pong.c b/examples/unix/c11/z_pong.c index 0cc873643..8be8fb256 100644 --- a/examples/unix/c11/z_pong.c +++ b/examples/unix/c11/z_pong.c @@ -47,20 +47,20 @@ int main(int argc, char** argv) { return -1; } - // TODO(sashacmc): - // z_keyexpr_t pong = z_keyexpr_unchecked("test/pong"); + z_view_keyexpr_t pong; + z_view_keyexpr_from_string_unchecked(&pong, "test/pong"); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(session), z_keyexpr("test/pong"), NULL) < 0) { + if (z_declare_publisher(&pub, z_loan(session), z_loan(pong), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } - // TODO(sashacmc): - // z_keyexpr_t ping = z_keyexpr_unchecked("test/ping"); + z_view_keyexpr_t ping; + z_view_keyexpr_from_string_unchecked(&ping, "test/ping"); z_owned_closure_sample_t respond; z_closure(&respond, callback, drop, (void*)z_move(pub)); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(session), z_keyexpr("test/ping"), z_move(respond), NULL) < 0) { + if (z_declare_subscriber(&sub, z_loan(session), z_loan(ping), z_move(respond), NULL) < 0) { printf("Unable to declare subscriber for key expression.\n"); return -1; } diff --git a/examples/unix/c11/z_pub.c b/examples/unix/c11/z_pub.c index 98d63fad6..8c78dc328 100644 --- a/examples/unix/c11/z_pub.c +++ b/examples/unix/c11/z_pub.c @@ -96,7 +96,9 @@ int main(int argc, char **argv) { } printf("Declaring publisher for '%s'...\n", keyexpr); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(keyexpr), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } diff --git a/examples/unix/c11/z_pub_st.c b/examples/unix/c11/z_pub_st.c index aeebe6c95..51037f4a4 100644 --- a/examples/unix/c11/z_pub_st.c +++ b/examples/unix/c11/z_pub_st.c @@ -82,7 +82,9 @@ int main(int argc, char **argv) { printf("Declaring publisher for '%s'...\n", keyexpr); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(keyexpr), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } diff --git a/examples/unix/c11/z_pub_thr.c b/examples/unix/c11/z_pub_thr.c index ed25fe188..228e70f01 100644 --- a/examples/unix/c11/z_pub_thr.c +++ b/examples/unix/c11/z_pub_thr.c @@ -52,7 +52,9 @@ int main(int argc, char **argv) { } // Declare publisher z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(keyexpr), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); exit(-1); } diff --git a/examples/unix/c11/z_pull.c b/examples/unix/c11/z_pull.c index 79d85ac6f..61a0f283a 100644 --- a/examples/unix/c11/z_pull.c +++ b/examples/unix/c11/z_pull.c @@ -76,7 +76,9 @@ int main(int argc, char **argv) { z_owned_sample_ring_channel_t channel; z_sample_ring_channel_new(&channel, size); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(keyexpr), z_move(channel.send), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(channel.send), NULL) < 0) { printf("Unable to declare subscriber.\n"); return -1; } diff --git a/examples/unix/c11/z_put.c b/examples/unix/c11/z_put.c index fe5dc6023..2f13733b3 100644 --- a/examples/unix/c11/z_put.c +++ b/examples/unix/c11/z_put.c @@ -86,8 +86,10 @@ int main(int argc, char **argv) { } printf("Declaring key expression '%s'...\n", keyexpr); + z_view_keyexpr_t vke; + z_view_keyexpr_from_string(&vke, keyexpr); z_owned_keyexpr_t ke; - if (z_declare_keyexpr(&ke, z_loan(s), z_keyexpr(keyexpr)) < 0) { + if (z_declare_keyexpr(&ke, z_loan(s), z_loan(vke)) < 0) { printf("Unable to declare key expression!\n"); zp_stop_read_task(z_loan_mut(s)); zp_stop_lease_task(z_loan_mut(s)); @@ -104,7 +106,7 @@ int main(int argc, char **argv) { z_bytes_map_insert_by_alias(&map, z_bytes_from_str("hi"), z_bytes_from_str("there")); options.attachment = z_bytes_map_as_attachment(&map); #endif - if (z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)value, strlen(value), &options) < 0) { + if (z_put(z_loan(s), z_loan(ke), (const uint8_t *)value, strlen(value), &options) < 0) { printf("Oh no! Put has failed...\n"); } diff --git a/examples/unix/c11/z_queryable.c b/examples/unix/c11/z_queryable.c index 6fff4a6f5..27d1c69d4 100644 --- a/examples/unix/c11/z_queryable.c +++ b/examples/unix/c11/z_queryable.c @@ -35,7 +35,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); z_owned_str_t keystr; z_keyexpr_to_string(z_query_keyexpr(query), &keystr); - // TODO(sashacmc): + // 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, @@ -61,7 +61,7 @@ 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_keyexpr(keyexpr), (const unsigned char *)value, strlen(value), &options); + z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)value, strlen(value), &options); z_drop(z_move(keystr)); msg_nb++; @@ -134,18 +134,17 @@ int main(int argc, char **argv) { return -1; } - // TODO(sashacmc): - // z_keyexpr_t ke = z_keyexpr(keyexpr); - // if (!z_check(ke)) { - // printf("%s is not a valid key expression", keyexpr); - // return -1; - // } + z_view_keyexpr_t ke; + if (z_view_keyexpr_from_string(&ke, keyexpr) < 0) { + printf("%s is not a valid key expression", keyexpr); + return -1; + } printf("Creating Queryable on '%s'...\n", keyexpr); z_owned_closure_query_t callback; z_closure(&callback, query_handler); z_owned_queryable_t qable; - if (z_declare_queryable(&qable, z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL) < 0) { + if (z_declare_queryable(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to create queryable.\n"); return -1; } diff --git a/examples/unix/c11/z_queryable_channel.c b/examples/unix/c11/z_queryable_channel.c index 8c0e220d6..8487afab6 100644 --- a/examples/unix/c11/z_queryable_channel.c +++ b/examples/unix/c11/z_queryable_channel.c @@ -81,18 +81,17 @@ int main(int argc, char **argv) { return -1; } - // TODO(sashacmc): - // z_keyexpr_t ke = z_keyexpr(keyexpr); - // if (!z_check(ke)) { - // printf("%s is not a valid key expression", keyexpr); - // return -1; - // } + z_view_keyexpr_t ke; + if (z_view_keyexpr_from_string(&ke, keyexpr) < 0) { + printf("%s is not a valid key expression", keyexpr); + return -1; + } printf("Creating Queryable on '%s'...\n", keyexpr); z_owned_query_ring_channel_t channel; z_query_ring_channel_new(&channel, 10); z_owned_queryable_t qable; - if (z_declare_queryable(&qable, z_loan(s), z_keyexpr(keyexpr), z_move(channel.send), NULL) < 0) { + if (z_declare_queryable(&qable, z_loan(s), z_loan(ke), z_move(channel.send), NULL) < 0) { printf("Unable to create queryable.\n"); return -1; } @@ -113,7 +112,7 @@ int main(int argc, char **argv) { 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_keyexpr(keyexpr), (const unsigned char *)value, strlen(value), &options); + z_query_reply(q, z_loan(ke), (const unsigned char *)value, strlen(value), &options); z_drop(z_move(keystr)); z_drop(z_move(query)); } diff --git a/examples/unix/c11/z_sub.c b/examples/unix/c11/z_sub.c index a79a05583..3b1e0865d 100644 --- a/examples/unix/c11/z_sub.c +++ b/examples/unix/c11/z_sub.c @@ -114,7 +114,9 @@ int main(int argc, char **argv) { z_closure(&callback, data_handler); printf("Declaring Subscriber on '%s'...\n", keyexpr); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to declare subscriber.\n"); return -1; } diff --git a/examples/unix/c11/z_sub_channel.c b/examples/unix/c11/z_sub_channel.c index 032598777..83985a7c6 100644 --- a/examples/unix/c11/z_sub_channel.c +++ b/examples/unix/c11/z_sub_channel.c @@ -68,7 +68,9 @@ int main(int argc, char **argv) { z_owned_sample_fifo_channel_t channel; z_sample_fifo_channel_new(&channel, 3); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(keyexpr), z_move(channel.send), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(channel.send), NULL) < 0) { printf("Unable to declare subscriber.\n"); return -1; } diff --git a/examples/unix/c11/z_sub_st.c b/examples/unix/c11/z_sub_st.c index 3a67c2805..0deee874f 100644 --- a/examples/unix/c11/z_sub_st.c +++ b/examples/unix/c11/z_sub_st.c @@ -91,7 +91,9 @@ int main(int argc, char **argv) { z_closure(&callback, data_handler); printf("Declaring Subscriber on '%s'...\n", keyexpr); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to declare subscriber.\n"); return -1; } diff --git a/examples/unix/c11/z_sub_thr.c b/examples/unix/c11/z_sub_thr.c index 5a1c8a685..0a7829489 100644 --- a/examples/unix/c11/z_sub_thr.c +++ b/examples/unix/c11/z_sub_thr.c @@ -96,7 +96,9 @@ int main(int argc, char **argv) { z_owned_closure_sample_t callback; z_closure(&callback, on_sample, drop_stats, (void *)context); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to create subscriber.\n"); exit(-1); } diff --git a/examples/unix/c99/z_get.c b/examples/unix/c99/z_get.c index 2d0d307ce..dff38043f 100644 --- a/examples/unix/c99/z_get.c +++ b/examples/unix/c99/z_get.c @@ -107,8 +107,8 @@ int main(int argc, char **argv) { return -1; } - const z_loaned_keyexpr_t *ke = z_keyexpr(keyexpr); - if (!z_keyexpr_is_initialized(ke)) { + z_view_keyexpr_t ke; + if (z_view_keyexpr_from_string(&ke, keyexpr) < 0) { printf("%s is not a valid key expression", keyexpr); return -1; } @@ -122,7 +122,7 @@ int main(int argc, char **argv) { } z_owned_closure_reply_t callback; z_closure_reply(&callback, reply_handler, reply_dropper, NULL); - if (z_get(z_session_loan(&s), ke, "", z_closure_reply_move(&callback), &opts) < 0) { + if (z_get(z_session_loan(&s), z_view_keyexpr_loan(&ke), "", z_closure_reply_move(&callback), &opts) < 0) { printf("Unable to send query.\n"); return -1; } diff --git a/examples/unix/c99/z_ping.c b/examples/unix/c99/z_ping.c index 52b966795..17fe7833c 100644 --- a/examples/unix/c99/z_ping.c +++ b/examples/unix/c99/z_ping.c @@ -80,21 +80,21 @@ int main(int argc, char** argv) { return -1; } - // TODO(sashacmc): - // z_keyexpr_t ping = z_keyexpr_unchecked("test/ping"); + z_view_keyexpr_t ping; + z_view_keyexpr_from_string_unchecked(&ping, "test/ping"); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_session_loan(&session), z_keyexpr("test/ping"), NULL) < 0) { + if (z_declare_publisher(&pub, z_session_loan(&session), z_view_keyexpr_loan(&ping), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } - // TODO(sashacmc): - // z_keyexpr_t pong = z_keyexpr_unchecked("test/pong"); + z_view_keyexpr_t pong; + z_view_keyexpr_from_string_unchecked(&pong, "test/pong"); z_owned_closure_sample_t respond; z_closure_sample(&respond, callback, drop, NULL); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_session_loan(&session), z_keyexpr("test/pong"), z_closure_sample_move(&respond), - NULL) < 0) { + if (z_declare_subscriber(&sub, z_session_loan(&session), z_view_keyexpr_loan(&pong), + z_closure_sample_move(&respond), NULL) < 0) { printf("Unable to declare subscriber for key expression.\n"); return -1; } diff --git a/examples/unix/c99/z_pong.c b/examples/unix/c99/z_pong.c index 97a86c3ed..533dc369a 100644 --- a/examples/unix/c99/z_pong.c +++ b/examples/unix/c99/z_pong.c @@ -50,19 +50,21 @@ int main(int argc, char** argv) { return -1; } - // TODO(sashacmc): z_keyexpr_t pong = z_keyexpr_unchecked("test/pong"); + z_view_keyexpr_t pong; + z_view_keyexpr_from_string_unchecked(&pong, "test/pong"); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_session_loan(&session), z_keyexpr("test/pong"), NULL) < 0) { + if (z_declare_publisher(&pub, z_session_loan(&session), z_view_keyexpr_loan(&pong), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } - // TODO(sashacmc): z_keyexpr_t ping = z_keyexpr_unchecked("test/ping"); + z_view_keyexpr_t ping; + z_view_keyexpr_from_string_unchecked(&ping, "test/ping"); z_owned_closure_sample_t respond; z_closure_sample(&respond, callback, drop, (void*)z_publisher_move(&pub)); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_session_loan(&session), z_keyexpr("test/ping"), z_closure_sample_move(&respond), - NULL) < 0) { + if (z_declare_subscriber(&sub, z_session_loan(&session), z_view_keyexpr_loan(&ping), + z_closure_sample_move(&respond), NULL) < 0) { printf("Unable to declare subscriber for key expression.\n"); return -1; } diff --git a/examples/unix/c99/z_pub.c b/examples/unix/c99/z_pub.c index 74376cd2f..6714a6e06 100644 --- a/examples/unix/c99/z_pub.c +++ b/examples/unix/c99/z_pub.c @@ -88,7 +88,9 @@ int main(int argc, char **argv) { printf("Declaring publisher for '%s'...\n", keyexpr); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_session_loan(&s), z_keyexpr(keyexpr), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_publisher(&pub, z_session_loan(&s), z_view_keyexpr_loan(&ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } diff --git a/examples/unix/c99/z_pub_st.c b/examples/unix/c99/z_pub_st.c index f576c8b07..d5d8220d8 100644 --- a/examples/unix/c99/z_pub_st.c +++ b/examples/unix/c99/z_pub_st.c @@ -81,7 +81,9 @@ int main(int argc, char **argv) { printf("Declaring publisher for '%s'...\n", keyexpr); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_session_loan(&s), z_keyexpr(keyexpr), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_publisher(&pub, z_session_loan(&s), z_view_keyexpr_loan(&ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } diff --git a/examples/unix/c99/z_pull.c b/examples/unix/c99/z_pull.c index 77301516a..e93bd9db6 100644 --- a/examples/unix/c99/z_pull.c +++ b/examples/unix/c99/z_pull.c @@ -80,7 +80,7 @@ int main(int argc, char **argv) { printf("Declaring Subscriber on '%s'...\n", keyexpr); // @TODO // z_owned_pull_subscriber_t sub = - // z_declare_pull_subscriber(z_session_loan(&s), z_keyexpr(keyexpr), z_closure_sample_move(&callback), NULL); + // z_declare_pull_subscriber(z_session_loan(&s), z_loan(ke), z_closure_sample_move(&callback), NULL); // if (!z_pull_subscriber_check(&sub)) { // printf("Unable to declare subscriber.\n"); // return -1; diff --git a/examples/unix/c99/z_put.c b/examples/unix/c99/z_put.c index 009803d8d..eb9e6ebf3 100644 --- a/examples/unix/c99/z_put.c +++ b/examples/unix/c99/z_put.c @@ -82,8 +82,10 @@ int main(int argc, char **argv) { } printf("Declaring key expression '%s'...\n", keyexpr); + z_view_keyexpr_t vke; + z_view_keyexpr_from_string(&vke, keyexpr); z_owned_keyexpr_t ke; - if (z_declare_keyexpr(&ke, z_session_loan(&s), z_keyexpr(keyexpr)) < 0) { + if (z_declare_keyexpr(&ke, z_session_loan(&s), z_view_keyexpr_loan(&vke)) < 0) { printf("Unable to declare key expression!\n"); zp_stop_read_task(z_session_loan_mut(&s)); zp_stop_lease_task(z_session_loan_mut(&s)); diff --git a/examples/unix/c99/z_queryable.c b/examples/unix/c99/z_queryable.c index ee38ab56a..7f2b4adc9 100644 --- a/examples/unix/c99/z_queryable.c +++ b/examples/unix/c99/z_queryable.c @@ -33,7 +33,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { 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_keyexpr(keyexpr), (const unsigned char *)value, strlen(value), &options); + z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)value, strlen(value), &options); z_str_drop(z_str_move(&keystr)); } @@ -96,8 +96,8 @@ int main(int argc, char **argv) { return -1; } - const z_loaned_keyexpr_t *ke = z_keyexpr(keyexpr); - if (!z_keyexpr_is_initialized(ke)) { + z_view_keyexpr_t ke; + if (z_view_keyexpr_from_string(&ke, keyexpr) < 0) { printf("%s is not a valid key expression", keyexpr); return -1; } @@ -107,7 +107,8 @@ int main(int argc, char **argv) { printf("Creating Queryable on '%s'...\n", keyexpr); z_owned_queryable_t qable; - if (z_declare_queryable(&qable, z_session_loan(&s), ke, z_closure_query_move(&callback), NULL) < 0) { + if (z_declare_queryable(&qable, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_query_move(&callback), + NULL) < 0) { printf("Unable to create queryable.\n"); return -1; } diff --git a/examples/unix/c99/z_scout.c b/examples/unix/c99/z_scout.c index 61206287f..cd07d9778 100644 --- a/examples/unix/c99/z_scout.c +++ b/examples/unix/c99/z_scout.c @@ -43,7 +43,7 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { void fprintlocators(FILE *stream, const z_str_array_t *locs) { fprintf(stream, "["); (void)locs; - // TODO(sashacmc): + // 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)); diff --git a/examples/unix/c99/z_sub.c b/examples/unix/c99/z_sub.c index 37b0699e0..4276819ea 100644 --- a/examples/unix/c99/z_sub.c +++ b/examples/unix/c99/z_sub.c @@ -92,8 +92,10 @@ int main(int argc, char **argv) { printf("Declaring Subscriber on '%s'...\n", keyexpr); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_session_loan(&s), z_keyexpr(keyexpr), z_closure_sample_move(&callback), NULL) < - 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_subscriber(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&callback), + NULL) < 0) { printf("Unable to declare subscriber.\n"); return -1; } diff --git a/examples/unix/c99/z_sub_st.c b/examples/unix/c99/z_sub_st.c index 03f1cbf35..5a3e83e02 100644 --- a/examples/unix/c99/z_sub_st.c +++ b/examples/unix/c99/z_sub_st.c @@ -93,8 +93,10 @@ int main(int argc, char **argv) { printf("Declaring Subscriber on '%s'...\n", keyexpr); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_session_loan(&s), z_keyexpr(keyexpr), z_closure_sample_move(&callback), NULL) < - 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_subscriber(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&callback), + NULL) < 0) { printf("Unable to declare subscriber.\n"); return -1; } diff --git a/examples/windows/z_get.c b/examples/windows/z_get.c index a20d4a4bd..042909497 100644 --- a/examples/windows/z_get.c +++ b/examples/windows/z_get.c @@ -33,7 +33,7 @@ void reply_handler(z_owned_reply_t *reply, void *ctx) { if (z_reply_is_ok(reply)) { const z_loaned_sample_t *sample = z_reply_ok(reply); z_owned_str_t keystr; - z_keyexpr_to_string(sample.keyexpr, &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); z_drop(z_move(keystr)); @@ -72,8 +72,8 @@ int main(int argc, char **argv) { return -1; } - z_keyexpr_t ke = z_keyexpr(keyexpr); - if (!z_check(ke)) { + z_view_keyexpr_t ke; + if (z_view_keyexpr_from_string(&ke, keyexpr) < 0) { printf("%s is not a valid key expression", keyexpr); return -1; } @@ -87,7 +87,7 @@ int main(int argc, char **argv) { } z_owned_closure_reply_t callback; z_closure(&callback, reply_handler, reply_dropper); - if (z_get(z_loan(s), ke, "", z_move(callback), &opts) < 0) { + if (z_get(z_loan(s), z_loan(ke), "", z_move(callback), &opts) < 0) { printf("Unable to send query.\n"); return -1; } diff --git a/examples/windows/z_ping.c b/examples/windows/z_ping.c index 850cea78a..8dfd075ca 100644 --- a/examples/windows/z_ping.c +++ b/examples/windows/z_ping.c @@ -30,7 +30,7 @@ static z_condvar_t cond; static z_mutex_t mutex; -void callback(const z_sample_t* sample, void* context) { +void callback(const z_loaned_sample_t* sample, void* context) { (void)sample; (void)context; z_condvar_signal(&cond); @@ -77,18 +77,20 @@ int main(int argc, char** argv) { return -1; } - z_keyexpr_t ping = z_keyexpr_unchecked("test/ping"); + z_view_keyexpr_t ping; + z_view_keyexpr_from_string_unchecked(&ping, "test/ping"); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(session), ping, NULL) < 0) { + if (z_declare_publisher(&pub, z_loan(session), z_loan(ping), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } - z_keyexpr_t pong = z_keyexpr_unchecked("test/pong"); + z_view_keyexpr_t pong; + z_view_keyexpr_from_string_unchecked(&pong, "test/pong"); z_owned_closure_sample_t respond; z_closure(&respond, callback, drop, NULL); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(session), pong, z_move(respond), NULL) < 0) { + if (z_declare_subscriber(&sub, z_loan(session), z_loan(pong), z_move(respond), NULL) < 0) { printf("Unable to declare subscriber for key expression.\n"); return -1; } diff --git a/examples/windows/z_pong.c b/examples/windows/z_pong.c index 240f03da6..8be8fb256 100644 --- a/examples/windows/z_pong.c +++ b/examples/windows/z_pong.c @@ -16,10 +16,10 @@ #include "zenoh-pico.h" #if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 -void callback(const z_sample_t* sample, void* context) { - z_publisher_t pub = z_loan(*(z_owned_publisher_t*)context); - z_bytes_t payload = z_sample_payload(sample); - z_publisher_put(pub, payload.start, payload.len, NULL); +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_bytes_t* payload = z_sample_payload(sample); + z_publisher_put(pub, payload->start, payload->len, NULL); } void drop(void* context) { z_owned_publisher_t* pub = (z_owned_publisher_t*)context; @@ -47,18 +47,20 @@ int main(int argc, char** argv) { return -1; } - z_keyexpr_t pong = z_keyexpr_unchecked("test/pong"); + z_view_keyexpr_t pong; + z_view_keyexpr_from_string_unchecked(&pong, "test/pong"); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(session), pong, NULL) < 0) { + if (z_declare_publisher(&pub, z_loan(session), z_loan(pong), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } - z_keyexpr_t ping = z_keyexpr_unchecked("test/ping"); + z_view_keyexpr_t ping; + z_view_keyexpr_from_string_unchecked(&ping, "test/ping"); z_owned_closure_sample_t respond; z_closure(&respond, callback, drop, (void*)z_move(pub)); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(session), ping, z_move(respond), NULL) < 0) { + if (z_declare_subscriber(&sub, z_loan(session), z_loan(ping), z_move(respond), NULL) < 0) { printf("Unable to declare subscriber for key expression.\n"); return -1; } diff --git a/examples/windows/z_pub.c b/examples/windows/z_pub.c index 29f32efad..5ef1da47a 100644 --- a/examples/windows/z_pub.c +++ b/examples/windows/z_pub.c @@ -50,7 +50,9 @@ int main(int argc, char **argv) { printf("Declaring publisher for '%s'...\n", keyexpr); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(keyexpr), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } diff --git a/examples/windows/z_pub_st.c b/examples/windows/z_pub_st.c index 2b7c2d76e..959fb2b6f 100644 --- a/examples/windows/z_pub_st.c +++ b/examples/windows/z_pub_st.c @@ -45,7 +45,9 @@ int main(int argc, char **argv) { printf("Declaring publisher for '%s'...\n", keyexpr); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(keyexpr), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); return -1; } diff --git a/examples/windows/z_pull.c b/examples/windows/z_pull.c index c8beb623a..5cc5be9ce 100644 --- a/examples/windows/z_pull.c +++ b/examples/windows/z_pull.c @@ -59,7 +59,7 @@ int main(int argc, char **argv) { // z_closure(&callback, data_handler); printf("Declaring Subscriber on '%s'...\n", keyexpr); // @TODO - // z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL); + // z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_loan(ke), z_move(callback), NULL); // if (!z_check(sub)) { // printf("Unable to declare subscriber.\n"); // return -1; diff --git a/examples/windows/z_put.c b/examples/windows/z_put.c index a9596286a..d009968a3 100644 --- a/examples/windows/z_put.c +++ b/examples/windows/z_put.c @@ -49,8 +49,10 @@ int main(int argc, char **argv) { } printf("Declaring key expression '%s'...\n", keyexpr); + z_view_keyexpr_t vke; + z_view_keyexpr_from_string(&vke, keyexpr); z_owned_keyexpr_t ke; - if (z_declare_keyexpr(&ke, z_loan(s), z_keyexpr(keyexpr)) < 0) { + if (z_declare_keyexpr(&ke, z_loan(s), z_loan(vke)) < 0) { printf("Unable to declare key expression!\n"); zp_stop_read_task(z_loan_mut(s)); zp_stop_lease_task(z_loan_mut(s)); diff --git a/examples/windows/z_queryable.c b/examples/windows/z_queryable.c index 1fde0df81..0c409b597 100644 --- a/examples/windows/z_queryable.c +++ b/examples/windows/z_queryable.c @@ -25,16 +25,18 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); z_owned_str_t keystr; z_keyexpr_to_string(z_query_keyexpr(query), &keystr); - 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); - } + // 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_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_keyexpr(keyexpr), (const unsigned char *)value, strlen(value), &options); + z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)value, strlen(value), &options); z_drop(z_move(keystr)); } @@ -63,8 +65,8 @@ int main(int argc, char **argv) { return -1; } - z_keyexpr_t ke = z_keyexpr(keyexpr); - if (!z_check(ke)) { + z_view_keyexpr_t ke; + if (z_view_keyexpr_from_string(&ke, keyexpr) < 0) { printf("%s is not a valid key expression", keyexpr); return -1; } @@ -73,7 +75,7 @@ int main(int argc, char **argv) { z_owned_closure_query_t callback; z_closure(&callback, query_handler); z_owned_queryable_t qable; - if (z_declare_queryable(&qable, z_loan(s), ke, z_move(callback), NULL) < 0) { + if (z_declare_queryable(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to create queryable.\n"); return -1; } diff --git a/examples/windows/z_scout.c b/examples/windows/z_scout.c index ea6a69130..a89ddd038 100644 --- a/examples/windows/z_scout.c +++ b/examples/windows/z_scout.c @@ -42,24 +42,26 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { void fprintlocators(FILE *stream, const z_str_array_t *locs) { fprintf(stream, "["); - 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, ", "); - } - } + (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, ", "); + // } + //} fprintf(stream, "]"); } -void fprinthello(FILE *stream, const z_hello_t hello) { +void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, "Hello { zid: "); - fprintzid(stream, hello.zid); + fprintzid(stream, hello->zid); fprintf(stream, ", whatami: "); - fprintwhatami(stream, hello.whatami); + fprintwhatami(stream, hello->whatami); fprintf(stream, ", locators: "); - fprintlocators(stream, &hello.locators); + fprintlocators(stream, &hello->locators); fprintf(stream, " }"); } diff --git a/examples/windows/z_sub.c b/examples/windows/z_sub.c index 4b1441228..298d54b4f 100644 --- a/examples/windows/z_sub.c +++ b/examples/windows/z_sub.c @@ -60,7 +60,9 @@ int main(int argc, char **argv) { z_closure(&callback, data_handler); printf("Declaring Subscriber on '%s'...\n", keyexpr); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to declare subscriber.\n"); return -1; } diff --git a/examples/windows/z_sub_st.c b/examples/windows/z_sub_st.c index 04ed79fe2..4276a4ecb 100644 --- a/examples/windows/z_sub_st.c +++ b/examples/windows/z_sub_st.c @@ -58,7 +58,9 @@ int main(int argc, char **argv) { z_closure(&callback, data_handler); printf("Declaring Subscriber on '%s'...\n", keyexpr); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to declare subscriber.\n"); return -1; } diff --git a/examples/zephyr/z_get.c b/examples/zephyr/z_get.c index 2dbe27234..658dfffa0 100644 --- a/examples/zephyr/z_get.c +++ b/examples/zephyr/z_get.c @@ -37,7 +37,7 @@ void reply_handler(z_owned_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_keyexpr_to_string(sample.keyexpr, &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); z_drop(z_move(keystr)); @@ -78,7 +78,9 @@ int main(int argc, char **argv) { opts.target = Z_QUERY_TARGET_ALL; z_owned_closure_reply_t callback; z_closure(&callback, reply_handler, reply_dropper); - if (z_get(z_loan(s), z_keyexpr(KEYEXPR), "", z_move(callback), &opts) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_get(z_loan(s), z_loan(ke), "", z_move(callback), &opts) < 0) { printf("Unable to send query.\n"); exit(-1); } diff --git a/examples/zephyr/z_pub.c b/examples/zephyr/z_pub.c index b96e7ba74..209f91dc5 100644 --- a/examples/zephyr/z_pub.c +++ b/examples/zephyr/z_pub.c @@ -57,8 +57,10 @@ int main(int argc, char **argv) { zp_start_lease_task(z_loan_mut(s), NULL); printf("Declaring publisher for '%s'...", KEYEXPR); + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(KEYEXPR), NULL) < 0) { + if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); exit(-1); } diff --git a/examples/zephyr/z_pull.c b/examples/zephyr/z_pull.c index f739edd26..cdab228bf 100644 --- a/examples/zephyr/z_pull.c +++ b/examples/zephyr/z_pull.c @@ -68,7 +68,7 @@ int main(int argc, char **argv) { // z_closure(&callback, data_handler); printf("Declaring Subscriber on '%s'...", KEYEXPR); // @TODO - // z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL); + // z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_loan(ke), z_move(callback), NULL); // if (!z_check(sub)) { // printf("Unable to declare subscriber.\n"); // exit(-1); diff --git a/examples/zephyr/z_queryable.c b/examples/zephyr/z_queryable.c index 5455aef8f..3950bc1b8 100644 --- a/examples/zephyr/z_queryable.c +++ b/examples/zephyr/z_queryable.c @@ -35,9 +35,11 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { (void)(ctx); z_owned_str_t keystr; 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_query_reply(query, z_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), NULL); + // 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_drop(z_move(keystr)); } @@ -70,7 +72,9 @@ int main(int argc, char **argv) { z_owned_closure_query_t callback; z_closure(&callback, query_handler); z_owned_queryable_t qable; - if (z_declare_queryable(&qable, z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); + if (z_declare_queryable(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to declare queryable.\n"); exit(-1); } diff --git a/examples/zephyr/z_scout.c b/examples/zephyr/z_scout.c index 718d6675a..3f1c9c93e 100644 --- a/examples/zephyr/z_scout.c +++ b/examples/zephyr/z_scout.c @@ -39,24 +39,26 @@ void fprintwhatami(FILE *stream, unsigned int whatami) { void fprintlocators(FILE *stream, const z_str_array_t *locs) { fprintf(stream, "["); - 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, ", "); - } - } + (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, ", "); + // } + //} fprintf(stream, "]"); } -void fprinthello(FILE *stream, const z_hello_t hello) { +void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, "Hello { zid: "); - fprintzid(stream, hello.zid); + fprintzid(stream, hello->zid); fprintf(stream, ", whatami: "); - fprintwhatami(stream, hello.whatami); + fprintwhatami(stream, hello->whatami); fprintf(stream, ", locators: "); - fprintlocators(stream, &hello.locators); + fprintlocators(stream, &hello->locators); fprintf(stream, " }"); } diff --git a/examples/zephyr/z_sub.c b/examples/zephyr/z_sub.c index eddd62b14..362b249a2 100644 --- a/examples/zephyr/z_sub.c +++ b/examples/zephyr/z_sub.c @@ -65,8 +65,10 @@ int main(int argc, char **argv) { printf("Declaring Subscriber on '%s'...", KEYEXPR); z_owned_closure_sample_t callback; z_closure(&callback, data_handler); + z_view_keyexpr_t ke; + z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL) < 0) { + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to declare subscriber.\n"); exit(-1); } diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index 35d13ed14..e58db7b68 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -35,6 +35,7 @@ #define z_loan(x) _Generic((x), \ z_owned_keyexpr_t : z_keyexpr_loan, \ + z_view_keyexpr_t : z_view_keyexpr_loan, \ z_owned_config_t : z_config_loan, \ z_owned_scouting_config_t : z_scouting_config_loan, \ z_owned_session_t : z_session_loan, \ diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 5cfb25aaf..f2d135868 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -58,7 +58,7 @@ int8_t z_view_str_wrap(z_view_str_t *str, const char *value); * Returns: * The :c:type:`z_keyexpr_t` corresponding to the given string. */ -int8_t z_view_keyexpr_new(z_view_keyexpr_t *keyexpr, const char *name); +int8_t z_view_keyexpr_from_string(z_view_keyexpr_t *keyexpr, const char *name); /** * Constructs a :c:type:`z_keyexpr_t` departing from a string. @@ -74,7 +74,7 @@ int8_t z_view_keyexpr_new(z_view_keyexpr_t *keyexpr, const char *name); // TODO(sashacmc): z_owned_keyexpr_t z_keyexpr_unchecked(const char *name); -int8_t z_view_keyexpr_unchecked(z_view_keyexpr_t *keyexpr, const char *name); +int8_t z_view_keyexpr_from_string_unchecked(z_view_keyexpr_t *keyexpr, const char *name); /** * Get null-terminated string departing from a :c:type:`z_keyexpr_t`. @@ -799,9 +799,6 @@ _VIEW_FUNCTIONS(z_loaned_str_t, z_view_str_t, str) // Gets internal value from refcountered owned type (e.g. z_owned_session_t, z_owned_query_t) #define _Z_OWNED_RC_IN_VAL(arg) ((arg)->_rc.in->val) -// TODO(sashacmc): remove this VERY BAD workaround (it is only to allow compilaton)!!! -z_loaned_keyexpr_t *z_keyexpr(const char *name); - // 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); @@ -1147,7 +1144,7 @@ void z_get_options_default(z_get_options_t *options); * Returns: * Returns ``0`` if the put operation is successful, or a ``negative value`` otherwise. */ -int8_t z_get(const z_loaned_session_t *zs, z_loaned_keyexpr_t *keyexpr, const char *parameters, +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); /** * Checks if the queryable answered with an OK, which allows this value to be treated as a sample. diff --git a/src/api/api.c b/src/api/api.c index a18bab192..cfbdf0d2b 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -41,13 +41,6 @@ #include "zenoh-pico/utils/result.h" #include "zenoh-pico/utils/uuid.h" -// TODO(sashacmc): remove this VERY BAD workaround (it is only to allow compilaton)!!! -z_loaned_keyexpr_t *z_keyexpr(const char *name) { - static z_view_keyexpr_t keyexpr; - z_view_keyexpr_new(&keyexpr, name); - return (z_loaned_keyexpr_t *)z_view_keyexpr_loan(&keyexpr); -} - /********* Data Types Handlers *********/ int8_t z_view_str_wrap(z_view_str_t *str, const char *value) { @@ -60,12 +53,12 @@ int8_t z_view_str_wrap(z_view_str_t *str, const char *value) { // 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); } -int8_t z_view_keyexpr_new(z_view_keyexpr_t *keyexpr, const char *name) { +int8_t z_view_keyexpr_from_string(z_view_keyexpr_t *keyexpr, const char *name) { keyexpr->_val = _z_rname(name); return _Z_RES_OK; } -int8_t z_view_keyexpr_unchecked(z_view_keyexpr_t *keyexpr, const char *name) { +int8_t z_view_keyexpr_from_string_unchecked(z_view_keyexpr_t *keyexpr, const char *name) { keyexpr->_val = _z_rname(name); return _Z_RES_OK; } @@ -818,7 +811,7 @@ void __z_reply_handler(_z_reply_t *reply, __z_reply_handler_wrapper_t *wrapped_c z_reply_drop(&oreply); // user_call is allowed to take ownership of the reply by setting oreply._val to NULL } -int8_t z_get(const z_loaned_session_t *zs, z_loaned_keyexpr_t *keyexpr, const char *parameters, +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) { int8_t ret = _Z_RES_OK; diff --git a/src/transport/raweth/tx.c b/src/transport/raweth/tx.c index a3cf15a8d..faeada46e 100644 --- a/src/transport/raweth/tx.c +++ b/src/transport/raweth/tx.c @@ -241,7 +241,7 @@ int8_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, _ZP_UNUSED(cong_ctrl); #endif // Z_FEATURE_MULTI_THREAD == 1 - const z_keyexpr_t *keyexpr = NULL; + const _z_keyexpr_t *keyexpr = NULL; switch (n_msg->_tag) { case _Z_N_PUSH: keyexpr = &n_msg->_body._push._key; diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 3f4a4fc14..6c8d46060 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -19,6 +19,7 @@ #undef NDEBUG #include +#define URI "demo/example/**/*" #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) #include #define sleep(x) Sleep(x * 1000) @@ -65,8 +66,9 @@ void query_handler(const z_loaned_query_t *query, void *arg) { printf("%s\n", __func__); queries++; + const z_loaned_keyexpr_t *query_ke = z_query_keyexpr(query); z_owned_str_t k_str; - z_keyexpr_to_string(z_query_keyexpr(query), &k_str); + z_keyexpr_to_string(query_ke, &k_str); #ifdef ZENOH_PICO if (z_check(k_str) == false) { zp_keyexpr_resolve(*(const z_loaned_session_t **)arg, z_query_keyexpr(query), &k_str); @@ -80,7 +82,7 @@ void query_handler(const z_loaned_query_t *query, void *arg) { (void)(payload_value); z_query_reply_options_t _ret_qreply_opt; z_query_reply_options_default(&_ret_qreply_opt); - z_query_reply(query, z_keyexpr(z_loan(k_str)->val), (const uint8_t *)value, strlen(value), &_ret_qreply_opt); + z_query_reply(query, query_ke, (const uint8_t *)value, strlen(value), &_ret_qreply_opt); z_drop(z_move(k_str)); } @@ -134,37 +136,37 @@ int main(int argc, char **argv) { zc_init_logger(); #endif - printf("Testing Keyexpr..."); - const z_loaned_keyexpr_t *key = z_keyexpr("demo/example"); - _Bool _ret_bool = z_keyexpr_is_initialized(key); - assert_eq(_ret_bool, true); + z_view_keyexpr_t key_demo_example, key_demo_example_a, key_demo_example_starstar; + z_view_keyexpr_from_string(&key_demo_example, "demo/example"); + z_view_keyexpr_from_string(&key_demo_example_a, "demo/example/a"); + z_view_keyexpr_from_string(&key_demo_example_starstar, "demo/example/**"); - int8_t _ret_int8 = z_keyexpr_includes(z_keyexpr("demo/example/**"), z_keyexpr("demo/example/a")); - assert_eq(_ret_int8, 0); + _Bool _ret_bool = z_keyexpr_includes(z_loan(key_demo_example_starstar), z_loan(key_demo_example_a)); + assert(_ret_bool); #ifdef ZENOH_PICO - _ret_int8 = zp_keyexpr_includes_null_terminated("demo/example/**", "demo/example/a"); - assert_eq(_ret_int8, 0); + _ret_bool = zp_keyexpr_includes_null_terminated("demo/example/**", "demo/example/a"); + assert(_ret_bool); #endif - _ret_int8 = z_keyexpr_intersects(z_keyexpr("demo/example/**"), z_keyexpr("demo/example/a")); - assert_eq(_ret_int8, 0); + _ret_bool = z_keyexpr_intersects(z_loan(key_demo_example_starstar), z_loan(key_demo_example_a)); + assert(_ret_bool); #ifdef ZENOH_PICO - _ret_int8 = zp_keyexpr_intersect_null_terminated("demo/example/**", "demo/example/a"); - assert_eq(_ret_int8, 0); + _ret_bool = zp_keyexpr_intersect_null_terminated("demo/example/**", "demo/example/a"); + assert(_ret_bool); #endif - _ret_int8 = z_keyexpr_equals(z_keyexpr("demo/example/**"), z_keyexpr("demo/example")); - assert_eq(_ret_int8, -1); + _ret_bool = z_keyexpr_equals(z_loan(key_demo_example_starstar), z_loan(key_demo_example)); + assert(!_ret_bool); #ifdef ZENOH_PICO - _ret_int8 = zp_keyexpr_equals_null_terminated("demo/example/**", "demo/example"); - assert_eq(_ret_int8, -1); + _ret_bool = zp_keyexpr_equals_null_terminated("demo/example/**", "demo/example"); + assert(!_ret_bool); #endif sleep(SLEEP); - size_t keyexpr_len = strlen("demo/example/**/*"); - char *keyexpr_str = (char *)malloc(keyexpr_len + 1); - memcpy(keyexpr_str, "demo/example/**/*", keyexpr_len); + size_t keyexpr_len = strlen(URI); + char *keyexpr_str = (char *)z_malloc(keyexpr_len + 1); + memcpy(keyexpr_str, URI, keyexpr_len); keyexpr_str[keyexpr_len] = '\0'; - _ret_int8 = z_keyexpr_is_canon(keyexpr_str, keyexpr_len); + int8_t _ret_int8 = z_keyexpr_is_canon(keyexpr_str, keyexpr_len); assert(_ret_int8 < 0); #ifdef ZENOH_PICO @@ -173,11 +175,11 @@ int main(int argc, char **argv) { #endif _ret_int8 = z_keyexpr_canonize(keyexpr_str, &keyexpr_len); assert_eq(_ret_int8, 0); - assert_eq(strlen("demo/example/**/*"), keyexpr_len); + assert_eq(strlen(URI), keyexpr_len); #ifdef ZENOH_PICO _ret_int8 = zp_keyexpr_canonize_null_terminated(keyexpr_str); assert_eq(_ret_int8, 0); - assert_eq(strlen("demo/example/**/*"), keyexpr_len); + assert_eq(strlen(URI), keyexpr_len); #endif printf("Ok\n"); @@ -292,19 +294,22 @@ int main(int argc, char **argv) { z_closure(&_ret_closure_sample, data_handler, NULL, &ls1); z_subscriber_options_t _ret_sub_opt; z_subscriber_options_default(&_ret_sub_opt); + + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr_str); z_owned_subscriber_t _ret_sub; - _ret_int8 = - z_declare_subscriber(&_ret_sub, z_loan(s2), z_keyexpr(keyexpr_str), z_move(_ret_closure_sample), &_ret_sub_opt); + _ret_int8 = z_declare_subscriber(&_ret_sub, z_loan(s2), z_loan(ke), z_move(_ret_closure_sample), &_ret_sub_opt); assert(_ret_int8 == _Z_RES_OK); printf("Ok\n"); sleep(SLEEP); - printf("Declaring Keyexpr..."); - char *s1_res = (char *)malloc(64); - snprintf(s1_res, 64, "%s/chunk/%d", keyexpr_str, 1); + char s1_res[64]; + sprintf(s1_res, "%s/chunk/%d", keyexpr_str, 1); + z_view_keyexpr_t s1_key; + z_view_keyexpr_from_string(&s1_key, s1_res); z_owned_keyexpr_t _ret_expr; - z_declare_keyexpr(&_ret_expr, z_loan(s1), z_keyexpr(s1_res)); + z_declare_keyexpr(&_ret_expr, z_loan(s1), z_loan(s1_key)); assert(z_check(_ret_expr)); printf("Ok\n"); @@ -346,7 +351,7 @@ int main(int argc, char **argv) { z_publisher_options_default(&_ret_pub_opt); _ret_pub_opt.congestion_control = Z_CONGESTION_CONTROL_BLOCK; z_owned_publisher_t _ret_pub; - _ret_int8 = z_declare_publisher(&_ret_pub, z_loan(s1), z_keyexpr(keyexpr_str), &_ret_pub_opt); + _ret_int8 = z_declare_publisher(&_ret_pub, z_loan(s1), z_loan(ke), &_ret_pub_opt); assert(_ret_int8 == _Z_RES_OK); printf("Ok\n"); @@ -394,7 +399,7 @@ int main(int argc, char **argv) { z_queryable_options_t _ret_qle_opt; z_queryable_options_default(&_ret_qle_opt); z_owned_queryable_t qle; - assert(z_declare_queryable(&qle, z_loan(s1), z_keyexpr(s1_res), z_move(_ret_closure_query), &_ret_qle_opt) == + assert(z_declare_queryable(&qle, z_loan(s1), z_loan(s1_key), z_move(_ret_closure_query), &_ret_qle_opt) == _Z_RES_OK); printf("Ok\n"); @@ -420,7 +425,7 @@ int main(int argc, char **argv) { printf("Ok\n"); printf("Testing Get..."); - _ret_int8 = z_get(z_loan(s2), z_keyexpr(s1_res), "", z_move(_ret_closure_reply), &_ret_get_opt); + _ret_int8 = z_get(z_loan(s2), z_loan(s1_key), "", z_move(_ret_closure_reply), &_ret_get_opt); assert_eq(_ret_int8, 0); printf("Ok\n"); @@ -452,7 +457,6 @@ int main(int argc, char **argv) { sleep(SLEEP * 5); - free(s1_res); free(keyexpr_str); return 0; diff --git a/tests/z_client_test.c b/tests/z_client_test.c index b4cbdd2a3..d1a60de03 100644 --- a/tests/z_client_test.c +++ b/tests/z_client_test.c @@ -61,7 +61,7 @@ void query_handler(const z_loaned_query_t *query, void *arg) { assert(z_loan(pred)->len == strlen("")); assert(strncmp((const char *)z_loan(pred)->val, "", strlen("")) == 0); - z_query_reply(query, z_keyexpr(res), (const uint8_t *)res, strlen(res), NULL); + z_query_reply(query, z_query_keyexpr(query), (const uint8_t *)res, strlen(res), NULL); queries++; z_drop(z_move(k_str)); @@ -160,8 +160,10 @@ int main(int argc, char **argv) { char *s1_res = (char *)malloc(64); for (unsigned int i = 0; i < SET; i++) { snprintf(s1_res, 64, "%s%u", uri, i); + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, s1_res); z_owned_keyexpr_t expr; - z_declare_keyexpr(&expr, z_loan(s1), z_keyexpr(s1_res)); + z_declare_keyexpr(&expr, z_loan(s1), z_loan(ke)); printf("Declared resource on session 1: %u %s\n", z_loan(expr)->_id, z_loan(expr)->_suffix); rids1[i] = expr; } @@ -170,8 +172,10 @@ int main(int argc, char **argv) { for (unsigned int i = 0; i < SET; i++) { snprintf(s1_res, 64, "%s%u", uri, i); + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, s1_res); z_owned_keyexpr_t expr; - z_declare_keyexpr(&expr, z_loan(s2), z_keyexpr(s1_res)); + z_declare_keyexpr(&expr, z_loan(s2), z_loan(ke)); printf("Declared resource on session 2: %u %s\n", z_loan(expr)->_id, z_loan(expr)->_suffix); rids2[i] = expr; } @@ -197,7 +201,9 @@ int main(int argc, char **argv) { z_owned_closure_query_t callback; z_closure(&callback, query_handler, NULL, &idx[i]); z_owned_queryable_t *qle = (z_owned_queryable_t *)z_malloc(sizeof(z_owned_queryable_t)); - assert(z_declare_queryable(qle, z_loan(s2), z_keyexpr(s1_res), &callback, NULL) == _Z_RES_OK); + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, s1_res); + assert(z_declare_queryable(qle, z_loan(s2), z_loan(ke), &callback, NULL) == _Z_RES_OK); printf("Declared queryable on session 2: %ju %zu %s\n", (uintmax_t)qle->_val->_entity_id, (z_zint_t)0, s1_res); qles2 = _z_list_push(qles2, qle); } @@ -287,7 +293,9 @@ int main(int argc, char **argv) { snprintf(s1_res, 64, "%s%u", uri, i); z_owned_closure_reply_t callback; z_closure(&callback, reply_handler, NULL, &idx[i]); - z_get(z_loan(s1), z_keyexpr(s1_res), "", &callback, NULL); + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, s1_res); + z_get(z_loan(s1), z_loan(ke), "", &callback, NULL); printf("Queried data from session 1: %zu %s\n", (z_zint_t)0, s1_res); } } diff --git a/tests/z_peer_multicast_test.c b/tests/z_peer_multicast_test.c index 2e7df7cc1..01906c594 100644 --- a/tests/z_peer_multicast_test.c +++ b/tests/z_peer_multicast_test.c @@ -115,7 +115,9 @@ int main(int argc, char **argv) { z_owned_closure_sample_t callback; z_closure(&callback, data_handler, NULL, &idx[i]); z_owned_subscriber_t *sub = (z_owned_subscriber_t *)z_malloc(sizeof(z_owned_subscriber_t)); - int8_t res = z_declare_subscriber(sub, z_loan(s2), z_keyexpr(s1_res), &callback, NULL); + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, s1_res); + int8_t res = z_declare_subscriber(sub, z_loan(s2), z_loan(ke), &callback, NULL); assert(res == _Z_RES_OK); printf("Declared subscription on session 2: %ju %zu %s\n", (uintmax_t)z_subscriber_loan(sub)->_entity_id, (z_zint_t)0, s1_res); @@ -135,7 +137,9 @@ int main(int argc, char **argv) { z_put_options_t opt; z_put_options_default(&opt); opt.congestion_control = Z_CONGESTION_CONTROL_BLOCK; - z_put(z_loan(s1), z_keyexpr(s1_res), (const uint8_t *)payload, len, &opt); + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, s1_res); + z_put(z_loan(s1), z_loan(ke), (const uint8_t *)payload, len, &opt); printf("Wrote data from session 1: %s %zu b\t(%u/%u)\n", s1_res, len, n * SET + (i + 1), total); } } diff --git a/tests/z_perf_rx.c b/tests/z_perf_rx.c index 88e106786..e3324f01d 100644 --- a/tests/z_perf_rx.c +++ b/tests/z_perf_rx.c @@ -102,7 +102,9 @@ int main(int argc, char **argv) { z_owned_closure_sample_t callback; z_closure(&callback, on_sample, NULL, (void *)&test_stats); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to create subscriber.\n"); exit(-1); } diff --git a/tests/z_perf_tx.c b/tests/z_perf_tx.c index cac34429d..be324d3b7 100644 --- a/tests/z_perf_tx.c +++ b/tests/z_perf_tx.c @@ -77,7 +77,9 @@ int main(int argc, char **argv) { } // Declare publisher z_owned_publisher_t pub; - if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(keyexpr), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) { printf("Unable to declare publisher for key expression!\n"); exit(-1); } diff --git a/tests/z_test_fragment_rx.c b/tests/z_test_fragment_rx.c index 368f976be..81d6b27c2 100644 --- a/tests/z_test_fragment_rx.c +++ b/tests/z_test_fragment_rx.c @@ -79,7 +79,9 @@ int main(int argc, char **argv) { z_owned_closure_sample_t callback; z_closure(&callback, data_handler); z_owned_subscriber_t sub; - if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL) < 0) { + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); + if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) { printf("Unable to declare subscriber.\n"); return -1; } diff --git a/tests/z_test_fragment_tx.c b/tests/z_test_fragment_tx.c index 356c9453f..0e6658565 100644 --- a/tests/z_test_fragment_tx.c +++ b/tests/z_test_fragment_tx.c @@ -74,9 +74,11 @@ int main(int argc, char **argv) { z_sleep_s(3); } // Put data + z_view_keyexpr_t ke; + z_view_keyexpr_from_string(&ke, keyexpr); for (int i = 0; i < 5; i++) { printf("[tx]: Sending packet on %s, len: %d\n", keyexpr, (int)size); - if (z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)value, size, NULL) < 0) { + if (z_put(z_loan(s), z_loan(ke), (const uint8_t *)value, size, NULL) < 0) { printf("Oh no! Put has failed...\n"); } z_sleep_s(1);