C / Pico
General API changes
We have reworked the type naming to clarify how types should be interacted with.
Owned types
Owned types are allocated by the user and it is their responsibility to drop them using z_drop
(or z_close
for sessions).
Previously, we were returning Zenoh structures by value. In Zenoh 1.0.0, a reference to memory must be provided. This allows initializing user allocated structures and frees return value for error codes.
Here is a quick example of this change:
- Zenoh 0.11.x
z_owned_session_t session = z_open(z_move(config));
+C / Pico
General API changes
We have reworked the type naming to clarify how types should be interacted with.
Owned types
Owned types are allocated by the user and it is their responsibility to drop them using z_drop
(or z_close
for sessions).
Previously, we were returning Zenoh structures by value. In Zenoh 1.0.0, a reference to memory must be provided. This allows initializing user allocated structures and frees return value for error codes.
Here is a quick example of this change:
- Zenoh 0.11.x
z_owned_session_t session = z_open(z_move(config));
if (!z_check(session)) {
return -1;
}
@@ -41,7 +41,7 @@
z_owned_subscriber_t sub;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str(&ke, keyexpr);
-if (z_declare_subscriber(&sub, z_loan(session), z_loan(ke), z_move(callback), NULL) < 0) {
+if (z_declare_subscriber(z_loan(session), &sub, z_loan(ke), z_move(callback), NULL) < 0) {
return -1;
}
Payload and Serialization
Zenoh 1.0.0 handles payload differently. Before one would pass the pointer to the buffer and its length, now everything must be converted/serialized into z_owned_bytes_t
.
Raw data in the form of null-terminated strings or buffers (i.e. uint8_t*
+ length) can be converted directly into z_owned_bytes_t
@@ -254,7 +254,6 @@
}
}
The same now also works for Subscriber
and Queryable
:
// callback
-// callback
void data_handler(const z_loaned_sample_t *sample, void *context) {
// do something with sample
}
@@ -262,7 +261,7 @@
z_owned_closure_sample_t callback;
z_closure(&callback, data_handler, NULL, NULL);
z_owned_subscriber_t sub;
-if (z_declare_subscriber(&sub, z_loan(session), z_loan(keyexpr), z_move(callback), NULL) < 0) {
+if (z_declare_subscriber(z_loan(session), &sub, z_loan(keyexpr), z_move(callback), NULL) < 0) {
printf("Unable to declare subscriber.\n");
exit(-1);
}
@@ -272,7 +271,7 @@
z_owned_closure_sample_t closure;
z_fifo_channel_reply_new(&closure, &handler, 16);
z_owned_subscriber_t sub;
-if (z_declare_subscriber(&sub, z_loan(session), z_loan(keyexpr), z_move(closure), NULL) < 0) {
+if (z_declare_subscriber(z_loan(session), &sub, z_loan(keyexpr), z_move(closure), NULL) < 0) {
printf("Unable to declare subscriber.\n");
exit(-1);
}