-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding utility functions for parsing query params relevant to advance…
…d pub/sub.
- Loading branch information
Showing
10 changed files
with
696 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Copyright (c) 2025 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, <[email protected]> | ||
// | ||
|
||
#ifndef ZENOH_PICO_UTILS_QUERY_PARAMS_H | ||
#define ZENOH_PICO_UTILS_QUERY_PARAMS_H | ||
|
||
#include "zenoh-pico/utils/string.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern const char *_Z_QUERY_PARAMS_KEY_TIME; | ||
|
||
typedef struct { | ||
_z_str_se_t key; | ||
_z_str_se_t value; | ||
} _z_query_param_t; | ||
|
||
/** | ||
* Extracts the next query parameter from a `_z_str_se_t` string. | ||
* | ||
* Returns a `_z_query_param_t` with positions of the next key/value in the string if present. | ||
* After invocation `str` will point to the remainder of the string. | ||
*/ | ||
_z_query_param_t _z_query_params_next(_z_str_se_t *str); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* ZENOH_PICO_UTILS_QUERY_PARAMS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// Copyright (c) 2025 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, <[email protected]> | ||
// | ||
|
||
#ifndef ZENOH_PICO_UTILS_TIME_RANGE_H | ||
#define ZENOH_PICO_UTILS_TIME_RANGE_H | ||
|
||
#include "zenoh-pico/system/platform.h" | ||
#include "zenoh-pico/utils/string.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct { | ||
enum { _Z_TIME_BOUND_INCLUSIVE, _Z_TIME_BOUND_EXCLUSIVE, _Z_TIME_BOUND_UNBOUNDED } bound; | ||
double now_offset; | ||
} _z_time_bound_t; | ||
|
||
typedef struct { | ||
_z_time_bound_t start; | ||
_z_time_bound_t end; | ||
} _z_time_range_t; | ||
|
||
/** | ||
* Parse a time range from a string. | ||
* | ||
* Returns true if the string contained a valid time range, false otherwise. | ||
* If valid range will contain the result. | ||
*/ | ||
bool _z_time_range_from_str(const char *str, size_t len, _z_time_range_t *range); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* ZENOH_PICO_UTILS_TIME_RANGE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Copyright (c) 2025 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, <[email protected]> | ||
// | ||
|
||
#include "zenoh-pico/utils/query_params.h" | ||
|
||
#include "zenoh-pico/utils/pointers.h" | ||
|
||
const char *_Z_QUERY_PARAMS_KEY_TIME = "_time"; | ||
|
||
static const char *_Z_QUERY_PARAMS_LIST_SEPARATOR = ";"; | ||
static const char *_Z_QUERY_PARAMS_FIELD_SEPARATOR = "="; | ||
|
||
_z_query_param_t _z_query_params_next(_z_str_se_t *str) { | ||
_z_query_param_t result = {0}; | ||
|
||
_z_splitstr_t params = {.s = *str, .delimiter = _Z_QUERY_PARAMS_LIST_SEPARATOR}; | ||
_z_str_se_t param = _z_splitstr_next(¶ms); | ||
str->start = params.s.start; | ||
str->end = params.s.end; | ||
|
||
if (param.start != NULL) { | ||
_z_splitstr_t kvpair = {.s = param, .delimiter = _Z_QUERY_PARAMS_FIELD_SEPARATOR}; | ||
_z_str_se_t key = _z_splitstr_next(&kvpair); | ||
|
||
// Set key if length > 0 | ||
if (_z_ptr_char_diff(key.end, key.start) > 0) { | ||
result.key.start = key.start; | ||
result.key.end = key.end; | ||
|
||
// Set value if length > 0 | ||
if (_z_ptr_char_diff(kvpair.s.end, kvpair.s.start) > 0) { | ||
result.value.start = kvpair.s.start; | ||
result.value.end = kvpair.s.end; | ||
} | ||
} | ||
} | ||
return result; | ||
} |
Oops, something went wrong.