From b2e0e720839280088d45e8ee7feaeb4a2a5d5150 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Mon, 16 Sep 2024 18:03:08 +0200 Subject: [PATCH 01/16] feat: add z_bytes example --- examples/CMakeLists.txt | 1 + examples/unix/c11/z_bytes.c | 184 ++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 examples/unix/c11/z_bytes.c diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a0476703f..a3fc911cd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -54,6 +54,7 @@ if(UNIX) add_example(z_pong unix/c11/z_pong.c) add_example(z_pub_thr unix/c11/z_pub_thr.c) add_example(z_sub_thr unix/c11/z_sub_thr.c) + add_example(z_bytes unix/c11/z_bytes.c) endif() elseif(MSVC) add_example(z_put windows/z_put.c) diff --git a/examples/unix/c11/z_bytes.c b/examples/unix/c11/z_bytes.c new file mode 100644 index 000000000..da5497f72 --- /dev/null +++ b/examples/unix/c11/z_bytes.c @@ -0,0 +1,184 @@ +// +// Copyright (c) 2022 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// + +#include +#include +#include +#include +#include +#include +#include + +#undef NDEBUG +#include + +#include "zenoh-pico/system/platform.h" + +typedef struct kv_pair_t { + const char *key; + const char *value; +} kv_pair_t; + +typedef struct kv_pairs_tx_t { + const kv_pair_t *data; + uint32_t len; + uint32_t current_idx; +} kv_pairs_tx_t; + +typedef struct kv_pair_decoded_t { + z_owned_string_t key; + z_owned_string_t value; +} kv_pair_decoded_t; + +typedef struct kv_pairs_rx_t { + kv_pair_decoded_t *data; + uint32_t len; + uint32_t current_idx; +} kv_pairs_rx_t; + +static bool hashmap_iter(z_owned_bytes_t *kv_pair, void *context); +static bool iter_body(z_owned_bytes_t *b, void *context); +static void parse_hashmap(kv_pairs_rx_t *kvp, const z_loaned_bytes_t *hashmap); +static void drop_hashmap(kv_pairs_rx_t *kvp); + +int main(void) { + z_owned_bytes_t payload; + // z_owned_encoding_t encoding; + + // Number types: uint8, uint16, uint32, uint64, int8, int16, int32, int64, float, double + uint32_t input_u32 = 123456; + uint32_t output_u32 = 0; + z_bytes_serialize_from_uint32(&payload, input_u32); + z_bytes_deserialize_into_uint32(z_loan(payload), &output_u32); + assert(input_u32 == output_u32); + z_drop(z_move(payload)); + // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. + // z_encoding_from_str(&encoding, "zenoh/uint32"); + + // String, also work with and z_owned_string_t + const char *input_str = "test"; + z_owned_string_t output_string; + z_bytes_serialize_from_str(&payload, input_str); + z_bytes_deserialize_into_string(z_loan(payload), &output_string); + assert(strncmp(input_str, z_string_data(z_loan(output_string)), strlen(input_str)) == 0); + z_drop(z_move(payload)); + z_drop(z_move(output_string)); + // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. + // z_encoding_from_str(&encoding, "zenoh/string"); + + // Bytes, also work with z_owned_slice_t + const uint8_t input_bytes[] = {1, 2, 3, 4}; + z_owned_slice_t output_bytes; + z_bytes_serialize_from_buf(&payload, input_bytes, sizeof(input_bytes)); + z_bytes_deserialize_into_slice(z_loan(payload), &output_bytes); + assert(memcmp(input_bytes, z_slice_data(z_loan(output_bytes)), sizeof(input_bytes)) == 0); + z_drop(z_move(payload)); + z_drop(z_move(output_bytes)); + // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. + // z_encoding_from_str(&encoding, "zenoh/bytes"); + + // Writer reader + uint8_t input_writer[] = {0, 1, 2, 3, 4}; + uint8_t output_reader[5] = {0}; + z_bytes_empty(&payload); + z_bytes_writer_t writer = z_bytes_get_writer(z_bytes_loan_mut(&payload)); + z_bytes_writer_write_all(&writer, input_writer, 3); + z_bytes_writer_write_all(&writer, input_writer + 3, 2); + z_bytes_reader_t reader = z_bytes_get_reader(z_bytes_loan(&payload)); + z_bytes_reader_read(&reader, output_reader, sizeof(output_reader)); + assert(0 == memcmp(input_writer, output_reader, sizeof(output_reader))); + z_drop(z_move(payload)); + + // Iterator + uint8_t result_iter[] = {0, 1, 2, 3, 4}; + uint8_t output_iter[5] = {0}; + uint8_t context = 0; + z_bytes_from_iter(&payload, iter_body, (void *)(&context)); + z_bytes_iterator_t it = z_bytes_get_iterator(z_bytes_loan(&payload)); + + z_owned_bytes_t current_item; + size_t i = 0; + while (z_bytes_iterator_next(&it, ¤t_item)) { + z_bytes_deserialize_into_uint8(z_bytes_loan(¤t_item), &output_reader[i]); + z_bytes_drop(z_bytes_move(¤t_item)); + i++; + } + assert(memcmp(output_iter, result_iter, sizeof(output_iter))); + z_drop(z_move(payload)); + + // Hash map + kv_pair_t input_hashmap[1]; + input_hashmap[0] = (kv_pair_t){.key = "test_key", .value = "test_value"}; + kv_pairs_tx_t ctx = (kv_pairs_tx_t){.data = input_hashmap, .current_idx = 0, .len = 1}; + z_owned_bytes_t hashmap; + z_bytes_from_iter(&hashmap, hashmap_iter, (void *)&ctx); + kv_pairs_rx_t output_hashmap = { + .current_idx = 0, .len = 16, .data = (kv_pair_decoded_t *)malloc(16 * sizeof(kv_pair_decoded_t))}; + parse_hashmap(&output_hashmap, z_loan(hashmap)); + assert(strncmp(input_hashmap[0].key, _z_string_data(z_loan(output_hashmap.data[0].key)), + strlen(input_hashmap[0].key)) == 0); + assert(strncmp(input_hashmap[0].value, _z_string_data(z_loan(output_hashmap.data[0].value)), + strlen(input_hashmap[0].value)) == 0); + z_drop(z_move(payload)); + drop_hashmap(&output_hashmap); + return 0; +} + +static bool iter_body(z_owned_bytes_t *b, void *context) { + uint8_t *val = (uint8_t *)context; + if (*val >= 5) { + return false; + } else { + z_bytes_serialize_from_uint8(b, *val); + } + *val = *val + 1; + return true; +} + +static bool hashmap_iter(z_owned_bytes_t *kv_pair, void *context) { + kv_pairs_tx_t *kvs = (kv_pairs_tx_t *)(context); + z_owned_bytes_t k, v; + if (kvs->current_idx >= kvs->len) { + return false; + } else { + z_bytes_serialize_from_str(&k, kvs->data[kvs->current_idx].key); + z_bytes_serialize_from_str(&v, kvs->data[kvs->current_idx].value); + z_bytes_from_pair(kv_pair, z_move(k), z_move(v)); + kvs->current_idx++; + return true; + } +} + +static void parse_hashmap(kv_pairs_rx_t *kvp, const z_loaned_bytes_t *hashmap) { + z_owned_bytes_t kv, first, second; + z_bytes_iterator_t iter = z_bytes_get_iterator(hashmap); + + while (kvp->current_idx < kvp->len && z_bytes_iterator_next(&iter, &kv)) { + z_bytes_deserialize_into_pair(z_loan(kv), &first, &second); + z_bytes_deserialize_into_string(z_loan(first), &kvp->data[kvp->current_idx].key); + z_bytes_deserialize_into_string(z_loan(second), &kvp->data[kvp->current_idx].value); + z_bytes_drop(z_bytes_move(&first)); + z_bytes_drop(z_bytes_move(&second)); + z_bytes_drop(z_bytes_move(&kv)); + kvp->current_idx++; + } +} + +static void drop_hashmap(kv_pairs_rx_t *kvp) { + for (size_t i = 0; i < kvp->current_idx; i++) { + z_string_drop(z_string_move(&kvp->data[i].key)); + z_string_drop(z_string_move(&kvp->data[i].value)); + } + z_free(kvp->data); +} From f2bedc47010057c81040fa9a34b145f694f1605f Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 17 Sep 2024 14:37:26 +0200 Subject: [PATCH 02/16] feat: add encoding constants --- include/zenoh-pico/api/constants.h | 87 ------- include/zenoh-pico/api/types.h | 382 +++++++++++++++++++++++++++++ src/api/api.c | 331 +++++++++++++++++++++++++ 3 files changed, 713 insertions(+), 87 deletions(-) diff --git a/include/zenoh-pico/api/constants.h b/include/zenoh-pico/api/constants.h index d91fc3441..d2c623e4c 100644 --- a/include/zenoh-pico/api/constants.h +++ b/include/zenoh-pico/api/constants.h @@ -109,93 +109,6 @@ typedef enum { typedef enum { Z_SAMPLE_KIND_PUT = 0, Z_SAMPLE_KIND_DELETE = 1 } z_sample_kind_t; #define Z_SAMPLE_KIND_DEFAULT Z_SAMPLE_KIND_PUT -/** - * Default encoding values used by Zenoh. - * - * An encoding has a similar role to Content-type in HTTP: it indicates, when present, how data should be interpreted by - * the application. - * - * Please note the Zenoh protocol does not impose any encoding value nor it operates on it. - * It can be seen as some optional metadata that is carried over by Zenoh in such a way the application may perform - * different operations depending on the encoding value. - * - * A set of associated constants are provided to cover the most common encodings for user convenience. - * This is particularly useful in helping Zenoh to perform additional wire-level optimizations. - * - * Register your encoding metadata from a string with :c:func:`z_encoding_from_str`. To get the optimization, you need - * Z_FEATURE_ENCODING_VALUES to 1 and your string should follow the format: ";" - * - * E.g: "text/plain;utf8" - * - * Here is the list of constants: - */ -// "zenoh/bytes" -// "zenoh/int8" -// "zenoh/int16" -// "zenoh/int32" -// "zenoh/int64" -// "zenoh/int128" -// "zenoh/uint8" -// "zenoh/uint16" -// "zenoh/uint32" -// "zenoh/uint64" -// "zenoh/uint128" -// "zenoh/float32" -// "zenoh/float64" -// "zenoh/bool" -// "zenoh/string" -// "zenoh/error" -// "application/octet-stream" -// "text/plain" -// "application/json" -// "text/json" -// "application/cdr" -// "application/cbor" -// "application/yaml" -// "text/yaml" -// "text/json5" -// "application/python-serialized-object" -// "application/protobuf" -// "application/java-serialized-object" -// "application/openmetrics-text" -// "image/png" -// "image/jpeg" -// "image/gif" -// "image/bmp" -// "image/webp" -// "application/xml" -// "application/x-www-form-urlencoded" -// "text/html" -// "text/xml" -// "text/css" -// "text/javascript" -// "text/markdown" -// "text/csv" -// "application/sql" -// "application/coap-payload" -// "application/json-patch+json" -// "application/json-seq" -// "application/jsonpath" -// "application/jwt" -// "application/mp4" -// "application/soap+xml" -// "application/yang" -// "audio/aac" -// "audio/flac" -// "audio/mp4" -// "audio/ogg" -// "audio/vorbis" -// "video/h261" -// "video/h263" -// "video/h264" -// "video/h265" -// "video/h266" -// "video/mp4" -// "video/ogg" -// "video/raw" -// "video/vp8" -// "video/vp9" - /** * Consolidation mode values. * diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index f1f6ae955..c10fa8db8 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -607,6 +607,388 @@ _Z_OWNED_TYPE_VALUE(_z_closure_zid_t, closure_zid) void z_closure_zid_call(const z_loaned_closure_zid_t *closure, const z_id_t *id); +/** + * Default encoding values used by Zenoh. + * + * An encoding has a similar role to Content-type in HTTP: it indicates, when present, how data should be interpreted by + * the application. + * + * Please note the Zenoh protocol does not impose any encoding value nor it operates on it. + * It can be seen as some optional metadata that is carried over by Zenoh in such a way the application may perform + * different operations depending on the encoding value. + * + * A set of associated constants are provided to cover the most common encodings for user convenience. + * This is particularly useful in helping Zenoh to perform additional wire-level optimizations. + * + * Register your encoding metadata from a string with :c:func:`z_encoding_from_str`. To get the optimization, you need + * Z_FEATURE_ENCODING_VALUES to 1 and your string should follow the format: ";" + * + * E.g: "text/plain;utf8" + * + * Or you can set the value to the constants directly with this list of constants: + */ + +#if Z_FEATURE_ENCODING_VALUES == 1 +// - Below are Primitives types, supported in all Zenoh bindings +// Just some bytes. +// +// Constant alias for string: `"zenoh/bytes"`. +// +// Usually used for types: `uint8_t[]`. +extern const z_owned_encoding_t ENCODING_ZENOH_BYTES; + +// A VLE-encoded signed little-endian 8bit integer. Binary representation uses two's complement. +//// - Primitives types supported in all Zenoh bindings +// Constant alias for string: `"zenoh/int8"`. +// +// Usually used for types: `int8_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_INT8; + +// A VLE-encoded signed little-endian 16bit integer. Binary representation uses two's complement. +// +// Constant alias for string: `"zenoh/int16"`. +// +// Usually used for types: `int16_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_INT16; + +// A VLE-encoded signed little-endian 32bit integer. Binary representation uses two's complement. +// +// Constant alias for string: `"zenoh/int32"`. +// +// Usually used for types: `int32_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_INT32; + +// A VLE-encoded signed little-endian 64bit integer. Binary representation uses two's complement. +// +// Constant alias for string: `"zenoh/int64"`. +// +// Usually used for types: `int64_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_INT64; + +// A VLE-encoded signed little-endian 128bit integer. Binary representation uses two's complement. +// +// Constant alias for string: `"zenoh/int128"`. +extern const z_owned_encoding_t ENCODING_ZENOH_INT128; + +// A VLE-encoded unsigned little-endian 8bit integer. +// +// Constant alias for string: `"zenoh/uint8"`. +// +// Usually used for types: `uint8_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_UINT8; + +// A VLE-encoded unsigned little-endian 16bit integer. +// +// Constant alias for string: `"zenoh/uint16"`. +// +// Usually used for types: `uint16_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_UINT16; +// A VLE-encoded unsigned little-endian 32bit integer. +// +// Constant alias for string: `"zenoh/uint32"`. +// +// Usually used for types: `uint32_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_UINT32; + +// A VLE-encoded unsigned little-endian 64bit integer. +// +// Constant alias for string: `"zenoh/uint64"`. +// +// Usually used for types: `uint64_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_UINT64; + +// A VLE-encoded unsigned little-endian 128bit integer. +// +// Constant alias for string: `"zenoh/uint128"`. +extern const z_owned_encoding_t ENCODING_ZENOH_UINT128; + +// A VLE-encoded 32bit float. Binary representation uses *IEEE 754-2008* *binary32* . +// +// Constant alias for string: `"zenoh/float32"`. +// +// Usually used for types: `float`. +extern const z_owned_encoding_t ENCODING_ZENOH_FLOAT32; + +// A VLE-encoded 64bit float. Binary representation uses *IEEE 754-2008* *binary64*. +// +// Constant alias for string: `"zenoh/float64"`. +// +// Usually used for types: `double`. +extern const z_owned_encoding_t ENCODING_ZENOH_FLOAT64; + +// A boolean. `0` is `false`, `1` is `true`. Other values are invalid. +// +// Constant alias for string: `"zenoh/bool"`. +// +// Usually used for types: `bool`. +extern const z_owned_encoding_t ENCODING_ZENOH_BOOL; + +// A UTF-8 string. +// +// Constant alias for string: `"zenoh/string"`. +// +// Usually used for types: `char[]`. +extern const z_owned_encoding_t ENCODING_ZENOH_STRING; +// A zenoh error. +// +// Constant alias for string: `"zenoh/error"`. +// +// Usually used for types: `z_reply_err_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_ERROR; + +// - Below are Advanced types, may be supported in some of the Zenoh bindings. +// An application-specific stream of bytes. +// +// Constant alias for string: `"application/octet-stream"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_OCTET_STREAM; + +// A textual file. +// +// Constant alias for string: `"text/plain"`. +extern const z_owned_encoding_t ENCODING_TEXT_PLAIN; + +// JSON data intended to be consumed by an application. +// +// Constant alias for string: `"application/json"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JSON; + +// JSON data intended to be human readable. +// +// Constant alias for string: `"text/json"`. +extern const z_owned_encoding_t ENCODING_TEXT_JSON; + +// A Common Data Representation (CDR)-encoded data. +// +// Constant alias for string: `"application/cdr"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_CDR; + +// A Concise Binary Object Representation (CBOR)-encoded data. +// +// Constant alias for string: `"application/cbor"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_CBOR; + +// YAML data intended to be consumed by an application. +// +// Constant alias for string: `"application/yaml"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_YAML; + +// YAML data intended to be human readable. +// +// Constant alias for string: `"text/yaml"`. +extern const z_owned_encoding_t ENCODING_TEXT_YAML; + +// JSON5 encoded data that are human readable. +// +// Constant alias for string: `"text/json5"`. +extern const z_owned_encoding_t ENCODING_TEXT_JSON5; + +// A Python object serialized using [pickle](https://docs.python.org/3/library/pickle.html). +// +// Constant alias for string: `"application/python-serialized-object"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_PYTHON_SERIALIZED_OBJECT; + +// An application-specific protobuf-encoded data. +// +// Constant alias for string: `"application/protobuf"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_PROTOBUF; + +// A Java serialized object. +// +// Constant alias for string: `"application/java-serialized-object"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JAVA_SERIALIZED_OBJECT; + +// An [openmetrics](https://github.com/OpenObservability/OpenMetrics) data, common used by +// [Prometheus](https://prometheus.io/). +// +// Constant alias for string: `"application/openmetrics-text"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_OPENMETRICS_TEXT; + +// A Portable Network Graphics (PNG) image. +// +// Constant alias for string: `"image/png"`. +extern const z_owned_encoding_t ENCODING_IMAGE_PNG; + +// A Joint Photographic Experts Group (JPEG) image. +// +// Constant alias for string: `"image/jpeg"`. +extern const z_owned_encoding_t ENCODING_IMAGE_JPEG; + +// A Graphics Interchange Format (GIF) image. +// +// Constant alias for string: `"image/gif"`. +extern const z_owned_encoding_t ENCODING_IMAGE_GIF; + +// A BitMap (BMP) image. +// +// Constant alias for string: `"image/bmp"`. +extern const z_owned_encoding_t ENCODING_IMAGE_BMP; + +// A Web Portable (WebP) image. +// +// Constant alias for string: `"image/webp"`. +extern const z_owned_encoding_t ENCODING_IMAGE_WEBP; + +// An XML file intended to be consumed by an application.. +// +// Constant alias for string: `"application/xml"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_XML; + +// An encoded a list of tuples, each consisting of a name and a value. +// +// Constant alias for string: `"application/x-www-form-urlencoded"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_X_WWW_FORM_URLENCODED; + +// An HTML file. +// +// Constant alias for string: `"text/html"`. +extern const z_owned_encoding_t ENCODING_TEXT_HTML; + +// An XML file that is human readable. +// +// Constant alias for string: `"text/xml"`. +extern const z_owned_encoding_t ENCODING_TEXT_XML; + +// A CSS file. +// +// Constant alias for string: `"text/css"`. +extern const z_owned_encoding_t ENCODING_TEXT_CSS; + +// A JavaScript file. +// +// Constant alias for string: `"text/javascript"`. +extern const z_owned_encoding_t ENCODING_TEXT_JAVASCRIPT; + +// A MarkDown file. +// +// Constant alias for string: `"text/markdown"`. +extern const z_owned_encoding_t ENCODING_TEXT_MARKDOWN; + +// A CSV file. +// +// Constant alias for string: `"text/csv"`. +extern const z_owned_encoding_t ENCODING_TEXT_CSV; + +// An application-specific SQL query. +// +// Constant alias for string: `"application/sql"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_SQL; + +// Constrained Application Protocol (CoAP) data intended for CoAP-to-HTTP and HTTP-to-CoAP proxies. +// +// Constant alias for string: `"application/coap-payload"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_COAP_PAYLOAD; + +// Defines a JSON document structure for expressing a sequence of operations to apply to a JSON document. +// +// Constant alias for string: `"application/json-patch+json"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_PATCH_JSON; + +// A JSON text sequence consists of any number of JSON texts, all encoded in UTF-8. +// +// Constant alias for string: `"application/json-seq"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_SEQ; + +// A JSONPath defines a string syntax for selecting and extracting JSON values from within a given JSON value. +// +// Constant alias for string: `"application/jsonpath"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JSONPATH; + +// A JSON Web Token (JWT). +// +// Constant alias for string: `"application/jwt"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JWT; + +// An application-specific MPEG-4 encoded data, either audio or video. +// +// Constant alias for string: `"application/mp4"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_MP4; + +// A SOAP 1.2 message serialized as XML 1.0. +// +// Constant alias for string: `"application/soap+xml"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_SOAP_XML; + +// A YANG-encoded data commonly used by the Network Configuration Protocol (NETCONF). +// +// Constant alias for string: `"application/yang"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_YANG; + +// A MPEG-4 Advanced Audio Coding (AAC) media. +// +// Constant alias for string: `"audio/aac"`. +extern const z_owned_encoding_t ENCODING_AUDIO_AAC; + +// A Free Lossless Audio Codec (FLAC) media. +// +// Constant alias for string: `"audio/flac"`. +extern const z_owned_encoding_t ENCODING_AUDIO_FLAC; + +// An audio codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. +// +// Constant alias for string: `"audio/mp4"`. +extern const z_owned_encoding_t ENCODING_AUDIO_MP4; + +// An Ogg-encapsulated audio stream. +// +// Constant alias for string: `"audio/ogg"`. +extern const z_owned_encoding_t ENCODING_AUDIO_OGG; + +// A Vorbis-encoded audio stream. +// +// Constant alias for string: `"audio/vorbis"`. +extern const z_owned_encoding_t ENCODING_AUDIO_VORBIS; + +// A h261-encoded video stream. +// +// Constant alias for string: `"video/h261"`. +extern const z_owned_encoding_t ENCODING_VIDEO_H261; + +// A h263-encoded video stream. +// +// Constant alias for string: `"video/h263"`. +extern const z_owned_encoding_t ENCODING_VIDEO_H263; + +// A h264-encoded video stream. +// +// Constant alias for string: `"video/h264"`. +extern const z_owned_encoding_t ENCODING_VIDEO_H264; + +// A h265-encoded video stream. +// +// Constant alias for string: `"video/h265"`. +extern const z_owned_encoding_t ENCODING_VIDEO_H265; + +// A h266-encoded video stream. +// +// Constant alias for string: `"video/h266"`. +extern const z_owned_encoding_t ENCODING_VIDEO_H266; + +// A video codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. +// +// Constant alias for string: `"video/mp4"`. +extern const z_owned_encoding_t ENCODING_VIDEO_MP4; + +// An Ogg-encapsulated video stream. +// +// Constant alias for string: `"video/ogg"`. +extern const z_owned_encoding_t ENCODING_VIDEO_OGG; + +// An uncompressed, studio-quality video stream. +// +// Constant alias for string: `"video/raw"`. +extern const z_owned_encoding_t ENCODING_VIDEO_RAW; + +// A VP8-encoded video stream. +// +// Constant alias for string: `"video/vp8"`. +extern const z_owned_encoding_t ENCODING_VIDEO_VP8; + +// A VP9-encoded video stream. +// +// Constant alias for string: `"video/vp9"`. +extern const z_owned_encoding_t ENCODING_VIDEO_VP9; +#endif + #ifdef __cplusplus } #endif diff --git a/src/api/api.c b/src/api/api.c index 7883a46f6..060edfa9c 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -217,6 +217,337 @@ z_result_t zp_config_insert(z_loaned_config_t *config, uint8_t key, const char * #if Z_FEATURE_ENCODING_VALUES == 1 #define ENCODING_SCHEMA_SEPARATOR ';' +const z_owned_encoding_t ENCODING_ZENOH_BYTES = { + ._val = { + .id = 0, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_INT8 = { + ._val = { + .id = 1, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_INT16 = { + ._val = { + .id = 2, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_INT32 = { + ._val = { + .id = 3, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_INT64 = { + ._val = { + .id = 4, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_INT128 = { + ._val = { + .id = 5, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_UINT8 = { + ._val = { + .id = 6, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_UINT16 = { + ._val = { + .id = 7, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_UINT32 = { + ._val = { + .id = 8, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_UINT64 = { + ._val = { + .id = 9, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_UINT128 = { + ._val = { + .id = 10, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_FLOAT32 = { + ._val = { + .id = 11, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_FLOAT64 = { + ._val = { + .id = 12, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_BOOL = { + ._val = { + .id = 13, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_STRING = { + ._val = { + .id = 14, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_ZENOH_ERROR = { + ._val = { + .id = 15, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_OCTET_STREAM = { + ._val = { + .id = 16, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_TEXT_PLAIN = { + ._val = { + .id = 17, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_JSON = { + ._val = { + .id = 18, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_TEXT_JSON = { + ._val = { + .id = 19, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_CDR = { + ._val = { + .id = 20, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_CBOR = { + ._val = { + .id = 21, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_YAML = { + ._val = { + .id = 22, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_TEXT_YAML = { + ._val = { + .id = 23, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_TEXT_JSON5 = { + ._val = { + .id = 24, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_PYTHON_SERIALIZED_OBJECT = { + ._val = { + .id = 25, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_PROTOBUF = { + ._val = { + .id = 26, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_JAVA_SERIALIZED_OBJECT = { + ._val = { + .id = 27, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_OPENMETRICS_TEXT = { + ._val = { + .id = 28, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_IMAGE_PNG = { + ._val = { + .id = 29, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_IMAGE_JPEG = { + ._val = { + .id = 30, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_IMAGE_GIF = { + ._val = { + .id = 31, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_IMAGE_BMP = { + ._val = { + .id = 32, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_IMAGE_WEBP = { + ._val = { + .id = 33, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_XML = { + ._val = { + .id = 34, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_X_WWW_FORM_URLENCODED = { + ._val = { + .id = 35, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_TEXT_HTML = { + ._val = { + .id = 36, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_TEXT_XML = { + ._val = { + .id = 37, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_TEXT_CSS = { + ._val = { + .id = 38, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_TEXT_JAVASCRIPT = { + ._val = { + .id = 39, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_TEXT_MARKDOWN = { + ._val = { + .id = 40, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_TEXT_CSV = { + ._val = { + .id = 41, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_SQL = { + ._val = { + .id = 42, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_COAP_PAYLOAD = { + ._val = { + .id = 43, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_JSON_PATCH_JSON = { + ._val = { + .id = 44, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_JSON_SEQ = { + ._val = { + .id = 45, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_JSONPATH = { + ._val = { + .id = 46, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_JWT = { + ._val = { + .id = 47, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_MP4 = { + ._val = { + .id = 48, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_SOAP_XML = { + ._val = { + .id = 49, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_APPLICATION_YANG = { + ._val = { + .id = 50, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_AUDIO_AAC = { + ._val = { + .id = 51, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_AUDIO_FLAC = { + ._val = { + .id = 52, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_AUDIO_MP4 = { + ._val = { + .id = 53, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_AUDIO_OGG = { + ._val = { + .id = 54, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_AUDIO_VORBIS = { + ._val = { + .id = 55, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_VIDEO_H261 = { + ._val = { + .id = 56, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_VIDEO_H263 = { + ._val = { + .id = 57, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_VIDEO_H264 = { + ._val = { + .id = 58, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_VIDEO_H265 = { + ._val = { + .id = 59, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_VIDEO_H266 = { + ._val = { + .id = 60, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_VIDEO_MP4 = { + ._val = { + .id = 61, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_VIDEO_OGG = { + ._val = { + .id = 62, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_VIDEO_RAW = { + ._val = { + .id = 63, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_VIDEO_VP8 = { + ._val = { + .id = 64, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; +const z_owned_encoding_t ENCODING_VIDEO_VP9 = { + ._val = { + .id = 65, + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, + }}; + const char *ENCODING_VALUES_ID_TO_STR[] = { "zenoh/bytes", "zenoh/int8", From 7981602204ecdef7a4af119edb1fc2dc4892ee91 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 17 Sep 2024 14:38:06 +0200 Subject: [PATCH 03/16] feat: use encoding constants in z_bytes --- examples/unix/c11/z_bytes.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/unix/c11/z_bytes.c b/examples/unix/c11/z_bytes.c index da5497f72..2f1519988 100644 --- a/examples/unix/c11/z_bytes.c +++ b/examples/unix/c11/z_bytes.c @@ -54,7 +54,8 @@ static void drop_hashmap(kv_pairs_rx_t *kvp); int main(void) { z_owned_bytes_t payload; - // z_owned_encoding_t encoding; + z_owned_encoding_t encoding; + (void)encoding; // Number types: uint8, uint16, uint32, uint64, int8, int16, int32, int64, float, double uint32_t input_u32 = 123456; @@ -64,7 +65,7 @@ int main(void) { assert(input_u32 == output_u32); z_drop(z_move(payload)); // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. - // z_encoding_from_str(&encoding, "zenoh/uint32"); + encoding = ENCODING_ZENOH_UINT32; // String, also work with and z_owned_string_t const char *input_str = "test"; @@ -75,7 +76,7 @@ int main(void) { z_drop(z_move(payload)); z_drop(z_move(output_string)); // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. - // z_encoding_from_str(&encoding, "zenoh/string"); + encoding = ENCODING_ZENOH_STRING; // Bytes, also work with z_owned_slice_t const uint8_t input_bytes[] = {1, 2, 3, 4}; @@ -86,7 +87,7 @@ int main(void) { z_drop(z_move(payload)); z_drop(z_move(output_bytes)); // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. - // z_encoding_from_str(&encoding, "zenoh/bytes"); + encoding = ENCODING_ZENOH_BYTES; // That's the default value // Writer reader uint8_t input_writer[] = {0, 1, 2, 3, 4}; From 7407dcc03da3fcda933a167d1e030ea07eb055fc Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 17 Sep 2024 14:44:01 +0200 Subject: [PATCH 04/16] refactor: move encoding constants to encoding.h --- examples/unix/c11/z_bytes.c | 2 +- include/zenoh-pico.h | 1 + include/zenoh-pico.h.in | 1 + include/zenoh-pico/api/encoding.h | 408 ++++++++++++++++++++++++++++++ include/zenoh-pico/api/types.h | 382 ---------------------------- 5 files changed, 411 insertions(+), 383 deletions(-) create mode 100644 include/zenoh-pico/api/encoding.h diff --git a/examples/unix/c11/z_bytes.c b/examples/unix/c11/z_bytes.c index 2f1519988..2d8f51a11 100644 --- a/examples/unix/c11/z_bytes.c +++ b/examples/unix/c11/z_bytes.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2022 ZettaScale Technology +// Copyright (c) 2024 ZettaScale Technology // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License 2.0 which is available at diff --git a/include/zenoh-pico.h b/include/zenoh-pico.h index a41138ff3..b34291ca4 100644 --- a/include/zenoh-pico.h +++ b/include/zenoh-pico.h @@ -24,6 +24,7 @@ #define ZENOH_PICO_TWEAK 0 #include "zenoh-pico/api/constants.h" +#include "zenoh-pico/api/encoding.h" #include "zenoh-pico/api/handlers.h" #include "zenoh-pico/api/macros.h" #include "zenoh-pico/api/primitives.h" diff --git a/include/zenoh-pico.h.in b/include/zenoh-pico.h.in index 1db75cd76..bd4790b1e 100644 --- a/include/zenoh-pico.h.in +++ b/include/zenoh-pico.h.in @@ -24,6 +24,7 @@ #define ZENOH_PICO_TWEAK @ZENOH_PICO_TWEAK@ #include "zenoh-pico/api/constants.h" +#include "zenoh-pico/api/encoding.h" #include "zenoh-pico/api/handlers.h" #include "zenoh-pico/api/macros.h" #include "zenoh-pico/api/primitives.h" diff --git a/include/zenoh-pico/api/encoding.h b/include/zenoh-pico/api/encoding.h new file mode 100644 index 000000000..fdfb0b1b8 --- /dev/null +++ b/include/zenoh-pico/api/encoding.h @@ -0,0 +1,408 @@ +// +// Copyright (c) 2024 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, + +#ifndef ZENOH_PICO_API_ENCODING_H +#define ZENOH_PICO_API_ENCODING_H + +#include "zenoh-pico/api/types.h" + +#ifdef __cplusplus +extern "C" { +#endif +/** + * Default encoding values used by Zenoh. + * + * An encoding has a similar role to Content-type in HTTP: it indicates, when present, how data should be interpreted by + * the application. + * + * Please note the Zenoh protocol does not impose any encoding value nor it operates on it. + * It can be seen as some optional metadata that is carried over by Zenoh in such a way the application may perform + * different operations depending on the encoding value. + * + * A set of associated constants are provided to cover the most common encodings for user convenience. + * This is particularly useful in helping Zenoh to perform additional wire-level optimizations. + * + * Register your encoding metadata from a string with :c:func:`z_encoding_from_str`. To get the optimization, you need + * Z_FEATURE_ENCODING_VALUES to 1 and your string should follow the format: ";" + * + * E.g: "text/plain;utf8" + * + * Or you can set the value to the constants directly with this list of constants: + */ + +#if Z_FEATURE_ENCODING_VALUES == 1 +// - Below are Primitives types, supported in all Zenoh bindings +// Just some bytes. +// +// Constant alias for string: `"zenoh/bytes"`. +// +// Usually used for types: `uint8_t[]`. +extern const z_owned_encoding_t ENCODING_ZENOH_BYTES; + +// A VLE-encoded signed little-endian 8bit integer. Binary representation uses two's complement. +//// - Primitives types supported in all Zenoh bindings +// Constant alias for string: `"zenoh/int8"`. +// +// Usually used for types: `int8_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_INT8; + +// A VLE-encoded signed little-endian 16bit integer. Binary representation uses two's complement. +// +// Constant alias for string: `"zenoh/int16"`. +// +// Usually used for types: `int16_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_INT16; + +// A VLE-encoded signed little-endian 32bit integer. Binary representation uses two's complement. +// +// Constant alias for string: `"zenoh/int32"`. +// +// Usually used for types: `int32_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_INT32; + +// A VLE-encoded signed little-endian 64bit integer. Binary representation uses two's complement. +// +// Constant alias for string: `"zenoh/int64"`. +// +// Usually used for types: `int64_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_INT64; + +// A VLE-encoded signed little-endian 128bit integer. Binary representation uses two's complement. +// +// Constant alias for string: `"zenoh/int128"`. +extern const z_owned_encoding_t ENCODING_ZENOH_INT128; + +// A VLE-encoded unsigned little-endian 8bit integer. +// +// Constant alias for string: `"zenoh/uint8"`. +// +// Usually used for types: `uint8_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_UINT8; + +// A VLE-encoded unsigned little-endian 16bit integer. +// +// Constant alias for string: `"zenoh/uint16"`. +// +// Usually used for types: `uint16_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_UINT16; +// A VLE-encoded unsigned little-endian 32bit integer. +// +// Constant alias for string: `"zenoh/uint32"`. +// +// Usually used for types: `uint32_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_UINT32; + +// A VLE-encoded unsigned little-endian 64bit integer. +// +// Constant alias for string: `"zenoh/uint64"`. +// +// Usually used for types: `uint64_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_UINT64; + +// A VLE-encoded unsigned little-endian 128bit integer. +// +// Constant alias for string: `"zenoh/uint128"`. +extern const z_owned_encoding_t ENCODING_ZENOH_UINT128; + +// A VLE-encoded 32bit float. Binary representation uses *IEEE 754-2008* *binary32* . +// +// Constant alias for string: `"zenoh/float32"`. +// +// Usually used for types: `float`. +extern const z_owned_encoding_t ENCODING_ZENOH_FLOAT32; + +// A VLE-encoded 64bit float. Binary representation uses *IEEE 754-2008* *binary64*. +// +// Constant alias for string: `"zenoh/float64"`. +// +// Usually used for types: `double`. +extern const z_owned_encoding_t ENCODING_ZENOH_FLOAT64; + +// A boolean. `0` is `false`, `1` is `true`. Other values are invalid. +// +// Constant alias for string: `"zenoh/bool"`. +// +// Usually used for types: `bool`. +extern const z_owned_encoding_t ENCODING_ZENOH_BOOL; + +// A UTF-8 string. +// +// Constant alias for string: `"zenoh/string"`. +// +// Usually used for types: `char[]`. +extern const z_owned_encoding_t ENCODING_ZENOH_STRING; +// A zenoh error. +// +// Constant alias for string: `"zenoh/error"`. +// +// Usually used for types: `z_reply_err_t`. +extern const z_owned_encoding_t ENCODING_ZENOH_ERROR; + +// - Below are Advanced types, may be supported in some of the Zenoh bindings. +// An application-specific stream of bytes. +// +// Constant alias for string: `"application/octet-stream"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_OCTET_STREAM; + +// A textual file. +// +// Constant alias for string: `"text/plain"`. +extern const z_owned_encoding_t ENCODING_TEXT_PLAIN; + +// JSON data intended to be consumed by an application. +// +// Constant alias for string: `"application/json"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JSON; + +// JSON data intended to be human readable. +// +// Constant alias for string: `"text/json"`. +extern const z_owned_encoding_t ENCODING_TEXT_JSON; + +// A Common Data Representation (CDR)-encoded data. +// +// Constant alias for string: `"application/cdr"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_CDR; + +// A Concise Binary Object Representation (CBOR)-encoded data. +// +// Constant alias for string: `"application/cbor"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_CBOR; + +// YAML data intended to be consumed by an application. +// +// Constant alias for string: `"application/yaml"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_YAML; + +// YAML data intended to be human readable. +// +// Constant alias for string: `"text/yaml"`. +extern const z_owned_encoding_t ENCODING_TEXT_YAML; + +// JSON5 encoded data that are human readable. +// +// Constant alias for string: `"text/json5"`. +extern const z_owned_encoding_t ENCODING_TEXT_JSON5; + +// A Python object serialized using [pickle](https://docs.python.org/3/library/pickle.html). +// +// Constant alias for string: `"application/python-serialized-object"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_PYTHON_SERIALIZED_OBJECT; + +// An application-specific protobuf-encoded data. +// +// Constant alias for string: `"application/protobuf"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_PROTOBUF; + +// A Java serialized object. +// +// Constant alias for string: `"application/java-serialized-object"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JAVA_SERIALIZED_OBJECT; + +// An [openmetrics](https://github.com/OpenObservability/OpenMetrics) data, common used by +// [Prometheus](https://prometheus.io/). +// +// Constant alias for string: `"application/openmetrics-text"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_OPENMETRICS_TEXT; + +// A Portable Network Graphics (PNG) image. +// +// Constant alias for string: `"image/png"`. +extern const z_owned_encoding_t ENCODING_IMAGE_PNG; + +// A Joint Photographic Experts Group (JPEG) image. +// +// Constant alias for string: `"image/jpeg"`. +extern const z_owned_encoding_t ENCODING_IMAGE_JPEG; + +// A Graphics Interchange Format (GIF) image. +// +// Constant alias for string: `"image/gif"`. +extern const z_owned_encoding_t ENCODING_IMAGE_GIF; + +// A BitMap (BMP) image. +// +// Constant alias for string: `"image/bmp"`. +extern const z_owned_encoding_t ENCODING_IMAGE_BMP; + +// A Web Portable (WebP) image. +// +// Constant alias for string: `"image/webp"`. +extern const z_owned_encoding_t ENCODING_IMAGE_WEBP; + +// An XML file intended to be consumed by an application.. +// +// Constant alias for string: `"application/xml"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_XML; + +// An encoded a list of tuples, each consisting of a name and a value. +// +// Constant alias for string: `"application/x-www-form-urlencoded"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_X_WWW_FORM_URLENCODED; + +// An HTML file. +// +// Constant alias for string: `"text/html"`. +extern const z_owned_encoding_t ENCODING_TEXT_HTML; + +// An XML file that is human readable. +// +// Constant alias for string: `"text/xml"`. +extern const z_owned_encoding_t ENCODING_TEXT_XML; + +// A CSS file. +// +// Constant alias for string: `"text/css"`. +extern const z_owned_encoding_t ENCODING_TEXT_CSS; + +// A JavaScript file. +// +// Constant alias for string: `"text/javascript"`. +extern const z_owned_encoding_t ENCODING_TEXT_JAVASCRIPT; + +// A MarkDown file. +// +// Constant alias for string: `"text/markdown"`. +extern const z_owned_encoding_t ENCODING_TEXT_MARKDOWN; + +// A CSV file. +// +// Constant alias for string: `"text/csv"`. +extern const z_owned_encoding_t ENCODING_TEXT_CSV; + +// An application-specific SQL query. +// +// Constant alias for string: `"application/sql"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_SQL; + +// Constrained Application Protocol (CoAP) data intended for CoAP-to-HTTP and HTTP-to-CoAP proxies. +// +// Constant alias for string: `"application/coap-payload"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_COAP_PAYLOAD; + +// Defines a JSON document structure for expressing a sequence of operations to apply to a JSON document. +// +// Constant alias for string: `"application/json-patch+json"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_PATCH_JSON; + +// A JSON text sequence consists of any number of JSON texts, all encoded in UTF-8. +// +// Constant alias for string: `"application/json-seq"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_SEQ; + +// A JSONPath defines a string syntax for selecting and extracting JSON values from within a given JSON value. +// +// Constant alias for string: `"application/jsonpath"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JSONPATH; + +// A JSON Web Token (JWT). +// +// Constant alias for string: `"application/jwt"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_JWT; + +// An application-specific MPEG-4 encoded data, either audio or video. +// +// Constant alias for string: `"application/mp4"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_MP4; + +// A SOAP 1.2 message serialized as XML 1.0. +// +// Constant alias for string: `"application/soap+xml"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_SOAP_XML; + +// A YANG-encoded data commonly used by the Network Configuration Protocol (NETCONF). +// +// Constant alias for string: `"application/yang"`. +extern const z_owned_encoding_t ENCODING_APPLICATION_YANG; + +// A MPEG-4 Advanced Audio Coding (AAC) media. +// +// Constant alias for string: `"audio/aac"`. +extern const z_owned_encoding_t ENCODING_AUDIO_AAC; + +// A Free Lossless Audio Codec (FLAC) media. +// +// Constant alias for string: `"audio/flac"`. +extern const z_owned_encoding_t ENCODING_AUDIO_FLAC; + +// An audio codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. +// +// Constant alias for string: `"audio/mp4"`. +extern const z_owned_encoding_t ENCODING_AUDIO_MP4; + +// An Ogg-encapsulated audio stream. +// +// Constant alias for string: `"audio/ogg"`. +extern const z_owned_encoding_t ENCODING_AUDIO_OGG; + +// A Vorbis-encoded audio stream. +// +// Constant alias for string: `"audio/vorbis"`. +extern const z_owned_encoding_t ENCODING_AUDIO_VORBIS; + +// A h261-encoded video stream. +// +// Constant alias for string: `"video/h261"`. +extern const z_owned_encoding_t ENCODING_VIDEO_H261; + +// A h263-encoded video stream. +// +// Constant alias for string: `"video/h263"`. +extern const z_owned_encoding_t ENCODING_VIDEO_H263; + +// A h264-encoded video stream. +// +// Constant alias for string: `"video/h264"`. +extern const z_owned_encoding_t ENCODING_VIDEO_H264; + +// A h265-encoded video stream. +// +// Constant alias for string: `"video/h265"`. +extern const z_owned_encoding_t ENCODING_VIDEO_H265; + +// A h266-encoded video stream. +// +// Constant alias for string: `"video/h266"`. +extern const z_owned_encoding_t ENCODING_VIDEO_H266; + +// A video codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. +// +// Constant alias for string: `"video/mp4"`. +extern const z_owned_encoding_t ENCODING_VIDEO_MP4; + +// An Ogg-encapsulated video stream. +// +// Constant alias for string: `"video/ogg"`. +extern const z_owned_encoding_t ENCODING_VIDEO_OGG; + +// An uncompressed, studio-quality video stream. +// +// Constant alias for string: `"video/raw"`. +extern const z_owned_encoding_t ENCODING_VIDEO_RAW; + +// A VP8-encoded video stream. +// +// Constant alias for string: `"video/vp8"`. +extern const z_owned_encoding_t ENCODING_VIDEO_VP8; + +// A VP9-encoded video stream. +// +// Constant alias for string: `"video/vp9"`. +extern const z_owned_encoding_t ENCODING_VIDEO_VP9; +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ZENOH_PICO_API_ENCODING_H */ diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index c10fa8db8..f1f6ae955 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -607,388 +607,6 @@ _Z_OWNED_TYPE_VALUE(_z_closure_zid_t, closure_zid) void z_closure_zid_call(const z_loaned_closure_zid_t *closure, const z_id_t *id); -/** - * Default encoding values used by Zenoh. - * - * An encoding has a similar role to Content-type in HTTP: it indicates, when present, how data should be interpreted by - * the application. - * - * Please note the Zenoh protocol does not impose any encoding value nor it operates on it. - * It can be seen as some optional metadata that is carried over by Zenoh in such a way the application may perform - * different operations depending on the encoding value. - * - * A set of associated constants are provided to cover the most common encodings for user convenience. - * This is particularly useful in helping Zenoh to perform additional wire-level optimizations. - * - * Register your encoding metadata from a string with :c:func:`z_encoding_from_str`. To get the optimization, you need - * Z_FEATURE_ENCODING_VALUES to 1 and your string should follow the format: ";" - * - * E.g: "text/plain;utf8" - * - * Or you can set the value to the constants directly with this list of constants: - */ - -#if Z_FEATURE_ENCODING_VALUES == 1 -// - Below are Primitives types, supported in all Zenoh bindings -// Just some bytes. -// -// Constant alias for string: `"zenoh/bytes"`. -// -// Usually used for types: `uint8_t[]`. -extern const z_owned_encoding_t ENCODING_ZENOH_BYTES; - -// A VLE-encoded signed little-endian 8bit integer. Binary representation uses two's complement. -//// - Primitives types supported in all Zenoh bindings -// Constant alias for string: `"zenoh/int8"`. -// -// Usually used for types: `int8_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_INT8; - -// A VLE-encoded signed little-endian 16bit integer. Binary representation uses two's complement. -// -// Constant alias for string: `"zenoh/int16"`. -// -// Usually used for types: `int16_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_INT16; - -// A VLE-encoded signed little-endian 32bit integer. Binary representation uses two's complement. -// -// Constant alias for string: `"zenoh/int32"`. -// -// Usually used for types: `int32_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_INT32; - -// A VLE-encoded signed little-endian 64bit integer. Binary representation uses two's complement. -// -// Constant alias for string: `"zenoh/int64"`. -// -// Usually used for types: `int64_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_INT64; - -// A VLE-encoded signed little-endian 128bit integer. Binary representation uses two's complement. -// -// Constant alias for string: `"zenoh/int128"`. -extern const z_owned_encoding_t ENCODING_ZENOH_INT128; - -// A VLE-encoded unsigned little-endian 8bit integer. -// -// Constant alias for string: `"zenoh/uint8"`. -// -// Usually used for types: `uint8_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_UINT8; - -// A VLE-encoded unsigned little-endian 16bit integer. -// -// Constant alias for string: `"zenoh/uint16"`. -// -// Usually used for types: `uint16_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_UINT16; -// A VLE-encoded unsigned little-endian 32bit integer. -// -// Constant alias for string: `"zenoh/uint32"`. -// -// Usually used for types: `uint32_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_UINT32; - -// A VLE-encoded unsigned little-endian 64bit integer. -// -// Constant alias for string: `"zenoh/uint64"`. -// -// Usually used for types: `uint64_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_UINT64; - -// A VLE-encoded unsigned little-endian 128bit integer. -// -// Constant alias for string: `"zenoh/uint128"`. -extern const z_owned_encoding_t ENCODING_ZENOH_UINT128; - -// A VLE-encoded 32bit float. Binary representation uses *IEEE 754-2008* *binary32* . -// -// Constant alias for string: `"zenoh/float32"`. -// -// Usually used for types: `float`. -extern const z_owned_encoding_t ENCODING_ZENOH_FLOAT32; - -// A VLE-encoded 64bit float. Binary representation uses *IEEE 754-2008* *binary64*. -// -// Constant alias for string: `"zenoh/float64"`. -// -// Usually used for types: `double`. -extern const z_owned_encoding_t ENCODING_ZENOH_FLOAT64; - -// A boolean. `0` is `false`, `1` is `true`. Other values are invalid. -// -// Constant alias for string: `"zenoh/bool"`. -// -// Usually used for types: `bool`. -extern const z_owned_encoding_t ENCODING_ZENOH_BOOL; - -// A UTF-8 string. -// -// Constant alias for string: `"zenoh/string"`. -// -// Usually used for types: `char[]`. -extern const z_owned_encoding_t ENCODING_ZENOH_STRING; -// A zenoh error. -// -// Constant alias for string: `"zenoh/error"`. -// -// Usually used for types: `z_reply_err_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_ERROR; - -// - Below are Advanced types, may be supported in some of the Zenoh bindings. -// An application-specific stream of bytes. -// -// Constant alias for string: `"application/octet-stream"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_OCTET_STREAM; - -// A textual file. -// -// Constant alias for string: `"text/plain"`. -extern const z_owned_encoding_t ENCODING_TEXT_PLAIN; - -// JSON data intended to be consumed by an application. -// -// Constant alias for string: `"application/json"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JSON; - -// JSON data intended to be human readable. -// -// Constant alias for string: `"text/json"`. -extern const z_owned_encoding_t ENCODING_TEXT_JSON; - -// A Common Data Representation (CDR)-encoded data. -// -// Constant alias for string: `"application/cdr"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_CDR; - -// A Concise Binary Object Representation (CBOR)-encoded data. -// -// Constant alias for string: `"application/cbor"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_CBOR; - -// YAML data intended to be consumed by an application. -// -// Constant alias for string: `"application/yaml"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_YAML; - -// YAML data intended to be human readable. -// -// Constant alias for string: `"text/yaml"`. -extern const z_owned_encoding_t ENCODING_TEXT_YAML; - -// JSON5 encoded data that are human readable. -// -// Constant alias for string: `"text/json5"`. -extern const z_owned_encoding_t ENCODING_TEXT_JSON5; - -// A Python object serialized using [pickle](https://docs.python.org/3/library/pickle.html). -// -// Constant alias for string: `"application/python-serialized-object"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_PYTHON_SERIALIZED_OBJECT; - -// An application-specific protobuf-encoded data. -// -// Constant alias for string: `"application/protobuf"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_PROTOBUF; - -// A Java serialized object. -// -// Constant alias for string: `"application/java-serialized-object"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JAVA_SERIALIZED_OBJECT; - -// An [openmetrics](https://github.com/OpenObservability/OpenMetrics) data, common used by -// [Prometheus](https://prometheus.io/). -// -// Constant alias for string: `"application/openmetrics-text"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_OPENMETRICS_TEXT; - -// A Portable Network Graphics (PNG) image. -// -// Constant alias for string: `"image/png"`. -extern const z_owned_encoding_t ENCODING_IMAGE_PNG; - -// A Joint Photographic Experts Group (JPEG) image. -// -// Constant alias for string: `"image/jpeg"`. -extern const z_owned_encoding_t ENCODING_IMAGE_JPEG; - -// A Graphics Interchange Format (GIF) image. -// -// Constant alias for string: `"image/gif"`. -extern const z_owned_encoding_t ENCODING_IMAGE_GIF; - -// A BitMap (BMP) image. -// -// Constant alias for string: `"image/bmp"`. -extern const z_owned_encoding_t ENCODING_IMAGE_BMP; - -// A Web Portable (WebP) image. -// -// Constant alias for string: `"image/webp"`. -extern const z_owned_encoding_t ENCODING_IMAGE_WEBP; - -// An XML file intended to be consumed by an application.. -// -// Constant alias for string: `"application/xml"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_XML; - -// An encoded a list of tuples, each consisting of a name and a value. -// -// Constant alias for string: `"application/x-www-form-urlencoded"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_X_WWW_FORM_URLENCODED; - -// An HTML file. -// -// Constant alias for string: `"text/html"`. -extern const z_owned_encoding_t ENCODING_TEXT_HTML; - -// An XML file that is human readable. -// -// Constant alias for string: `"text/xml"`. -extern const z_owned_encoding_t ENCODING_TEXT_XML; - -// A CSS file. -// -// Constant alias for string: `"text/css"`. -extern const z_owned_encoding_t ENCODING_TEXT_CSS; - -// A JavaScript file. -// -// Constant alias for string: `"text/javascript"`. -extern const z_owned_encoding_t ENCODING_TEXT_JAVASCRIPT; - -// A MarkDown file. -// -// Constant alias for string: `"text/markdown"`. -extern const z_owned_encoding_t ENCODING_TEXT_MARKDOWN; - -// A CSV file. -// -// Constant alias for string: `"text/csv"`. -extern const z_owned_encoding_t ENCODING_TEXT_CSV; - -// An application-specific SQL query. -// -// Constant alias for string: `"application/sql"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_SQL; - -// Constrained Application Protocol (CoAP) data intended for CoAP-to-HTTP and HTTP-to-CoAP proxies. -// -// Constant alias for string: `"application/coap-payload"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_COAP_PAYLOAD; - -// Defines a JSON document structure for expressing a sequence of operations to apply to a JSON document. -// -// Constant alias for string: `"application/json-patch+json"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_PATCH_JSON; - -// A JSON text sequence consists of any number of JSON texts, all encoded in UTF-8. -// -// Constant alias for string: `"application/json-seq"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_SEQ; - -// A JSONPath defines a string syntax for selecting and extracting JSON values from within a given JSON value. -// -// Constant alias for string: `"application/jsonpath"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JSONPATH; - -// A JSON Web Token (JWT). -// -// Constant alias for string: `"application/jwt"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JWT; - -// An application-specific MPEG-4 encoded data, either audio or video. -// -// Constant alias for string: `"application/mp4"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_MP4; - -// A SOAP 1.2 message serialized as XML 1.0. -// -// Constant alias for string: `"application/soap+xml"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_SOAP_XML; - -// A YANG-encoded data commonly used by the Network Configuration Protocol (NETCONF). -// -// Constant alias for string: `"application/yang"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_YANG; - -// A MPEG-4 Advanced Audio Coding (AAC) media. -// -// Constant alias for string: `"audio/aac"`. -extern const z_owned_encoding_t ENCODING_AUDIO_AAC; - -// A Free Lossless Audio Codec (FLAC) media. -// -// Constant alias for string: `"audio/flac"`. -extern const z_owned_encoding_t ENCODING_AUDIO_FLAC; - -// An audio codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. -// -// Constant alias for string: `"audio/mp4"`. -extern const z_owned_encoding_t ENCODING_AUDIO_MP4; - -// An Ogg-encapsulated audio stream. -// -// Constant alias for string: `"audio/ogg"`. -extern const z_owned_encoding_t ENCODING_AUDIO_OGG; - -// A Vorbis-encoded audio stream. -// -// Constant alias for string: `"audio/vorbis"`. -extern const z_owned_encoding_t ENCODING_AUDIO_VORBIS; - -// A h261-encoded video stream. -// -// Constant alias for string: `"video/h261"`. -extern const z_owned_encoding_t ENCODING_VIDEO_H261; - -// A h263-encoded video stream. -// -// Constant alias for string: `"video/h263"`. -extern const z_owned_encoding_t ENCODING_VIDEO_H263; - -// A h264-encoded video stream. -// -// Constant alias for string: `"video/h264"`. -extern const z_owned_encoding_t ENCODING_VIDEO_H264; - -// A h265-encoded video stream. -// -// Constant alias for string: `"video/h265"`. -extern const z_owned_encoding_t ENCODING_VIDEO_H265; - -// A h266-encoded video stream. -// -// Constant alias for string: `"video/h266"`. -extern const z_owned_encoding_t ENCODING_VIDEO_H266; - -// A video codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. -// -// Constant alias for string: `"video/mp4"`. -extern const z_owned_encoding_t ENCODING_VIDEO_MP4; - -// An Ogg-encapsulated video stream. -// -// Constant alias for string: `"video/ogg"`. -extern const z_owned_encoding_t ENCODING_VIDEO_OGG; - -// An uncompressed, studio-quality video stream. -// -// Constant alias for string: `"video/raw"`. -extern const z_owned_encoding_t ENCODING_VIDEO_RAW; - -// A VP8-encoded video stream. -// -// Constant alias for string: `"video/vp8"`. -extern const z_owned_encoding_t ENCODING_VIDEO_VP8; - -// A VP9-encoded video stream. -// -// Constant alias for string: `"video/vp9"`. -extern const z_owned_encoding_t ENCODING_VIDEO_VP9; -#endif - #ifdef __cplusplus } #endif From 8ee9b040c5cdd967b6aec344134a5c5bb9236c05 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 17 Sep 2024 15:03:10 +0200 Subject: [PATCH 05/16] fix: memory leak --- examples/unix/c11/z_bytes.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/unix/c11/z_bytes.c b/examples/unix/c11/z_bytes.c index 2d8f51a11..28e14fdec 100644 --- a/examples/unix/c11/z_bytes.c +++ b/examples/unix/c11/z_bytes.c @@ -122,11 +122,10 @@ int main(void) { kv_pair_t input_hashmap[1]; input_hashmap[0] = (kv_pair_t){.key = "test_key", .value = "test_value"}; kv_pairs_tx_t ctx = (kv_pairs_tx_t){.data = input_hashmap, .current_idx = 0, .len = 1}; - z_owned_bytes_t hashmap; - z_bytes_from_iter(&hashmap, hashmap_iter, (void *)&ctx); + z_bytes_from_iter(&payload, hashmap_iter, (void *)&ctx); kv_pairs_rx_t output_hashmap = { .current_idx = 0, .len = 16, .data = (kv_pair_decoded_t *)malloc(16 * sizeof(kv_pair_decoded_t))}; - parse_hashmap(&output_hashmap, z_loan(hashmap)); + parse_hashmap(&output_hashmap, z_loan(payload)); assert(strncmp(input_hashmap[0].key, _z_string_data(z_loan(output_hashmap.data[0].key)), strlen(input_hashmap[0].key)) == 0); assert(strncmp(input_hashmap[0].value, _z_string_data(z_loan(output_hashmap.data[0].value)), From f78c444e7d7b7de6af11e3ba8445fe6de4573bbb Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 17 Sep 2024 15:09:51 +0200 Subject: [PATCH 06/16] fix: compilation without encoding constants --- examples/unix/c11/z_bytes.c | 9 ++++----- src/api/api.c | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/unix/c11/z_bytes.c b/examples/unix/c11/z_bytes.c index 28e14fdec..dee10e86f 100644 --- a/examples/unix/c11/z_bytes.c +++ b/examples/unix/c11/z_bytes.c @@ -53,9 +53,8 @@ static void parse_hashmap(kv_pairs_rx_t *kvp, const z_loaned_bytes_t *hashmap); static void drop_hashmap(kv_pairs_rx_t *kvp); int main(void) { + // z_owned_encoding_t encoding; z_owned_bytes_t payload; - z_owned_encoding_t encoding; - (void)encoding; // Number types: uint8, uint16, uint32, uint64, int8, int16, int32, int64, float, double uint32_t input_u32 = 123456; @@ -65,7 +64,7 @@ int main(void) { assert(input_u32 == output_u32); z_drop(z_move(payload)); // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. - encoding = ENCODING_ZENOH_UINT32; + // encoding = ENCODING_ZENOH_UINT32; // String, also work with and z_owned_string_t const char *input_str = "test"; @@ -76,7 +75,7 @@ int main(void) { z_drop(z_move(payload)); z_drop(z_move(output_string)); // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. - encoding = ENCODING_ZENOH_STRING; + // encoding = ENCODING_ZENOH_STRING; // Bytes, also work with z_owned_slice_t const uint8_t input_bytes[] = {1, 2, 3, 4}; @@ -87,7 +86,7 @@ int main(void) { z_drop(z_move(payload)); z_drop(z_move(output_bytes)); // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. - encoding = ENCODING_ZENOH_BYTES; // That's the default value + // encoding = ENCODING_ZENOH_BYTES; // That's the default value // Writer reader uint8_t input_writer[] = {0, 1, 2, 3, 4}; diff --git a/src/api/api.c b/src/api/api.c index 060edfa9c..396becfc4 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -681,11 +681,11 @@ static z_result_t _z_encoding_convert_into_string(const z_loaned_encoding_t *enc #else static z_result_t _z_encoding_convert_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { - return _z_encoding_make(encoding->_val, _Z_ENCODING_ID_DEFAULT, s, len); + return _z_encoding_make(&encoding->_val, _Z_ENCODING_ID_DEFAULT, s, len); } static z_result_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { - _z_string_copy(s->_val, &encoding->schema); + _z_string_copy(&s->_val, &encoding->schema); return _Z_RES_OK; } From 4bb09d567d282c747257a5de87d143b0a67e05d8 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Wed, 18 Sep 2024 10:07:02 +0200 Subject: [PATCH 07/16] refactor: move encoding to a separate file --- src/api/api.c | 524 --------------------------------------------- src/api/encoding.c | 283 ++++++++++++++++++++++++ 2 files changed, 283 insertions(+), 524 deletions(-) create mode 100644 src/api/encoding.c diff --git a/src/api/api.c b/src/api/api.c index 396becfc4..829ce3211 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -214,533 +214,9 @@ z_result_t zp_config_insert(z_loaned_config_t *config, uint8_t key, const char * return _zp_config_insert(config, key, value); } -#if Z_FEATURE_ENCODING_VALUES == 1 -#define ENCODING_SCHEMA_SEPARATOR ';' - -const z_owned_encoding_t ENCODING_ZENOH_BYTES = { - ._val = { - .id = 0, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_INT8 = { - ._val = { - .id = 1, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_INT16 = { - ._val = { - .id = 2, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_INT32 = { - ._val = { - .id = 3, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_INT64 = { - ._val = { - .id = 4, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_INT128 = { - ._val = { - .id = 5, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_UINT8 = { - ._val = { - .id = 6, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_UINT16 = { - ._val = { - .id = 7, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_UINT32 = { - ._val = { - .id = 8, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_UINT64 = { - ._val = { - .id = 9, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_UINT128 = { - ._val = { - .id = 10, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_FLOAT32 = { - ._val = { - .id = 11, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_FLOAT64 = { - ._val = { - .id = 12, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_BOOL = { - ._val = { - .id = 13, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_STRING = { - ._val = { - .id = 14, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_ZENOH_ERROR = { - ._val = { - .id = 15, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_OCTET_STREAM = { - ._val = { - .id = 16, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_TEXT_PLAIN = { - ._val = { - .id = 17, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_JSON = { - ._val = { - .id = 18, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_TEXT_JSON = { - ._val = { - .id = 19, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_CDR = { - ._val = { - .id = 20, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_CBOR = { - ._val = { - .id = 21, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_YAML = { - ._val = { - .id = 22, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_TEXT_YAML = { - ._val = { - .id = 23, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_TEXT_JSON5 = { - ._val = { - .id = 24, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_PYTHON_SERIALIZED_OBJECT = { - ._val = { - .id = 25, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_PROTOBUF = { - ._val = { - .id = 26, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_JAVA_SERIALIZED_OBJECT = { - ._val = { - .id = 27, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_OPENMETRICS_TEXT = { - ._val = { - .id = 28, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_IMAGE_PNG = { - ._val = { - .id = 29, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_IMAGE_JPEG = { - ._val = { - .id = 30, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_IMAGE_GIF = { - ._val = { - .id = 31, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_IMAGE_BMP = { - ._val = { - .id = 32, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_IMAGE_WEBP = { - ._val = { - .id = 33, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_XML = { - ._val = { - .id = 34, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_X_WWW_FORM_URLENCODED = { - ._val = { - .id = 35, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_TEXT_HTML = { - ._val = { - .id = 36, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_TEXT_XML = { - ._val = { - .id = 37, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_TEXT_CSS = { - ._val = { - .id = 38, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_TEXT_JAVASCRIPT = { - ._val = { - .id = 39, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_TEXT_MARKDOWN = { - ._val = { - .id = 40, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_TEXT_CSV = { - ._val = { - .id = 41, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_SQL = { - ._val = { - .id = 42, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_COAP_PAYLOAD = { - ._val = { - .id = 43, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_JSON_PATCH_JSON = { - ._val = { - .id = 44, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_JSON_SEQ = { - ._val = { - .id = 45, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_JSONPATH = { - ._val = { - .id = 46, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_JWT = { - ._val = { - .id = 47, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_MP4 = { - ._val = { - .id = 48, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_SOAP_XML = { - ._val = { - .id = 49, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_APPLICATION_YANG = { - ._val = { - .id = 50, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_AUDIO_AAC = { - ._val = { - .id = 51, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_AUDIO_FLAC = { - ._val = { - .id = 52, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_AUDIO_MP4 = { - ._val = { - .id = 53, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_AUDIO_OGG = { - ._val = { - .id = 54, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_AUDIO_VORBIS = { - ._val = { - .id = 55, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_VIDEO_H261 = { - ._val = { - .id = 56, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_VIDEO_H263 = { - ._val = { - .id = 57, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_VIDEO_H264 = { - ._val = { - .id = 58, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_VIDEO_H265 = { - ._val = { - .id = 59, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_VIDEO_H266 = { - ._val = { - .id = 60, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_VIDEO_MP4 = { - ._val = { - .id = 61, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_VIDEO_OGG = { - ._val = { - .id = 62, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_VIDEO_RAW = { - ._val = { - .id = 63, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_VIDEO_VP8 = { - ._val = { - .id = 64, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; -const z_owned_encoding_t ENCODING_VIDEO_VP9 = { - ._val = { - .id = 65, - .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, - }}; - -const char *ENCODING_VALUES_ID_TO_STR[] = { - "zenoh/bytes", - "zenoh/int8", - "zenoh/int16", - "zenoh/int32", - "zenoh/int64", - "zenoh/int128", - "zenoh/uint8", - "zenoh/uint16", - "zenoh/uint32", - "zenoh/uint64", - "zenoh/uint128", - "zenoh/float32", - "zenoh/float64", - "zenoh/bool", - "zenoh/string", - "zenoh/error", - "application/octet-stream", - "text/plain", - "application/json", - "text/json", - "application/cdr", - "application/cbor", - "application/yaml", - "text/yaml", - "text/json5", - "application/python-serialized-object", - "application/protobuf", - "application/java-serialized-object", - "application/openmetrics-text", - "image/png", - "image/jpeg", - "image/gif", - "image/bmp", - "image/webp", - "application/xml", - "application/x-www-form-urlencoded", - "text/html", - "text/xml", - "text/css", - "text/javascript", - "text/markdown", - "text/csv", - "application/sql", - "application/coap-payload", - "application/json-patch+json", - "application/json-seq", - "application/jsonpath", - "application/jwt", - "application/mp4", - "application/soap+xml", - "application/yang", - "audio/aac", - "audio/flac", - "audio/mp4", - "audio/ogg", - "audio/vorbis", - "video/h261", - "video/h263", - "video/h264", - "video/h265", - "video/h266", - "video/mp4", - "video/ogg", - "video/raw", - "video/vp8", - "video/vp9", -}; - -static uint16_t _z_encoding_values_str_to_int(const char *schema, size_t len) { - for (size_t i = 0; i < _ZP_ARRAY_SIZE(ENCODING_VALUES_ID_TO_STR); i++) { - if (strncmp(schema, ENCODING_VALUES_ID_TO_STR[i], len) == 0) { - return (uint16_t)i; - } - } - return UINT16_MAX; -} - -static z_result_t _z_encoding_convert_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { - size_t pos = 0; - for (; pos < len; ++pos) { - if (s[pos] == ENCODING_SCHEMA_SEPARATOR) break; - } - - // Check id_end value + corner cases - if ((pos != len) && (pos != 0)) { - uint16_t id = _z_encoding_values_str_to_int(s, pos); - // Check id - if (id != UINT16_MAX) { - const char *ptr = (pos + 1 == len) ? NULL : s + pos + 1; - return _z_encoding_make(&encoding->_val, id, ptr, len - pos - 1); - } - } - // By default store the string as schema - return _z_encoding_make(&encoding->_val, _Z_ENCODING_ID_DEFAULT, s, len); -} - -static z_result_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { - const char *prefix = NULL; - size_t prefix_len = 0; - // Convert id - if (encoding->id < _ZP_ARRAY_SIZE(ENCODING_VALUES_ID_TO_STR)) { - prefix = ENCODING_VALUES_ID_TO_STR[encoding->id]; - prefix_len = strlen(prefix); - } - bool has_schema = _z_string_len(&encoding->schema) > 0; - // Size include null terminator - size_t total_len = prefix_len + _z_string_len(&encoding->schema) + 1; - // Check for schema separator - if (has_schema) { - total_len += 1; - } - // Allocate string - char *value = (char *)z_malloc(sizeof(char) * total_len); - memset(value, 0, total_len); - if (value == NULL) { - return _Z_ERR_SYSTEM_OUT_OF_MEMORY; - } - // Copy prefix - char sep = ENCODING_SCHEMA_SEPARATOR; - (void)strncpy(value, prefix, prefix_len); - // Copy schema and separator - if (has_schema) { - (void)strncat(value, &sep, 1); - (void)strncat(value, _z_string_data(&encoding->schema), _z_string_len(&encoding->schema)); - } - // Fill container - s->_val = _z_string_from_str_custom_deleter(value, _z_delete_context_default()); - return _Z_RES_OK; -} - -#else -static z_result_t _z_encoding_convert_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { - return _z_encoding_make(&encoding->_val, _Z_ENCODING_ID_DEFAULT, s, len); -} - -static z_result_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { - _z_string_copy(&s->_val, &encoding->schema); - return _Z_RES_OK; -} - -#endif - _Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_encoding_t, encoding, _z_encoding_check, _z_encoding_null, _z_encoding_copy, _z_encoding_clear) -z_result_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s) { - // Init owned encoding - z_internal_encoding_null(encoding); - // Convert string to encoding - if (s != NULL) { - return _z_encoding_convert_from_substr(encoding, s, strlen(s)); - } - return _Z_RES_OK; -} - -z_result_t z_encoding_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { - // Init owned encoding - z_internal_encoding_null(encoding); - // Convert string to encoding - if (s != NULL) { - return _z_encoding_convert_from_substr(encoding, s, len); - } - return _Z_RES_OK; -} -z_result_t z_encoding_set_schema_from_str(z_loaned_encoding_t *encoding, const char *schema) { - return z_encoding_set_schema_from_substr(encoding, schema, strlen(schema)); -} - -z_result_t z_encoding_set_schema_from_substr(z_loaned_encoding_t *encoding, const char *schema, size_t len) { - _z_string_clear(&encoding->schema); - if (schema == NULL && len > 0) { - return _Z_ERR_INVALID; - } - encoding->schema = _z_string_copy_from_substr(schema, len); - if (_z_string_len(&encoding->schema) != len) { - return _Z_ERR_SYSTEM_OUT_OF_MEMORY; - } - return _Z_RES_OK; -} - -z_result_t z_encoding_to_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { - // Init owned string - z_internal_string_null(s); - // Convert encoding to string - _z_encoding_convert_into_string(encoding, s); - return _Z_RES_OK; -} - -bool z_encoding_equals(const z_loaned_encoding_t *left, const z_loaned_encoding_t *right) { - return left->id == right->id && _z_string_equals(&left->schema, &right->schema); -} - z_result_t z_slice_copy_from_buf(z_owned_slice_t *slice, const uint8_t *data, size_t len) { slice->_val = _z_slice_copy_from_buf(data, len); if (slice->_val.start == NULL) { diff --git a/src/api/encoding.c b/src/api/encoding.c new file mode 100644 index 000000000..15e3a6c22 --- /dev/null +++ b/src/api/encoding.c @@ -0,0 +1,283 @@ +// +// Copyright (c) 2024 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// BÅ‚ażej Sowa, + +#include +#include +#include +#include +#include + +#include "zenoh-pico.h" + +#if Z_FEATURE_ENCODING_VALUES == 1 +#define ENCODING_SCHEMA_SEPARATOR ';' + +#define ENCODING_CONSTANT_MACRO(_name, _id) \ + const z_owned_encoding_t _name = { \ + ._val = { \ + .id = _id, \ + .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, \ + }} + +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_BYTES, 0); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_INT8, 1); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_INT16, 2); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_INT32, 3); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_INT64, 4); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_INT128, 5); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_UINT8, 6); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_UINT16, 7); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_UINT32, 8); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_UINT64, 9); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_UINT128, 10); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_FLOAT32, 11); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_FLOAT64, 12); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_BOOL, 13); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_STRING, 14); +ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_ERROR, 15); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_OCTET_STREAM, 16); +ENCODING_CONSTANT_MACRO(ENCODING_TEXT_PLAIN, 17); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JSON, 18); +ENCODING_CONSTANT_MACRO(ENCODING_TEXT_JSON, 19); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_CDR, 20); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_CBOR, 21); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_YAML, 22); +ENCODING_CONSTANT_MACRO(ENCODING_TEXT_YAML, 23); +ENCODING_CONSTANT_MACRO(ENCODING_TEXT_JSON5, 24); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_PYTHON_SERIALIZED_OBJECT, 25); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_PROTOBUF, 26); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JAVA_SERIALIZED_OBJECT, 27); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_OPENMETRICS_TEXT, 28); +ENCODING_CONSTANT_MACRO(ENCODING_IMAGE_PNG, 29); +ENCODING_CONSTANT_MACRO(ENCODING_IMAGE_JPEG, 30); +ENCODING_CONSTANT_MACRO(ENCODING_IMAGE_GIF, 31); +ENCODING_CONSTANT_MACRO(ENCODING_IMAGE_BMP, 32); +ENCODING_CONSTANT_MACRO(ENCODING_IMAGE_WEBP, 33); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_XML, 34); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_X_WWW_FORM_URLENCODED, 35); +ENCODING_CONSTANT_MACRO(ENCODING_TEXT_HTML, 36); +ENCODING_CONSTANT_MACRO(ENCODING_TEXT_XML, 37); +ENCODING_CONSTANT_MACRO(ENCODING_TEXT_CSS, 38); +ENCODING_CONSTANT_MACRO(ENCODING_TEXT_JAVASCRIPT, 39); +ENCODING_CONSTANT_MACRO(ENCODING_TEXT_MARKDOWN, 40); +ENCODING_CONSTANT_MACRO(ENCODING_TEXT_CSV, 41); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_SQL, 42); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_COAP_PAYLOAD, 43); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JSON_PATCH_JSON, 44); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JSON_SEQ, 45); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JSONPATH, 46); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JWT, 47); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_MP4, 48); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_SOAP_XML, 49); +ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_YANG, 50); +ENCODING_CONSTANT_MACRO(ENCODING_AUDIO_AAC, 51); +ENCODING_CONSTANT_MACRO(ENCODING_AUDIO_FLAC, 52); +ENCODING_CONSTANT_MACRO(ENCODING_AUDIO_MP4, 53); +ENCODING_CONSTANT_MACRO(ENCODING_AUDIO_OGG, 54); +ENCODING_CONSTANT_MACRO(ENCODING_AUDIO_VORBIS, 55); +ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_H261, 56); +ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_H263, 57); +ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_H264, 58); +ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_H265, 59); +ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_H266, 60); +ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_MP4, 61); +ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_OGG, 62); +ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_RAW, 63); +ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_VP8, 64); +ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_VP9, 65); + +const char *ENCODING_VALUES_ID_TO_STR[] = { + "zenoh/bytes", + "zenoh/int8", + "zenoh/int16", + "zenoh/int32", + "zenoh/int64", + "zenoh/int128", + "zenoh/uint8", + "zenoh/uint16", + "zenoh/uint32", + "zenoh/uint64", + "zenoh/uint128", + "zenoh/float32", + "zenoh/float64", + "zenoh/bool", + "zenoh/string", + "zenoh/error", + "application/octet-stream", + "text/plain", + "application/json", + "text/json", + "application/cdr", + "application/cbor", + "application/yaml", + "text/yaml", + "text/json5", + "application/python-serialized-object", + "application/protobuf", + "application/java-serialized-object", + "application/openmetrics-text", + "image/png", + "image/jpeg", + "image/gif", + "image/bmp", + "image/webp", + "application/xml", + "application/x-www-form-urlencoded", + "text/html", + "text/xml", + "text/css", + "text/javascript", + "text/markdown", + "text/csv", + "application/sql", + "application/coap-payload", + "application/json-patch+json", + "application/json-seq", + "application/jsonpath", + "application/jwt", + "application/mp4", + "application/soap+xml", + "application/yang", + "audio/aac", + "audio/flac", + "audio/mp4", + "audio/ogg", + "audio/vorbis", + "video/h261", + "video/h263", + "video/h264", + "video/h265", + "video/h266", + "video/mp4", + "video/ogg", + "video/raw", + "video/vp8", + "video/vp9", +}; + +static uint16_t _z_encoding_values_str_to_int(const char *schema, size_t len) { + for (size_t i = 0; i < _ZP_ARRAY_SIZE(ENCODING_VALUES_ID_TO_STR); i++) { + if (strncmp(schema, ENCODING_VALUES_ID_TO_STR[i], len) == 0) { + return (uint16_t)i; + } + } + return UINT16_MAX; +} + +static z_result_t _z_encoding_convert_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { + size_t pos = 0; + for (; pos < len; ++pos) { + if (s[pos] == ENCODING_SCHEMA_SEPARATOR) break; + } + + // Check id_end value + corner cases + if ((pos != len) && (pos != 0)) { + uint16_t id = _z_encoding_values_str_to_int(s, pos); + // Check id + if (id != UINT16_MAX) { + const char *ptr = (pos + 1 == len) ? NULL : s + pos + 1; + return _z_encoding_make(&encoding->_val, id, ptr, len - pos - 1); + } + } + // By default store the string as schema + return _z_encoding_make(&encoding->_val, _Z_ENCODING_ID_DEFAULT, s, len); +} + +static z_result_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { + const char *prefix = NULL; + size_t prefix_len = 0; + // Convert id + if (encoding->id < _ZP_ARRAY_SIZE(ENCODING_VALUES_ID_TO_STR)) { + prefix = ENCODING_VALUES_ID_TO_STR[encoding->id]; + prefix_len = strlen(prefix); + } + _Bool has_schema = _z_string_len(&encoding->schema) > 0; + // Size include null terminator + size_t total_len = prefix_len + _z_string_len(&encoding->schema) + 1; + // Check for schema separator + if (has_schema) { + total_len += 1; + } + // Allocate string + char *value = (char *)z_malloc(sizeof(char) * total_len); + memset(value, 0, total_len); + if (value == NULL) { + return _Z_ERR_SYSTEM_OUT_OF_MEMORY; + } + // Copy prefix + char sep = ENCODING_SCHEMA_SEPARATOR; + (void)strncpy(value, prefix, prefix_len); + // Copy schema and separator + if (has_schema) { + (void)strncat(value, &sep, 1); + (void)strncat(value, _z_string_data(&encoding->schema), _z_string_len(&encoding->schema)); + } + // Fill container + s->_val = _z_string_from_str_custom_deleter(value, _z_delete_context_default()); + return _Z_RES_OK; +} + +#else +static z_result_t _z_encoding_convert_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { + return _z_encoding_make(&encoding->_val, _Z_ENCODING_ID_DEFAULT, s, len); +} + +static z_result_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { + _z_string_copy(&s->_val, &encoding->schema); + return _Z_RES_OK; +} +#endif + +z_result_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s) { + // Init owned encoding + z_internal_encoding_null(encoding); + // Convert string to encoding + if (s != NULL) { + return _z_encoding_convert_from_substr(encoding, s, strlen(s)); + } + return _Z_RES_OK; +} + +z_result_t z_encoding_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { + // Init owned encoding + z_internal_encoding_null(encoding); + // Convert string to encoding + if (s != NULL) { + return _z_encoding_convert_from_substr(encoding, s, len); + } + return _Z_RES_OK; +} +z_result_t z_encoding_set_schema_from_str(z_loaned_encoding_t *encoding, const char *schema) { + return z_encoding_set_schema_from_substr(encoding, schema, strlen(schema)); +} + +z_result_t z_encoding_set_schema_from_substr(z_loaned_encoding_t *encoding, const char *schema, size_t len) { + _z_string_clear(&encoding->schema); + if (schema == NULL && len > 0) { + return _Z_ERR_INVALID; + } + encoding->schema = _z_string_copy_from_substr(schema, len); + if (_z_string_len(&encoding->schema) != len) { + return _Z_ERR_SYSTEM_OUT_OF_MEMORY; + } + return _Z_RES_OK; +} + +z_result_t z_encoding_to_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { + // Init owned string + z_internal_string_null(s); + // Convert encoding to string + _z_encoding_convert_into_string(encoding, s); + return _Z_RES_OK; +} From 02d6936fc36b5c9e283fc2bab2edf9ef8150b708 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Wed, 18 Sep 2024 16:20:09 +0200 Subject: [PATCH 08/16] feat: add zenoh-c encoding functions --- examples/unix/c11/z_bytes.c | 6 +- include/zenoh-pico/api/encoding.h | 98 +++++++++++++++++---- src/api/encoding.c | 139 +++++++++++++++--------------- 3 files changed, 155 insertions(+), 88 deletions(-) diff --git a/examples/unix/c11/z_bytes.c b/examples/unix/c11/z_bytes.c index dee10e86f..05f570e63 100644 --- a/examples/unix/c11/z_bytes.c +++ b/examples/unix/c11/z_bytes.c @@ -64,7 +64,7 @@ int main(void) { assert(input_u32 == output_u32); z_drop(z_move(payload)); // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. - // encoding = ENCODING_ZENOH_UINT32; + // encoding = ZP_ENCODING_ZENOH_UINT32; // String, also work with and z_owned_string_t const char *input_str = "test"; @@ -75,7 +75,7 @@ int main(void) { z_drop(z_move(payload)); z_drop(z_move(output_string)); // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. - // encoding = ENCODING_ZENOH_STRING; + // encoding = ZP_ENCODING_ZENOH_STRING; // Bytes, also work with z_owned_slice_t const uint8_t input_bytes[] = {1, 2, 3, 4}; @@ -86,7 +86,7 @@ int main(void) { z_drop(z_move(payload)); z_drop(z_move(output_bytes)); // Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc. - // encoding = ENCODING_ZENOH_BYTES; // That's the default value + // encoding = ZP_ENCODING_ZENOH_BYTES; // That's the default value // Writer reader uint8_t input_writer[] = {0, 1, 2, 3, 4}; diff --git a/include/zenoh-pico/api/encoding.h b/include/zenoh-pico/api/encoding.h index fdfb0b1b8..1270191b3 100644 --- a/include/zenoh-pico/api/encoding.h +++ b/include/zenoh-pico/api/encoding.h @@ -47,358 +47,424 @@ extern "C" { // Constant alias for string: `"zenoh/bytes"`. // // Usually used for types: `uint8_t[]`. -extern const z_owned_encoding_t ENCODING_ZENOH_BYTES; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_BYTES; +const z_loaned_encoding_t *z_encoding_zenoh_bytes(void); // A VLE-encoded signed little-endian 8bit integer. Binary representation uses two's complement. //// - Primitives types supported in all Zenoh bindings // Constant alias for string: `"zenoh/int8"`. // // Usually used for types: `int8_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_INT8; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT8; +const z_loaned_encoding_t *z_encoding_zenoh_int8(void); // A VLE-encoded signed little-endian 16bit integer. Binary representation uses two's complement. // // Constant alias for string: `"zenoh/int16"`. // // Usually used for types: `int16_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_INT16; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT16; +const z_loaned_encoding_t *z_encoding_zenoh_int16(void); // A VLE-encoded signed little-endian 32bit integer. Binary representation uses two's complement. // // Constant alias for string: `"zenoh/int32"`. // // Usually used for types: `int32_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_INT32; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT32; +const z_loaned_encoding_t *z_encoding_zenoh_int32(void); // A VLE-encoded signed little-endian 64bit integer. Binary representation uses two's complement. // // Constant alias for string: `"zenoh/int64"`. // // Usually used for types: `int64_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_INT64; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT64; +const z_loaned_encoding_t *z_encoding_zenoh_int64(void); // A VLE-encoded signed little-endian 128bit integer. Binary representation uses two's complement. // // Constant alias for string: `"zenoh/int128"`. -extern const z_owned_encoding_t ENCODING_ZENOH_INT128; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT128; +const z_loaned_encoding_t *z_encoding_zenoh_int128(void); // A VLE-encoded unsigned little-endian 8bit integer. // // Constant alias for string: `"zenoh/uint8"`. // // Usually used for types: `uint8_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_UINT8; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT8; +const z_loaned_encoding_t *z_encoding_zenoh_uint8(void); // A VLE-encoded unsigned little-endian 16bit integer. // // Constant alias for string: `"zenoh/uint16"`. // // Usually used for types: `uint16_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_UINT16; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT16; +const z_loaned_encoding_t *z_encoding_zenoh_uint16(void); // A VLE-encoded unsigned little-endian 32bit integer. // // Constant alias for string: `"zenoh/uint32"`. // // Usually used for types: `uint32_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_UINT32; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT32; +const z_loaned_encoding_t *z_encoding_zenoh_uint32(void); // A VLE-encoded unsigned little-endian 64bit integer. // // Constant alias for string: `"zenoh/uint64"`. // // Usually used for types: `uint64_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_UINT64; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT64; +const z_loaned_encoding_t *z_encoding_zenoh_uint64(void); // A VLE-encoded unsigned little-endian 128bit integer. // // Constant alias for string: `"zenoh/uint128"`. -extern const z_owned_encoding_t ENCODING_ZENOH_UINT128; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT128; +const z_loaned_encoding_t *z_encoding_zenoh_uint128(void); // A VLE-encoded 32bit float. Binary representation uses *IEEE 754-2008* *binary32* . // // Constant alias for string: `"zenoh/float32"`. // // Usually used for types: `float`. -extern const z_owned_encoding_t ENCODING_ZENOH_FLOAT32; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_FLOAT32; +const z_loaned_encoding_t *z_encoding_zenoh_float32(void); // A VLE-encoded 64bit float. Binary representation uses *IEEE 754-2008* *binary64*. // // Constant alias for string: `"zenoh/float64"`. // // Usually used for types: `double`. -extern const z_owned_encoding_t ENCODING_ZENOH_FLOAT64; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_FLOAT64; +const z_loaned_encoding_t *z_encoding_zenoh_float64(void); // A boolean. `0` is `false`, `1` is `true`. Other values are invalid. // // Constant alias for string: `"zenoh/bool"`. // // Usually used for types: `bool`. -extern const z_owned_encoding_t ENCODING_ZENOH_BOOL; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_BOOL; +const z_loaned_encoding_t *z_encoding_zenoh_bool(void); // A UTF-8 string. // // Constant alias for string: `"zenoh/string"`. // // Usually used for types: `char[]`. -extern const z_owned_encoding_t ENCODING_ZENOH_STRING; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_STRING; +const z_loaned_encoding_t *z_encoding_zenoh_string(void); // A zenoh error. // // Constant alias for string: `"zenoh/error"`. // // Usually used for types: `z_reply_err_t`. -extern const z_owned_encoding_t ENCODING_ZENOH_ERROR; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_ERROR; +const z_loaned_encoding_t *z_encoding_zenoh_error(void); // - Below are Advanced types, may be supported in some of the Zenoh bindings. // An application-specific stream of bytes. // // Constant alias for string: `"application/octet-stream"`. extern const z_owned_encoding_t ENCODING_APPLICATION_OCTET_STREAM; +const z_loaned_encoding_t *z_encoding_application_octet_stream(void); // A textual file. // // Constant alias for string: `"text/plain"`. extern const z_owned_encoding_t ENCODING_TEXT_PLAIN; +const z_loaned_encoding_t *z_encoding_text_plain(void); // JSON data intended to be consumed by an application. // // Constant alias for string: `"application/json"`. extern const z_owned_encoding_t ENCODING_APPLICATION_JSON; +const z_loaned_encoding_t *z_encoding_application_json(void); // JSON data intended to be human readable. // // Constant alias for string: `"text/json"`. extern const z_owned_encoding_t ENCODING_TEXT_JSON; +const z_loaned_encoding_t *z_encoding_text_json(void); // A Common Data Representation (CDR)-encoded data. // // Constant alias for string: `"application/cdr"`. extern const z_owned_encoding_t ENCODING_APPLICATION_CDR; +const z_loaned_encoding_t *z_encoding_application_cdr(void); // A Concise Binary Object Representation (CBOR)-encoded data. // // Constant alias for string: `"application/cbor"`. extern const z_owned_encoding_t ENCODING_APPLICATION_CBOR; +const z_loaned_encoding_t *z_encoding_application_cbor(void); // YAML data intended to be consumed by an application. // // Constant alias for string: `"application/yaml"`. extern const z_owned_encoding_t ENCODING_APPLICATION_YAML; +const z_loaned_encoding_t *z_encoding_application_yaml(void); // YAML data intended to be human readable. // // Constant alias for string: `"text/yaml"`. extern const z_owned_encoding_t ENCODING_TEXT_YAML; +const z_loaned_encoding_t *z_encoding_text_yaml(void); // JSON5 encoded data that are human readable. // // Constant alias for string: `"text/json5"`. extern const z_owned_encoding_t ENCODING_TEXT_JSON5; +const z_loaned_encoding_t *z_encoding_text_json5(void); // A Python object serialized using [pickle](https://docs.python.org/3/library/pickle.html). // // Constant alias for string: `"application/python-serialized-object"`. extern const z_owned_encoding_t ENCODING_APPLICATION_PYTHON_SERIALIZED_OBJECT; +const z_loaned_encoding_t *z_encoding_application_python_serialized_object(void); // An application-specific protobuf-encoded data. // // Constant alias for string: `"application/protobuf"`. extern const z_owned_encoding_t ENCODING_APPLICATION_PROTOBUF; +const z_loaned_encoding_t *z_encoding_application_protobuf(void); // A Java serialized object. // // Constant alias for string: `"application/java-serialized-object"`. extern const z_owned_encoding_t ENCODING_APPLICATION_JAVA_SERIALIZED_OBJECT; +const z_loaned_encoding_t *z_encoding_application_java_serialized_object(void); // An [openmetrics](https://github.com/OpenObservability/OpenMetrics) data, common used by // [Prometheus](https://prometheus.io/). // // Constant alias for string: `"application/openmetrics-text"`. extern const z_owned_encoding_t ENCODING_APPLICATION_OPENMETRICS_TEXT; +const z_loaned_encoding_t *z_encoding_application_openmetrics_text(void); // A Portable Network Graphics (PNG) image. // // Constant alias for string: `"image/png"`. extern const z_owned_encoding_t ENCODING_IMAGE_PNG; +const z_loaned_encoding_t *z_encoding_image_png(void); // A Joint Photographic Experts Group (JPEG) image. // // Constant alias for string: `"image/jpeg"`. extern const z_owned_encoding_t ENCODING_IMAGE_JPEG; +const z_loaned_encoding_t *z_encoding_image_jpeg(void); // A Graphics Interchange Format (GIF) image. // // Constant alias for string: `"image/gif"`. extern const z_owned_encoding_t ENCODING_IMAGE_GIF; +const z_loaned_encoding_t *z_encoding_image_gif(void); // A BitMap (BMP) image. // // Constant alias for string: `"image/bmp"`. extern const z_owned_encoding_t ENCODING_IMAGE_BMP; +const z_loaned_encoding_t *z_encoding_image_bmp(void); // A Web Portable (WebP) image. // // Constant alias for string: `"image/webp"`. extern const z_owned_encoding_t ENCODING_IMAGE_WEBP; +const z_loaned_encoding_t *z_encoding_image_webp(void); // An XML file intended to be consumed by an application.. // // Constant alias for string: `"application/xml"`. extern const z_owned_encoding_t ENCODING_APPLICATION_XML; +const z_loaned_encoding_t *z_encoding_application_xml(void); // An encoded a list of tuples, each consisting of a name and a value. // // Constant alias for string: `"application/x-www-form-urlencoded"`. extern const z_owned_encoding_t ENCODING_APPLICATION_X_WWW_FORM_URLENCODED; +const z_loaned_encoding_t *z_encoding_application_x_www_form_urlencoded(void); // An HTML file. // // Constant alias for string: `"text/html"`. extern const z_owned_encoding_t ENCODING_TEXT_HTML; +const z_loaned_encoding_t *z_encoding_text_html(void); // An XML file that is human readable. // // Constant alias for string: `"text/xml"`. extern const z_owned_encoding_t ENCODING_TEXT_XML; +const z_loaned_encoding_t *z_encoding_text_xml(void); // A CSS file. // // Constant alias for string: `"text/css"`. extern const z_owned_encoding_t ENCODING_TEXT_CSS; +const z_loaned_encoding_t *z_encoding_text_css(void); // A JavaScript file. // // Constant alias for string: `"text/javascript"`. extern const z_owned_encoding_t ENCODING_TEXT_JAVASCRIPT; +const z_loaned_encoding_t *z_encoding_text_javascript(void); // A MarkDown file. // // Constant alias for string: `"text/markdown"`. extern const z_owned_encoding_t ENCODING_TEXT_MARKDOWN; +const z_loaned_encoding_t *z_encoding_text_markdown(void); // A CSV file. // // Constant alias for string: `"text/csv"`. extern const z_owned_encoding_t ENCODING_TEXT_CSV; +const z_loaned_encoding_t *z_encoding_text_csv(void); // An application-specific SQL query. // // Constant alias for string: `"application/sql"`. extern const z_owned_encoding_t ENCODING_APPLICATION_SQL; +const z_loaned_encoding_t *z_encoding_application_sql(void); // Constrained Application Protocol (CoAP) data intended for CoAP-to-HTTP and HTTP-to-CoAP proxies. // // Constant alias for string: `"application/coap-payload"`. extern const z_owned_encoding_t ENCODING_APPLICATION_COAP_PAYLOAD; +const z_loaned_encoding_t *z_encoding_application_coap_payload(void); // Defines a JSON document structure for expressing a sequence of operations to apply to a JSON document. // // Constant alias for string: `"application/json-patch+json"`. extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_PATCH_JSON; +const z_loaned_encoding_t *z_encoding_application_json_patch_json(void); // A JSON text sequence consists of any number of JSON texts, all encoded in UTF-8. // // Constant alias for string: `"application/json-seq"`. extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_SEQ; +const z_loaned_encoding_t *z_encoding_application_json_seq(void); // A JSONPath defines a string syntax for selecting and extracting JSON values from within a given JSON value. // // Constant alias for string: `"application/jsonpath"`. extern const z_owned_encoding_t ENCODING_APPLICATION_JSONPATH; +const z_loaned_encoding_t *z_encoding_application_jsonpath(void); // A JSON Web Token (JWT). // // Constant alias for string: `"application/jwt"`. extern const z_owned_encoding_t ENCODING_APPLICATION_JWT; +const z_loaned_encoding_t *z_encoding_application_jwt(void); // An application-specific MPEG-4 encoded data, either audio or video. // // Constant alias for string: `"application/mp4"`. extern const z_owned_encoding_t ENCODING_APPLICATION_MP4; +const z_loaned_encoding_t *z_encoding_application_mp4(void); // A SOAP 1.2 message serialized as XML 1.0. // // Constant alias for string: `"application/soap+xml"`. extern const z_owned_encoding_t ENCODING_APPLICATION_SOAP_XML; +const z_loaned_encoding_t *z_encoding_application_soap_xml(void); // A YANG-encoded data commonly used by the Network Configuration Protocol (NETCONF). // // Constant alias for string: `"application/yang"`. extern const z_owned_encoding_t ENCODING_APPLICATION_YANG; +const z_loaned_encoding_t *z_encoding_application_yang(void); // A MPEG-4 Advanced Audio Coding (AAC) media. // // Constant alias for string: `"audio/aac"`. extern const z_owned_encoding_t ENCODING_AUDIO_AAC; +const z_loaned_encoding_t *z_encoding_audio_aac(void); // A Free Lossless Audio Codec (FLAC) media. // // Constant alias for string: `"audio/flac"`. extern const z_owned_encoding_t ENCODING_AUDIO_FLAC; +const z_loaned_encoding_t *z_encoding_audio_flac(void); // An audio codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. // // Constant alias for string: `"audio/mp4"`. extern const z_owned_encoding_t ENCODING_AUDIO_MP4; +const z_loaned_encoding_t *z_encoding_audio_mp4(void); // An Ogg-encapsulated audio stream. // // Constant alias for string: `"audio/ogg"`. extern const z_owned_encoding_t ENCODING_AUDIO_OGG; +const z_loaned_encoding_t *z_encoding_audio_ogg(void); // A Vorbis-encoded audio stream. // // Constant alias for string: `"audio/vorbis"`. extern const z_owned_encoding_t ENCODING_AUDIO_VORBIS; +const z_loaned_encoding_t *z_encoding_audio_vorbis(void); // A h261-encoded video stream. // // Constant alias for string: `"video/h261"`. extern const z_owned_encoding_t ENCODING_VIDEO_H261; +const z_loaned_encoding_t *z_encoding_video_h261(void); // A h263-encoded video stream. // // Constant alias for string: `"video/h263"`. extern const z_owned_encoding_t ENCODING_VIDEO_H263; +const z_loaned_encoding_t *z_encoding_video_h263(void); // A h264-encoded video stream. // // Constant alias for string: `"video/h264"`. extern const z_owned_encoding_t ENCODING_VIDEO_H264; +const z_loaned_encoding_t *z_encoding_video_h264(void); // A h265-encoded video stream. // // Constant alias for string: `"video/h265"`. extern const z_owned_encoding_t ENCODING_VIDEO_H265; +const z_loaned_encoding_t *z_encoding_video_h265(void); // A h266-encoded video stream. // // Constant alias for string: `"video/h266"`. extern const z_owned_encoding_t ENCODING_VIDEO_H266; +const z_loaned_encoding_t *z_encoding_video_h266(void); // A video codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. // // Constant alias for string: `"video/mp4"`. extern const z_owned_encoding_t ENCODING_VIDEO_MP4; +const z_loaned_encoding_t *z_encoding_video_mp4(void); // An Ogg-encapsulated video stream. // // Constant alias for string: `"video/ogg"`. extern const z_owned_encoding_t ENCODING_VIDEO_OGG; +const z_loaned_encoding_t *z_encoding_video_ogg(void); // An uncompressed, studio-quality video stream. // // Constant alias for string: `"video/raw"`. extern const z_owned_encoding_t ENCODING_VIDEO_RAW; +const z_loaned_encoding_t *z_encoding_video_raw(void); // A VP8-encoded video stream. // // Constant alias for string: `"video/vp8"`. extern const z_owned_encoding_t ENCODING_VIDEO_VP8; +const z_loaned_encoding_t *z_encoding_video_vp8(void); // A VP9-encoded video stream. // // Constant alias for string: `"video/vp9"`. extern const z_owned_encoding_t ENCODING_VIDEO_VP9; +const z_loaned_encoding_t *z_encoding_video_vp9(void); #endif #ifdef __cplusplus diff --git a/src/api/encoding.c b/src/api/encoding.c index 15e3a6c22..cf21bf035 100644 --- a/src/api/encoding.c +++ b/src/api/encoding.c @@ -23,79 +23,80 @@ #if Z_FEATURE_ENCODING_VALUES == 1 #define ENCODING_SCHEMA_SEPARATOR ';' -#define ENCODING_CONSTANT_MACRO(_name, _id) \ - const z_owned_encoding_t _name = { \ +#define ENCODING_CONSTANT_MACRO(_cname, _fname, _id) \ + const z_owned_encoding_t ZP_ENCODING_##_cname = { \ ._val = { \ .id = _id, \ .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, \ - }} + }}; \ + const z_loaned_encoding_t *z_encoding_##_fname(void) { return &ZP_ENCODING_##_cname._val; } -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_BYTES, 0); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_INT8, 1); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_INT16, 2); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_INT32, 3); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_INT64, 4); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_INT128, 5); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_UINT8, 6); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_UINT16, 7); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_UINT32, 8); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_UINT64, 9); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_UINT128, 10); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_FLOAT32, 11); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_FLOAT64, 12); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_BOOL, 13); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_STRING, 14); -ENCODING_CONSTANT_MACRO(ENCODING_ZENOH_ERROR, 15); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_OCTET_STREAM, 16); -ENCODING_CONSTANT_MACRO(ENCODING_TEXT_PLAIN, 17); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JSON, 18); -ENCODING_CONSTANT_MACRO(ENCODING_TEXT_JSON, 19); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_CDR, 20); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_CBOR, 21); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_YAML, 22); -ENCODING_CONSTANT_MACRO(ENCODING_TEXT_YAML, 23); -ENCODING_CONSTANT_MACRO(ENCODING_TEXT_JSON5, 24); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_PYTHON_SERIALIZED_OBJECT, 25); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_PROTOBUF, 26); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JAVA_SERIALIZED_OBJECT, 27); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_OPENMETRICS_TEXT, 28); -ENCODING_CONSTANT_MACRO(ENCODING_IMAGE_PNG, 29); -ENCODING_CONSTANT_MACRO(ENCODING_IMAGE_JPEG, 30); -ENCODING_CONSTANT_MACRO(ENCODING_IMAGE_GIF, 31); -ENCODING_CONSTANT_MACRO(ENCODING_IMAGE_BMP, 32); -ENCODING_CONSTANT_MACRO(ENCODING_IMAGE_WEBP, 33); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_XML, 34); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_X_WWW_FORM_URLENCODED, 35); -ENCODING_CONSTANT_MACRO(ENCODING_TEXT_HTML, 36); -ENCODING_CONSTANT_MACRO(ENCODING_TEXT_XML, 37); -ENCODING_CONSTANT_MACRO(ENCODING_TEXT_CSS, 38); -ENCODING_CONSTANT_MACRO(ENCODING_TEXT_JAVASCRIPT, 39); -ENCODING_CONSTANT_MACRO(ENCODING_TEXT_MARKDOWN, 40); -ENCODING_CONSTANT_MACRO(ENCODING_TEXT_CSV, 41); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_SQL, 42); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_COAP_PAYLOAD, 43); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JSON_PATCH_JSON, 44); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JSON_SEQ, 45); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JSONPATH, 46); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_JWT, 47); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_MP4, 48); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_SOAP_XML, 49); -ENCODING_CONSTANT_MACRO(ENCODING_APPLICATION_YANG, 50); -ENCODING_CONSTANT_MACRO(ENCODING_AUDIO_AAC, 51); -ENCODING_CONSTANT_MACRO(ENCODING_AUDIO_FLAC, 52); -ENCODING_CONSTANT_MACRO(ENCODING_AUDIO_MP4, 53); -ENCODING_CONSTANT_MACRO(ENCODING_AUDIO_OGG, 54); -ENCODING_CONSTANT_MACRO(ENCODING_AUDIO_VORBIS, 55); -ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_H261, 56); -ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_H263, 57); -ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_H264, 58); -ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_H265, 59); -ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_H266, 60); -ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_MP4, 61); -ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_OGG, 62); -ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_RAW, 63); -ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_VP8, 64); -ENCODING_CONSTANT_MACRO(ENCODING_VIDEO_VP9, 65); +ENCODING_CONSTANT_MACRO(ZENOH_BYTES, zenoh_bytes, 0) +ENCODING_CONSTANT_MACRO(ZENOH_INT8, zenoh_int8, 1) +ENCODING_CONSTANT_MACRO(ZENOH_INT16, zenoh_int16, 2) +ENCODING_CONSTANT_MACRO(ZENOH_INT32, zenoh_int32, 3) +ENCODING_CONSTANT_MACRO(ZENOH_INT64, zenoh_int64, 4) +ENCODING_CONSTANT_MACRO(ZENOH_INT128, zenoh_int128, 5) +ENCODING_CONSTANT_MACRO(ZENOH_UINT8, zenoh_uint8, 6) +ENCODING_CONSTANT_MACRO(ZENOH_UINT16, zenoh_uint16, 7) +ENCODING_CONSTANT_MACRO(ZENOH_UINT32, zenoh_uint32, 8) +ENCODING_CONSTANT_MACRO(ZENOH_UINT64, zenoh_uint64, 9) +ENCODING_CONSTANT_MACRO(ZENOH_UINT128, zenoh_uint128, 10) +ENCODING_CONSTANT_MACRO(ZENOH_FLOAT32, zenoh_float32, 11) +ENCODING_CONSTANT_MACRO(ZENOH_FLOAT64, zenoh_float64, 12) +ENCODING_CONSTANT_MACRO(ZENOH_BOOL, zenoh_bool, 13) +ENCODING_CONSTANT_MACRO(ZENOH_STRING, zenoh_string, 14) +ENCODING_CONSTANT_MACRO(ZENOH_ERROR, zenoh_error, 15) +ENCODING_CONSTANT_MACRO(APPLICATION_OCTET_STREAM, application_octet_stream, 16) +ENCODING_CONSTANT_MACRO(TEXT_PLAIN, text_plain, 17) +ENCODING_CONSTANT_MACRO(APPLICATION_JSON, application_json, 18) +ENCODING_CONSTANT_MACRO(TEXT_JSON, text_json, 19) +ENCODING_CONSTANT_MACRO(APPLICATION_CDR, application_cdr, 20) +ENCODING_CONSTANT_MACRO(APPLICATION_CBOR, application_cbor, 21) +ENCODING_CONSTANT_MACRO(APPLICATION_YAML, application_yaml, 22) +ENCODING_CONSTANT_MACRO(TEXT_YAML, text_yaml, 23) +ENCODING_CONSTANT_MACRO(TEXT_JSON5, text_json5, 24) +ENCODING_CONSTANT_MACRO(APPLICATION_PYTHON_SERIALIZED_OBJECT, application_python_serialized_object, 25) +ENCODING_CONSTANT_MACRO(APPLICATION_PROTOBUF, application_protobuf, 26) +ENCODING_CONSTANT_MACRO(APPLICATION_JAVA_SERIALIZED_OBJECT, application_java_serialized_object, 27) +ENCODING_CONSTANT_MACRO(APPLICATION_OPENMETRICS_TEXT, application_openmetrics_text, 28) +ENCODING_CONSTANT_MACRO(IMAGE_PNG, image_png, 29) +ENCODING_CONSTANT_MACRO(IMAGE_JPEG, image_jpeg, 30) +ENCODING_CONSTANT_MACRO(IMAGE_GIF, image_gif, 31) +ENCODING_CONSTANT_MACRO(IMAGE_BMP, image_bmp, 32) +ENCODING_CONSTANT_MACRO(IMAGE_WEBP, image_webp, 33) +ENCODING_CONSTANT_MACRO(APPLICATION_XML, application_xml, 34) +ENCODING_CONSTANT_MACRO(APPLICATION_X_WWW_FORM_URLENCODED, application_x_www_form_urlencoded, 35) +ENCODING_CONSTANT_MACRO(TEXT_HTML, text_html, 36) +ENCODING_CONSTANT_MACRO(TEXT_XML, text_xml, 37) +ENCODING_CONSTANT_MACRO(TEXT_CSS, text_css, 38) +ENCODING_CONSTANT_MACRO(TEXT_JAVASCRIPT, text_javascript, 39) +ENCODING_CONSTANT_MACRO(TEXT_MARKDOWN, text_markdown, 40) +ENCODING_CONSTANT_MACRO(TEXT_CSV, text_csv, 41) +ENCODING_CONSTANT_MACRO(APPLICATION_SQL, application_sql, 42) +ENCODING_CONSTANT_MACRO(APPLICATION_COAP_PAYLOAD, application_coap_payload, 43) +ENCODING_CONSTANT_MACRO(APPLICATION_JSON_PATCH_JSON, application_json_patch_json, 44) +ENCODING_CONSTANT_MACRO(APPLICATION_JSON_SEQ, application_json_seq, 45) +ENCODING_CONSTANT_MACRO(APPLICATION_JSONPATH, application_jsonpath, 46) +ENCODING_CONSTANT_MACRO(APPLICATION_JWT, application_jwt, 47) +ENCODING_CONSTANT_MACRO(APPLICATION_MP4, application_mp4, 48) +ENCODING_CONSTANT_MACRO(APPLICATION_SOAP_XML, application_soap_xml, 49) +ENCODING_CONSTANT_MACRO(APPLICATION_YANG, application_yang, 50) +ENCODING_CONSTANT_MACRO(AUDIO_AAC, audio_aac, 51) +ENCODING_CONSTANT_MACRO(AUDIO_FLAC, audio_flac, 52) +ENCODING_CONSTANT_MACRO(AUDIO_MP4, audio_mp4, 53) +ENCODING_CONSTANT_MACRO(AUDIO_OGG, audio_ogg, 54) +ENCODING_CONSTANT_MACRO(AUDIO_VORBIS, audio_vorbis, 55) +ENCODING_CONSTANT_MACRO(VIDEO_H261, video_h261, 56) +ENCODING_CONSTANT_MACRO(VIDEO_H263, video_h263, 57) +ENCODING_CONSTANT_MACRO(VIDEO_H264, video_h264, 58) +ENCODING_CONSTANT_MACRO(VIDEO_H265, video_h265, 59) +ENCODING_CONSTANT_MACRO(VIDEO_H266, video_h266, 60) +ENCODING_CONSTANT_MACRO(VIDEO_MP4, video_mp4, 61) +ENCODING_CONSTANT_MACRO(VIDEO_OGG, video_ogg, 62) +ENCODING_CONSTANT_MACRO(VIDEO_RAW, video_raw, 63) +ENCODING_CONSTANT_MACRO(VIDEO_VP8, video_vp8, 64) +ENCODING_CONSTANT_MACRO(VIDEO_VP9, video_vp9, 65) const char *ENCODING_VALUES_ID_TO_STR[] = { "zenoh/bytes", From 5a46325af1940e5e24e4988fa7e208b285187b92 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 19 Sep 2024 10:45:32 +0200 Subject: [PATCH 09/16] fix: define encoding func as inline --- src/api/encoding.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/encoding.c b/src/api/encoding.c index cf21bf035..b5cb4dc54 100644 --- a/src/api/encoding.c +++ b/src/api/encoding.c @@ -29,7 +29,7 @@ .id = _id, \ .schema = {._slice = {.start = NULL, .len = 0, ._delete_context = {.deleter = NULL, .context = NULL}}}, \ }}; \ - const z_loaned_encoding_t *z_encoding_##_fname(void) { return &ZP_ENCODING_##_cname._val; } + inline const z_loaned_encoding_t *z_encoding_##_fname(void) { return &ZP_ENCODING_##_cname._val; } ENCODING_CONSTANT_MACRO(ZENOH_BYTES, zenoh_bytes, 0) ENCODING_CONSTANT_MACRO(ZENOH_INT8, zenoh_int8, 1) From b1d1df25321d8e2808fc00e52d80a4172229dc17 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 19 Sep 2024 14:16:37 +0200 Subject: [PATCH 10/16] doc: add encoding constant functions --- docs/api.rst | 66 +++++++++++++++++++++++++++++++ include/zenoh-pico/api/encoding.h | 1 - 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/docs/api.rst b/docs/api.rst index 1d9b5a097..5221617e6 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -459,3 +459,69 @@ Primitives .. autocfunction:: primitives.h::zp_send_keep_alive .. autocfunction:: primitives.h::zp_send_join_options_default .. autocfunction:: primitives.h::zp_send_join +.. autocfunction:: encoding.h::z_encoding_zenoh_bytes +.. autocfunction:: encoding.h::z_encoding_zenoh_int8 +.. autocfunction:: encoding.h::z_encoding_zenoh_int16 +.. autocfunction:: encoding.h::z_encoding_zenoh_int32 +.. autocfunction:: encoding.h::z_encoding_zenoh_int64 +.. autocfunction:: encoding.h::z_encoding_zenoh_int128 +.. autocfunction:: encoding.h::z_encoding_zenoh_uint8 +.. autocfunction:: encoding.h::z_encoding_zenoh_uint16 +.. autocfunction:: encoding.h::z_encoding_zenoh_uint32 +.. autocfunction:: encoding.h::z_encoding_zenoh_uint64 +.. autocfunction:: encoding.h::z_encoding_zenoh_uint128 +.. autocfunction:: encoding.h::z_encoding_zenoh_float32 +.. autocfunction:: encoding.h::z_encoding_zenoh_float64 +.. autocfunction:: encoding.h::z_encoding_zenoh_bool +.. autocfunction:: encoding.h::z_encoding_zenoh_string +.. autocfunction:: encoding.h::z_encoding_zenoh_error +.. autocfunction:: encoding.h::z_encoding_application_octet_stream +.. autocfunction:: encoding.h::z_encoding_text_plain +.. autocfunction:: encoding.h::z_encoding_application_json +.. autocfunction:: encoding.h::z_encoding_text_json +.. autocfunction:: encoding.h::z_encoding_application_cdr +.. autocfunction:: encoding.h::z_encoding_application_cbor +.. autocfunction:: encoding.h::z_encoding_application_yaml +.. autocfunction:: encoding.h::z_encoding_text_yaml +.. autocfunction:: encoding.h::z_encoding_text_json5 +.. autocfunction:: encoding.h::z_encoding_application_python_serialized_object +.. autocfunction:: encoding.h::z_encoding_application_protobuf +.. autocfunction:: encoding.h::z_encoding_application_java_serialized_object +.. autocfunction:: encoding.h::z_encoding_application_openmetrics_text +.. autocfunction:: encoding.h::z_encoding_image_png +.. autocfunction:: encoding.h::z_encoding_image_jpeg +.. autocfunction:: encoding.h::z_encoding_image_gif +.. autocfunction:: encoding.h::z_encoding_image_bmp +.. autocfunction:: encoding.h::z_encoding_image_webp +.. autocfunction:: encoding.h::z_encoding_application_xml +.. autocfunction:: encoding.h::z_encoding_application_x_www_form_urlencoded +.. autocfunction:: encoding.h::z_encoding_text_html +.. autocfunction:: encoding.h::z_encoding_text_xml +.. autocfunction:: encoding.h::z_encoding_text_css +.. autocfunction:: encoding.h::z_encoding_text_javascript +.. autocfunction:: encoding.h::z_encoding_text_markdown +.. autocfunction:: encoding.h::z_encoding_text_csv +.. autocfunction:: encoding.h::z_encoding_application_sql +.. autocfunction:: encoding.h::z_encoding_application_coap_payload +.. autocfunction:: encoding.h::z_encoding_application_json_patch_json +.. autocfunction:: encoding.h::z_encoding_application_json_seq +.. autocfunction:: encoding.h::z_encoding_application_jsonpath +.. autocfunction:: encoding.h::z_encoding_application_jwt +.. autocfunction:: encoding.h::z_encoding_application_mp4 +.. autocfunction:: encoding.h::z_encoding_application_soap_xml +.. autocfunction:: encoding.h::z_encoding_application_yang +.. autocfunction:: encoding.h::z_encoding_audio_aac +.. autocfunction:: encoding.h::z_encoding_audio_flac +.. autocfunction:: encoding.h::z_encoding_audio_mp4 +.. autocfunction:: encoding.h::z_encoding_audio_ogg +.. autocfunction:: encoding.h::z_encoding_audio_vorbis +.. autocfunction:: encoding.h::z_encoding_video_h261 +.. autocfunction:: encoding.h::z_encoding_video_h263 +.. autocfunction:: encoding.h::z_encoding_video_h264 +.. autocfunction:: encoding.h::z_encoding_video_h265 +.. autocfunction:: encoding.h::z_encoding_video_h266 +.. autocfunction:: encoding.h::z_encoding_video_mp4 +.. autocfunction:: encoding.h::z_encoding_video_ogg +.. autocfunction:: encoding.h::z_encoding_video_raw +.. autocfunction:: encoding.h::z_encoding_video_vp8 +.. autocfunction:: encoding.h::z_encoding_video_vp9 diff --git a/include/zenoh-pico/api/encoding.h b/include/zenoh-pico/api/encoding.h index 1270191b3..c0d89c2fb 100644 --- a/include/zenoh-pico/api/encoding.h +++ b/include/zenoh-pico/api/encoding.h @@ -51,7 +51,6 @@ extern const z_owned_encoding_t ZP_ENCODING_ZENOH_BYTES; const z_loaned_encoding_t *z_encoding_zenoh_bytes(void); // A VLE-encoded signed little-endian 8bit integer. Binary representation uses two's complement. -//// - Primitives types supported in all Zenoh bindings // Constant alias for string: `"zenoh/int8"`. // // Usually used for types: `int8_t`. From 9922d2648b93d396e947ff423925b0af316f9a30 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 19 Sep 2024 14:41:34 +0200 Subject: [PATCH 11/16] fix: Wconversion issue --- src/system/unix/system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system/unix/system.c b/src/system/unix/system.c index e05205117..2049fba30 100644 --- a/src/system/unix/system.c +++ b/src/system/unix/system.c @@ -160,7 +160,7 @@ z_result_t z_sleep_ms(size_t time) { return _Z_RES_OK; } -z_result_t z_sleep_s(size_t time) { _Z_CHECK_SYS_ERR(sleep((unsigned int)time)); } +z_result_t z_sleep_s(size_t time) { _Z_CHECK_SYS_ERR((int)sleep((unsigned int)time)); } /*------------------ Instant ------------------*/ z_clock_t z_clock_now(void) { From 5ee13f353cba5c134f87421391e7da71453b1d46 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 19 Sep 2024 14:41:53 +0200 Subject: [PATCH 12/16] feat: add slice iterator example --- examples/unix/c11/z_bytes.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/unix/c11/z_bytes.c b/examples/unix/c11/z_bytes.c index 05f570e63..59aa2aba7 100644 --- a/examples/unix/c11/z_bytes.c +++ b/examples/unix/c11/z_bytes.c @@ -100,7 +100,7 @@ int main(void) { assert(0 == memcmp(input_writer, output_reader, sizeof(output_reader))); z_drop(z_move(payload)); - // Iterator + // Bytes iterator uint8_t result_iter[] = {0, 1, 2, 3, 4}; uint8_t output_iter[5] = {0}; uint8_t context = 0; @@ -131,6 +131,21 @@ int main(void) { strlen(input_hashmap[0].value)) == 0); z_drop(z_move(payload)); drop_hashmap(&output_hashmap); + + // Slice iterator + kv_pair_t input_val[1]; + input_val[0] = (kv_pair_t){.key = "test_key", .value = "test_value"}; + ctx = (kv_pairs_tx_t){.data = input_val, .current_idx = 0, .len = 1}; + z_bytes_from_iter(&payload, hashmap_iter, (void *)&ctx); + z_bytes_slice_iterator_t slice_iter = z_bytes_get_slice_iterator(z_bytes_loan(&payload)); + z_view_slice_t curr_slice; + while (z_bytes_slice_iterator_next(&slice_iter, &curr_slice)) { + printf("slice len: %d, slice data: '%.*s'\n", (int)z_slice_len(z_view_slice_loan(&curr_slice)), + (int)z_slice_len(z_view_slice_loan(&curr_slice)), + (const char *)z_slice_data(z_view_slice_loan(&curr_slice))); + } + z_drop(z_move(payload)); + return 0; } From 1c93a866fc06a7fcb8454b155038863a194112fd Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 19 Sep 2024 15:04:19 +0200 Subject: [PATCH 13/16] doc: fix encoding function comment --- include/zenoh-pico/api/encoding.h | 656 +++++++++++++++++------------- 1 file changed, 363 insertions(+), 293 deletions(-) diff --git a/include/zenoh-pico/api/encoding.h b/include/zenoh-pico/api/encoding.h index c0d89c2fb..0e46f4f46 100644 --- a/include/zenoh-pico/api/encoding.h +++ b/include/zenoh-pico/api/encoding.h @@ -42,428 +42,498 @@ extern "C" { #if Z_FEATURE_ENCODING_VALUES == 1 // - Below are Primitives types, supported in all Zenoh bindings -// Just some bytes. -// -// Constant alias for string: `"zenoh/bytes"`. -// -// Usually used for types: `uint8_t[]`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_BYTES; +/** + * Just some bytes. + * + * Constant alias for string: `"zenoh/bytes"`. + * + * Usually used for types: `uint8_t[]`. + */ const z_loaned_encoding_t *z_encoding_zenoh_bytes(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_BYTES; -// A VLE-encoded signed little-endian 8bit integer. Binary representation uses two's complement. -// Constant alias for string: `"zenoh/int8"`. -// -// Usually used for types: `int8_t`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT8; +/** + * A VLE-encoded signed little-endian 8bit integer. Binary representation uses two's complement. + * Constant alias for string: `"zenoh/int8"`. + * + * Usually used for types: `int8_t`. + */ const z_loaned_encoding_t *z_encoding_zenoh_int8(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT8; -// A VLE-encoded signed little-endian 16bit integer. Binary representation uses two's complement. -// -// Constant alias for string: `"zenoh/int16"`. -// -// Usually used for types: `int16_t`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT16; +/** + * A VLE-encoded signed little-endian 16bit integer. Binary representation uses two's complement. + * Constant alias for string: `"zenoh/int16"`. + * + * Usually used for types: `int16_t`. + */ const z_loaned_encoding_t *z_encoding_zenoh_int16(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT16; -// A VLE-encoded signed little-endian 32bit integer. Binary representation uses two's complement. -// -// Constant alias for string: `"zenoh/int32"`. -// -// Usually used for types: `int32_t`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT32; +/** + * A VLE-encoded signed little-endian 32bit integer. Binary representation uses two's complement. + * Constant alias for string: `"zenoh/int32"`. + * + * Usually used for types: `int32_t`. + */ const z_loaned_encoding_t *z_encoding_zenoh_int32(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT32; -// A VLE-encoded signed little-endian 64bit integer. Binary representation uses two's complement. -// -// Constant alias for string: `"zenoh/int64"`. -// -// Usually used for types: `int64_t`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT64; +/** + * A VLE-encoded signed little-endian 64bit integer. Binary representation uses two's complement. + * Constant alias for string: `"zenoh/int64"`. + * + * Usually used for types: `int64_t`. + */ const z_loaned_encoding_t *z_encoding_zenoh_int64(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT64; -// A VLE-encoded signed little-endian 128bit integer. Binary representation uses two's complement. -// -// Constant alias for string: `"zenoh/int128"`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT128; +/** + * A VLE-encoded signed little-endian 128bit integer. Binary representation uses two's complement. + * Constant alias for string: `"zenoh/int128"`. + */ const z_loaned_encoding_t *z_encoding_zenoh_int128(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_INT128; -// A VLE-encoded unsigned little-endian 8bit integer. -// -// Constant alias for string: `"zenoh/uint8"`. -// -// Usually used for types: `uint8_t`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT8; +/** + * A VLE-encoded unsigned little-endian 8bit integer. + * Constant alias for string: `"zenoh/uint8"`. + * + * Usually used for types: `uint8_t`. + */ const z_loaned_encoding_t *z_encoding_zenoh_uint8(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT8; -// A VLE-encoded unsigned little-endian 16bit integer. -// -// Constant alias for string: `"zenoh/uint16"`. -// -// Usually used for types: `uint16_t`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT16; +/** + * A VLE-encoded unsigned little-endian 16bit integer. + * Constant alias for string: `"zenoh/uint16"`. + * + * Usually used for types: `uint16_t`. + */ const z_loaned_encoding_t *z_encoding_zenoh_uint16(void); -// A VLE-encoded unsigned little-endian 32bit integer. -// -// Constant alias for string: `"zenoh/uint32"`. -// -// Usually used for types: `uint32_t`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT32; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT16; + +/** + * A VLE-encoded unsigned little-endian 32bit integer. + * Constant alias for string: `"zenoh/uint32"`. + * + * Usually used for types: `uint32_t`. + */ const z_loaned_encoding_t *z_encoding_zenoh_uint32(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT32; -// A VLE-encoded unsigned little-endian 64bit integer. -// -// Constant alias for string: `"zenoh/uint64"`. -// -// Usually used for types: `uint64_t`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT64; +/** + * A VLE-encoded unsigned little-endian 64bit integer. + * Constant alias for string: `"zenoh/uint64"`. + * + * Usually used for types: `uint64_t`. + */ const z_loaned_encoding_t *z_encoding_zenoh_uint64(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT64; -// A VLE-encoded unsigned little-endian 128bit integer. -// -// Constant alias for string: `"zenoh/uint128"`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT128; +/** + * A VLE-encoded unsigned little-endian 128bit integer. + * Constant alias for string: `"zenoh/uint128"`. + */ const z_loaned_encoding_t *z_encoding_zenoh_uint128(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_UINT128; -// A VLE-encoded 32bit float. Binary representation uses *IEEE 754-2008* *binary32* . -// -// Constant alias for string: `"zenoh/float32"`. -// -// Usually used for types: `float`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_FLOAT32; +/** + * A VLE-encoded 32bit float. Binary representation uses *IEEE 754-2008* *binary32*. + * Constant alias for string: `"zenoh/float32"`. + * + * Usually used for types: `float`. + */ const z_loaned_encoding_t *z_encoding_zenoh_float32(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_FLOAT32; -// A VLE-encoded 64bit float. Binary representation uses *IEEE 754-2008* *binary64*. -// -// Constant alias for string: `"zenoh/float64"`. -// -// Usually used for types: `double`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_FLOAT64; +/** + * A VLE-encoded 64bit float. Binary representation uses *IEEE 754-2008* *binary64*. + * Constant alias for string: `"zenoh/float64"`. + * + * Usually used for types: `double`. + */ const z_loaned_encoding_t *z_encoding_zenoh_float64(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_FLOAT64; -// A boolean. `0` is `false`, `1` is `true`. Other values are invalid. -// -// Constant alias for string: `"zenoh/bool"`. -// -// Usually used for types: `bool`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_BOOL; +/** + * A boolean. `0` is `false`, `1` is `true`. Other values are invalid. + * Constant alias for string: `"zenoh/bool"`. + * + * Usually used for types: `bool`. + */ const z_loaned_encoding_t *z_encoding_zenoh_bool(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_BOOL; -// A UTF-8 string. -// -// Constant alias for string: `"zenoh/string"`. -// -// Usually used for types: `char[]`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_STRING; +/** + * A UTF-8 string. + * Constant alias for string: `"zenoh/string"`. + * + * Usually used for types: `char[]`. + */ const z_loaned_encoding_t *z_encoding_zenoh_string(void); -// A zenoh error. -// -// Constant alias for string: `"zenoh/error"`. -// -// Usually used for types: `z_reply_err_t`. -extern const z_owned_encoding_t ZP_ENCODING_ZENOH_ERROR; +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_STRING; + +/** + * A zenoh error. + * Constant alias for string: `"zenoh/error"`. + * + * Usually used for types: `z_reply_err_t`. + */ const z_loaned_encoding_t *z_encoding_zenoh_error(void); +extern const z_owned_encoding_t ZP_ENCODING_ZENOH_ERROR; -// - Below are Advanced types, may be supported in some of the Zenoh bindings. -// An application-specific stream of bytes. -// -// Constant alias for string: `"application/octet-stream"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_OCTET_STREAM; +/** + * An application-specific stream of bytes. + * Constant alias for string: `"application/octet-stream"`. + */ const z_loaned_encoding_t *z_encoding_application_octet_stream(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_OCTET_STREAM; -// A textual file. -// -// Constant alias for string: `"text/plain"`. -extern const z_owned_encoding_t ENCODING_TEXT_PLAIN; +/** + * A textual file. + * Constant alias for string: `"text/plain"`. + */ const z_loaned_encoding_t *z_encoding_text_plain(void); +extern const z_owned_encoding_t ENCODING_TEXT_PLAIN; -// JSON data intended to be consumed by an application. -// -// Constant alias for string: `"application/json"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JSON; +/** + * JSON data intended to be consumed by an application. + * Constant alias for string: `"application/json"`. + */ const z_loaned_encoding_t *z_encoding_application_json(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_JSON; -// JSON data intended to be human readable. -// -// Constant alias for string: `"text/json"`. -extern const z_owned_encoding_t ENCODING_TEXT_JSON; +/** + * JSON data intended to be human readable. + * Constant alias for string: `"text/json"`. + */ const z_loaned_encoding_t *z_encoding_text_json(void); +extern const z_owned_encoding_t ENCODING_TEXT_JSON; -// A Common Data Representation (CDR)-encoded data. -// -// Constant alias for string: `"application/cdr"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_CDR; +/** + * A Common Data Representation (CDR)-encoded data. + * Constant alias for string: `"application/cdr"`. + */ const z_loaned_encoding_t *z_encoding_application_cdr(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_CDR; -// A Concise Binary Object Representation (CBOR)-encoded data. -// -// Constant alias for string: `"application/cbor"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_CBOR; +/** + * A Concise Binary Object Representation (CBOR)-encoded data. + * Constant alias for string: `"application/cbor"`. + */ const z_loaned_encoding_t *z_encoding_application_cbor(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_CBOR; -// YAML data intended to be consumed by an application. -// -// Constant alias for string: `"application/yaml"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_YAML; +/** + * YAML data intended to be consumed by an application. + * Constant alias for string: `"application/yaml"`. + */ const z_loaned_encoding_t *z_encoding_application_yaml(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_YAML; -// YAML data intended to be human readable. -// -// Constant alias for string: `"text/yaml"`. -extern const z_owned_encoding_t ENCODING_TEXT_YAML; +/** + * YAML data intended to be human readable. + * Constant alias for string: `"text/yaml"`. + */ const z_loaned_encoding_t *z_encoding_text_yaml(void); +extern const z_owned_encoding_t ENCODING_TEXT_YAML; -// JSON5 encoded data that are human readable. -// -// Constant alias for string: `"text/json5"`. -extern const z_owned_encoding_t ENCODING_TEXT_JSON5; +/** + * JSON5 encoded data that are human readable. + * Constant alias for string: `"text/json5"`. + */ const z_loaned_encoding_t *z_encoding_text_json5(void); +extern const z_owned_encoding_t ENCODING_TEXT_JSON5; -// A Python object serialized using [pickle](https://docs.python.org/3/library/pickle.html). -// -// Constant alias for string: `"application/python-serialized-object"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_PYTHON_SERIALIZED_OBJECT; +/** + * A Python object serialized using [pickle](https://docs.python.org/3/library/pickle.html). + * Constant alias for string: `"application/python-serialized-object"`. + */ const z_loaned_encoding_t *z_encoding_application_python_serialized_object(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_PYTHON_SERIALIZED_OBJECT; -// An application-specific protobuf-encoded data. -// -// Constant alias for string: `"application/protobuf"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_PROTOBUF; +/** + * An application-specific protobuf-encoded data. + * Constant alias for string: `"application/protobuf"`. + */ const z_loaned_encoding_t *z_encoding_application_protobuf(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_PROTOBUF; -// A Java serialized object. -// -// Constant alias for string: `"application/java-serialized-object"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JAVA_SERIALIZED_OBJECT; +/** + * A Java serialized object. + * Constant alias for string: `"application/java-serialized-object"`. + */ const z_loaned_encoding_t *z_encoding_application_java_serialized_object(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_JAVA_SERIALIZED_OBJECT; -// An [openmetrics](https://github.com/OpenObservability/OpenMetrics) data, common used by -// [Prometheus](https://prometheus.io/). -// -// Constant alias for string: `"application/openmetrics-text"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_OPENMETRICS_TEXT; +/** + * An [openmetrics](https://github.com/OpenObservability/OpenMetrics) data, commonly used by + * [Prometheus](https://prometheus.io/). + * Constant alias for string: `"application/openmetrics-text"`. + */ const z_loaned_encoding_t *z_encoding_application_openmetrics_text(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_OPENMETRICS_TEXT; -// A Portable Network Graphics (PNG) image. -// -// Constant alias for string: `"image/png"`. -extern const z_owned_encoding_t ENCODING_IMAGE_PNG; +/** + * A Portable Network Graphics (PNG) image. + * Constant alias for string: `"image/png"`. + */ const z_loaned_encoding_t *z_encoding_image_png(void); +extern const z_owned_encoding_t ENCODING_IMAGE_PNG; -// A Joint Photographic Experts Group (JPEG) image. -// -// Constant alias for string: `"image/jpeg"`. -extern const z_owned_encoding_t ENCODING_IMAGE_JPEG; +/** + * A Joint Photographic Experts Group (JPEG) image. + * Constant alias for string: `"image/jpeg"`. + */ const z_loaned_encoding_t *z_encoding_image_jpeg(void); +extern const z_owned_encoding_t ENCODING_IMAGE_JPEG; -// A Graphics Interchange Format (GIF) image. -// -// Constant alias for string: `"image/gif"`. -extern const z_owned_encoding_t ENCODING_IMAGE_GIF; +/** + * A Graphics Interchange Format (GIF) image. + * Constant alias for string: `"image/gif"`. + */ const z_loaned_encoding_t *z_encoding_image_gif(void); +extern const z_owned_encoding_t ENCODING_IMAGE_GIF; -// A BitMap (BMP) image. -// -// Constant alias for string: `"image/bmp"`. -extern const z_owned_encoding_t ENCODING_IMAGE_BMP; +/** + * A BitMap (BMP) image. + * Constant alias for string: `"image/bmp"`. + */ const z_loaned_encoding_t *z_encoding_image_bmp(void); +extern const z_owned_encoding_t ENCODING_IMAGE_BMP; -// A Web Portable (WebP) image. -// -// Constant alias for string: `"image/webp"`. -extern const z_owned_encoding_t ENCODING_IMAGE_WEBP; +/** + * A Web Portable (WebP) image. + * Constant alias for string: `"image/webp"`. + */ const z_loaned_encoding_t *z_encoding_image_webp(void); +extern const z_owned_encoding_t ENCODING_IMAGE_WEBP; -// An XML file intended to be consumed by an application.. -// -// Constant alias for string: `"application/xml"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_XML; +/** + * An XML file intended to be consumed by an application. + * Constant alias for string: `"application/xml"`. + */ const z_loaned_encoding_t *z_encoding_application_xml(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_XML; -// An encoded a list of tuples, each consisting of a name and a value. -// -// Constant alias for string: `"application/x-www-form-urlencoded"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_X_WWW_FORM_URLENCODED; +/** + * An encoded list of tuples, each consisting of a name and a value. + * Constant alias for string: `"application/x-www-form-urlencoded"`. + */ const z_loaned_encoding_t *z_encoding_application_x_www_form_urlencoded(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_X_WWW_FORM_URLENCODED; -// An HTML file. -// -// Constant alias for string: `"text/html"`. -extern const z_owned_encoding_t ENCODING_TEXT_HTML; +/** + * An HTML file. + * Constant alias for string: `"text/html"`. + */ const z_loaned_encoding_t *z_encoding_text_html(void); +extern const z_owned_encoding_t ENCODING_TEXT_HTML; -// An XML file that is human readable. -// -// Constant alias for string: `"text/xml"`. -extern const z_owned_encoding_t ENCODING_TEXT_XML; +/** + * An XML file that is human-readable. + * Constant alias for string: `"text/xml"`. + */ const z_loaned_encoding_t *z_encoding_text_xml(void); +extern const z_owned_encoding_t ENCODING_TEXT_XML; -// A CSS file. -// -// Constant alias for string: `"text/css"`. -extern const z_owned_encoding_t ENCODING_TEXT_CSS; +/** + * A CSS file. + * Constant alias for string: `"text/css"`. + */ const z_loaned_encoding_t *z_encoding_text_css(void); +extern const z_owned_encoding_t ENCODING_TEXT_CSS; -// A JavaScript file. -// -// Constant alias for string: `"text/javascript"`. -extern const z_owned_encoding_t ENCODING_TEXT_JAVASCRIPT; +/** + * A JavaScript file. + * Constant alias for string: `"text/javascript"`. + */ const z_loaned_encoding_t *z_encoding_text_javascript(void); +extern const z_owned_encoding_t ENCODING_TEXT_JAVASCRIPT; -// A MarkDown file. -// -// Constant alias for string: `"text/markdown"`. -extern const z_owned_encoding_t ENCODING_TEXT_MARKDOWN; +/** + * A Markdown file. + * Constant alias for string: `"text/markdown"`. + */ const z_loaned_encoding_t *z_encoding_text_markdown(void); +extern const z_owned_encoding_t ENCODING_TEXT_MARKDOWN; -// A CSV file. -// -// Constant alias for string: `"text/csv"`. -extern const z_owned_encoding_t ENCODING_TEXT_CSV; +/** + * A CSV file. + * Constant alias for string: `"text/csv"`. + */ const z_loaned_encoding_t *z_encoding_text_csv(void); +extern const z_owned_encoding_t ENCODING_TEXT_CSV; -// An application-specific SQL query. -// -// Constant alias for string: `"application/sql"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_SQL; +/** + * An application-specific SQL query. + * Constant alias for string: `"application/sql"`. + */ const z_loaned_encoding_t *z_encoding_application_sql(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_SQL; -// Constrained Application Protocol (CoAP) data intended for CoAP-to-HTTP and HTTP-to-CoAP proxies. -// -// Constant alias for string: `"application/coap-payload"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_COAP_PAYLOAD; +/** + * Constrained Application Protocol (CoAP) data intended for CoAP-to-HTTP and HTTP-to-CoAP proxies. + * Constant alias for string: `"application/coap-payload"`. + */ const z_loaned_encoding_t *z_encoding_application_coap_payload(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_COAP_PAYLOAD; -// Defines a JSON document structure for expressing a sequence of operations to apply to a JSON document. -// -// Constant alias for string: `"application/json-patch+json"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_PATCH_JSON; +/** + * Defines a JSON document structure for expressing a sequence of operations to apply to a JSON document. + * Constant alias for string: `"application/json-patch+json"`. + */ const z_loaned_encoding_t *z_encoding_application_json_patch_json(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_PATCH_JSON; -// A JSON text sequence consists of any number of JSON texts, all encoded in UTF-8. -// -// Constant alias for string: `"application/json-seq"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_SEQ; +/** + * A JSON text sequence consists of any number of JSON texts, all encoded in UTF-8. + * Constant alias for string: `"application/json-seq"`. + */ const z_loaned_encoding_t *z_encoding_application_json_seq(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_JSON_SEQ; -// A JSONPath defines a string syntax for selecting and extracting JSON values from within a given JSON value. -// -// Constant alias for string: `"application/jsonpath"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JSONPATH; +/** + * A JSONPath defines a string syntax for selecting and extracting JSON values from within a given JSON value. + * Constant alias for string: `"application/jsonpath"`. + */ const z_loaned_encoding_t *z_encoding_application_jsonpath(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_JSONPATH; -// A JSON Web Token (JWT). -// -// Constant alias for string: `"application/jwt"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_JWT; +/** + * A JSON Web Token (JWT). + * Constant alias for string: `"application/jwt"`. + */ const z_loaned_encoding_t *z_encoding_application_jwt(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_JWT; -// An application-specific MPEG-4 encoded data, either audio or video. -// -// Constant alias for string: `"application/mp4"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_MP4; +/** + * An application-specific MPEG-4 encoded data, either audio or video. + * Constant alias for string: `"application/mp4"`. + */ const z_loaned_encoding_t *z_encoding_application_mp4(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_MP4; -// A SOAP 1.2 message serialized as XML 1.0. -// -// Constant alias for string: `"application/soap+xml"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_SOAP_XML; +/** + * A SOAP 1.2 message serialized as XML 1.0. + * Constant alias for string: `"application/soap+xml"`. + */ const z_loaned_encoding_t *z_encoding_application_soap_xml(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_SOAP_XML; -// A YANG-encoded data commonly used by the Network Configuration Protocol (NETCONF). -// -// Constant alias for string: `"application/yang"`. -extern const z_owned_encoding_t ENCODING_APPLICATION_YANG; +/** + * A YANG-encoded data commonly used by the Network Configuration Protocol (NETCONF). + * Constant alias for string: `"application/yang"`. + */ const z_loaned_encoding_t *z_encoding_application_yang(void); +extern const z_owned_encoding_t ENCODING_APPLICATION_YANG; -// A MPEG-4 Advanced Audio Coding (AAC) media. -// -// Constant alias for string: `"audio/aac"`. -extern const z_owned_encoding_t ENCODING_AUDIO_AAC; +/** + * A MPEG-4 Advanced Audio Coding (AAC) media. + * Constant alias for string: `"audio/aac"`. + */ const z_loaned_encoding_t *z_encoding_audio_aac(void); +extern const z_owned_encoding_t ENCODING_AUDIO_AAC; -// A Free Lossless Audio Codec (FLAC) media. -// -// Constant alias for string: `"audio/flac"`. -extern const z_owned_encoding_t ENCODING_AUDIO_FLAC; +/** + * A Free Lossless Audio Codec (FLAC) media. + * Constant alias for string: `"audio/flac"`. + */ const z_loaned_encoding_t *z_encoding_audio_flac(void); +extern const z_owned_encoding_t ENCODING_AUDIO_FLAC; -// An audio codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. -// -// Constant alias for string: `"audio/mp4"`. -extern const z_owned_encoding_t ENCODING_AUDIO_MP4; +/** + * An audio codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. + * Constant alias for string: `"audio/mp4"`. + */ const z_loaned_encoding_t *z_encoding_audio_mp4(void); +extern const z_owned_encoding_t ENCODING_AUDIO_MP4; -// An Ogg-encapsulated audio stream. -// -// Constant alias for string: `"audio/ogg"`. -extern const z_owned_encoding_t ENCODING_AUDIO_OGG; +/** + * An Ogg-encapsulated audio stream. + * Constant alias for string: `"audio/ogg"`. + */ const z_loaned_encoding_t *z_encoding_audio_ogg(void); +extern const z_owned_encoding_t ENCODING_AUDIO_OGG; -// A Vorbis-encoded audio stream. -// -// Constant alias for string: `"audio/vorbis"`. -extern const z_owned_encoding_t ENCODING_AUDIO_VORBIS; +/** + * A Vorbis-encoded audio stream. + * Constant alias for string: `"audio/vorbis"`. + */ const z_loaned_encoding_t *z_encoding_audio_vorbis(void); +extern const z_owned_encoding_t ENCODING_AUDIO_VORBIS; -// A h261-encoded video stream. -// -// Constant alias for string: `"video/h261"`. -extern const z_owned_encoding_t ENCODING_VIDEO_H261; +/** + * A h261-encoded video stream. + * Constant alias for string: `"video/h261"`. + */ const z_loaned_encoding_t *z_encoding_video_h261(void); +extern const z_owned_encoding_t ENCODING_VIDEO_H261; -// A h263-encoded video stream. -// -// Constant alias for string: `"video/h263"`. -extern const z_owned_encoding_t ENCODING_VIDEO_H263; +/** + * A h263-encoded video stream. + * Constant alias for string: `"video/h263"`. + */ const z_loaned_encoding_t *z_encoding_video_h263(void); +extern const z_owned_encoding_t ENCODING_VIDEO_H263; -// A h264-encoded video stream. -// -// Constant alias for string: `"video/h264"`. -extern const z_owned_encoding_t ENCODING_VIDEO_H264; +/** + * A h264-encoded video stream. + * Constant alias for string: `"video/h264"`. + */ const z_loaned_encoding_t *z_encoding_video_h264(void); +extern const z_owned_encoding_t ENCODING_VIDEO_H264; -// A h265-encoded video stream. -// -// Constant alias for string: `"video/h265"`. -extern const z_owned_encoding_t ENCODING_VIDEO_H265; +/** + * A h265-encoded video stream. + * Constant alias for string: `"video/h265"`. + */ const z_loaned_encoding_t *z_encoding_video_h265(void); +extern const z_owned_encoding_t ENCODING_VIDEO_H265; -// A h266-encoded video stream. -// -// Constant alias for string: `"video/h266"`. -extern const z_owned_encoding_t ENCODING_VIDEO_H266; +/** + * A h266-encoded video stream. + * Constant alias for string: `"video/h266"`. + */ const z_loaned_encoding_t *z_encoding_video_h266(void); +extern const z_owned_encoding_t ENCODING_VIDEO_H266; -// A video codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. -// -// Constant alias for string: `"video/mp4"`. -extern const z_owned_encoding_t ENCODING_VIDEO_MP4; +/** + * A video codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. + * Constant alias for string: `"video/mp4"`. + */ const z_loaned_encoding_t *z_encoding_video_mp4(void); +extern const z_owned_encoding_t ENCODING_VIDEO_MP4; -// An Ogg-encapsulated video stream. -// -// Constant alias for string: `"video/ogg"`. -extern const z_owned_encoding_t ENCODING_VIDEO_OGG; +/** + * An Ogg-encapsulated video stream. + * Constant alias for string: `"video/ogg"`. + */ const z_loaned_encoding_t *z_encoding_video_ogg(void); +extern const z_owned_encoding_t ENCODING_VIDEO_OGG; -// An uncompressed, studio-quality video stream. -// -// Constant alias for string: `"video/raw"`. -extern const z_owned_encoding_t ENCODING_VIDEO_RAW; +/** + * An uncompressed, studio-quality video stream. + * Constant alias for string: `"video/raw"`. + */ const z_loaned_encoding_t *z_encoding_video_raw(void); +extern const z_owned_encoding_t ENCODING_VIDEO_RAW; -// A VP8-encoded video stream. -// -// Constant alias for string: `"video/vp8"`. -extern const z_owned_encoding_t ENCODING_VIDEO_VP8; +/** + * A VP8-encoded video stream. + * Constant alias for string: `"video/vp8"`. + */ const z_loaned_encoding_t *z_encoding_video_vp8(void); +extern const z_owned_encoding_t ENCODING_VIDEO_VP8; -// A VP9-encoded video stream. -// -// Constant alias for string: `"video/vp9"`. -extern const z_owned_encoding_t ENCODING_VIDEO_VP9; +/** + * A VP9-encoded video stream. + * Constant alias for string: `"video/vp9"`. + */ const z_loaned_encoding_t *z_encoding_video_vp9(void); +extern const z_owned_encoding_t ENCODING_VIDEO_VP9; + #endif #ifdef __cplusplus From b6ae5c3209d75da866226921127ef1c19f30979a Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 19 Sep 2024 15:28:33 +0200 Subject: [PATCH 14/16] doc: fix warning --- include/zenoh-pico/api/primitives.h | 2 +- include/zenoh-pico/api/types.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index b2f37e626..d74daa3d5 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1673,7 +1673,7 @@ const z_loaned_encoding_t *z_sample_encoding(const z_loaned_sample_t *sample); z_sample_kind_t z_sample_kind(const z_loaned_sample_t *sample); /** - * (unstable) Gets the reliability a sample was received with. + * Gets the reliability a sample was received with (unstable). * * Parameters: * sample: Pointer to a :c:type:`z_loaned_sample_t` to get the reliability from. diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index f1f6ae955..d30e968da 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -229,7 +229,7 @@ typedef struct { * publisher. * z_priority_t priority: The priority of messages issued by this publisher. * bool is_express: If true, Zenoh will not wait to batch this operation with others to reduce the bandwidth. - * (unstable) z_reliability_t reliability: The reliability that should be used to transmit the data. + * z_reliability_t reliability: (unstable) The reliability that should be used to transmit the data. */ typedef struct { z_moved_encoding_t *encoding; @@ -309,7 +309,7 @@ typedef struct { * z_timestamp_t *timestamp: The API level timestamp (e.g. of the data when it was created). * bool is_express: If true, Zenoh will not wait to batch this operation with others to reduce the bandwidth. * z_moved_bytes_t* attachment: An optional attachment to the publication. - * (unstable) z_reliability_t reliability: The reliability that should be used to transmit the data. + * z_reliability_t reliability: (unstable) The reliability that should be used to transmit the data. */ typedef struct { z_moved_encoding_t *encoding; @@ -331,7 +331,7 @@ typedef struct { * z_priority_t priority: The priority of this message when router. * bool is_express: If true, Zenoh will not wait to batch this operation with others to reduce the bandwidth. * z_timestamp_t *timestamp: The API level timestamp (e.g. of the data when it was created). - * (unstable) z_reliability_t reliability: The reliability that should be used to transmit the data. + * z_reliability_t reliability: (unstable) The reliability that should be used to transmit the data. */ typedef struct { z_congestion_control_t congestion_control; From bfecb4887501fec4b898303b806105480d41fa5e Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 19 Sep 2024 16:21:37 +0200 Subject: [PATCH 15/16] fix: print memory as hex --- examples/unix/c11/z_bytes.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/unix/c11/z_bytes.c b/examples/unix/c11/z_bytes.c index 59aa2aba7..a5a074b02 100644 --- a/examples/unix/c11/z_bytes.c +++ b/examples/unix/c11/z_bytes.c @@ -51,6 +51,7 @@ static bool hashmap_iter(z_owned_bytes_t *kv_pair, void *context); static bool iter_body(z_owned_bytes_t *b, void *context); static void parse_hashmap(kv_pairs_rx_t *kvp, const z_loaned_bytes_t *hashmap); static void drop_hashmap(kv_pairs_rx_t *kvp); +static void print_slice_data(z_view_slice_t *slice); int main(void) { // z_owned_encoding_t encoding; @@ -140,9 +141,9 @@ int main(void) { z_bytes_slice_iterator_t slice_iter = z_bytes_get_slice_iterator(z_bytes_loan(&payload)); z_view_slice_t curr_slice; while (z_bytes_slice_iterator_next(&slice_iter, &curr_slice)) { - printf("slice len: %d, slice data: '%.*s'\n", (int)z_slice_len(z_view_slice_loan(&curr_slice)), - (int)z_slice_len(z_view_slice_loan(&curr_slice)), - (const char *)z_slice_data(z_view_slice_loan(&curr_slice))); + printf("slice len: %d, slice data: '", (int)z_slice_len(z_view_slice_loan(&curr_slice))); + print_slice_data(&curr_slice); + printf("'\n"); } z_drop(z_move(payload)); @@ -196,3 +197,9 @@ static void drop_hashmap(kv_pairs_rx_t *kvp) { } z_free(kvp->data); } + +static void print_slice_data(z_view_slice_t *slice) { + for (size_t i = 0; i < z_slice_len(z_view_slice_loan(slice)); i++) { + printf("0x%02x ", z_slice_data(z_view_slice_loan(slice))[i]); + } +} From 5ce366dd526ff503f0156d61ac4386bdd2d0391b Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 19 Sep 2024 18:55:11 +0200 Subject: [PATCH 16/16] doc: missing config token --- docs/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/conf.py b/docs/conf.py index 4ad571076..1cf877a6e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -35,6 +35,7 @@ "-DZ_FEATURE_SUBSCRIPTION=1", "-DZ_FEATURE_QUERY=1", "-DZ_FEATURE_QUERYABLE=1", + "-DZ_FEATURE_ENCODING_VALUES=1" ] # -- Options for HTML output -------------------------------------------------