Skip to content

Commit

Permalink
part of tests passing [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
p-avital committed Jul 7, 2023
1 parent ef3e956 commit 7fe228b
Show file tree
Hide file tree
Showing 24 changed files with 880 additions and 2,120 deletions.
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE)
endif()

string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definition(ZENOH_LINUX)
Expand Down Expand Up @@ -104,15 +104,15 @@ endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
if(CMAKE_BUILD_TYPE_UPPER MATCHES "DEBUG")
if(UNIX)
add_compile_options(-c -Wall -Wextra -Werror -Wunused -Wstrict-prototypes -pipe -g -O0)
elseif(MSVC)
add_compile_options(/W4 /WX /Od)
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -pipe -g -O0)
endif()
elseif(CMAKE_BUILD_TYPE MATCHES "RELEASE")
elseif(CMAKE_BUILD_TYPE_UPPER MATCHES "RELEASE")
if(UNIX)
add_compile_options(-pipe -O3)
elseif(MSVC)
Expand Down Expand Up @@ -217,8 +217,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
endif()

if(BUILD_TESTING)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
add_executable(z_data_struct_test ${PROJECT_SOURCE_DIR}/tests/z_data_struct_test.c)
add_executable(z_endpoint_test ${PROJECT_SOURCE_DIR}/tests/z_endpoint_test.c)
add_executable(z_iobuf_test ${PROJECT_SOURCE_DIR}/tests/z_iobuf_test.c)
Expand Down
7 changes: 7 additions & 0 deletions include/zenoh-pico/protocol/codec/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_CORE_H
#define INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_CORE_H

#include <stddef.h>
#include <stdint.h>

#include "zenoh-pico/protocol/core.h"
Expand Down Expand Up @@ -52,16 +53,20 @@ int8_t _z_uint16_decode(uint16_t *u16, _z_zbuf_t *buf);
int8_t _z_uint64_encode(_z_wbuf_t *buf, uint64_t v);
int8_t _z_uint64_decode(uint64_t *u64, _z_zbuf_t *buf);

uint8_t _z_zint_len(_z_zint_t v);
int8_t _z_zint_encode(_z_wbuf_t *buf, _z_zint_t v);
int8_t _z_zint64_encode(_z_wbuf_t *buf, uint64_t v);
int8_t _z_zint16_decode(uint16_t *zint, _z_zbuf_t *buf);
int8_t _z_zint32_decode(uint32_t *zint, _z_zbuf_t *buf);
int8_t _z_zint64_decode(uint64_t *zint, _z_zbuf_t *buf);
int8_t _z_zint_decode(_z_zint_t *zint, _z_zbuf_t *buf);

int8_t _z_bytes_val_encode(_z_wbuf_t *buf, const _z_bytes_t *bs);
int8_t _z_bytes_val_decode(_z_bytes_t *bs, _z_zbuf_t *buf);
int8_t _z_bytes_val_decode_na(_z_bytes_t *bs, _z_zbuf_t *zbf);

int8_t _z_bytes_encode(_z_wbuf_t *buf, const _z_bytes_t *bs);
size_t _z_bytes_encode_len(const _z_bytes_t *bs);
int8_t _z_bytes_decode(_z_bytes_t *bs, _z_zbuf_t *buf);
int8_t _z_zbuf_read_exact(_z_zbuf_t *zbf, uint8_t *dest, size_t length);

Expand All @@ -76,5 +81,7 @@ int8_t _z_keyexpr_encode(_z_wbuf_t *buf, _Bool has_suffix, const _z_keyexpr_t *k
int8_t _z_keyexpr_decode(_z_keyexpr_t *ke, _z_zbuf_t *buf, _Bool has_suffix);

int8_t _z_timestamp_encode(_z_wbuf_t *buf, const _z_timestamp_t *ts);
int8_t _z_timestamp_encode_ext(_z_wbuf_t *buf, const _z_timestamp_t *ts);
int8_t _z_timestamp_decode(_z_timestamp_t *ts, _z_zbuf_t *buf);

#endif /* INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_CORE_H */
23 changes: 23 additions & 0 deletions include/zenoh-pico/protocol/codec/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@
#define _Z_DECL_INTEREST_MID 8
#define _Z_FINAL_INTEREST_MID 9
#define _Z_UNDECL_INTEREST_MID 10
int8_t _z_decl_kexpr_encode(_z_wbuf_t *wbf, const _z_decl_kexpr_t *decl);
int8_t _z_decl_kexpr_decode(_z_decl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_undecl_kexpr_encode(_z_wbuf_t *wbf, const _z_undecl_kexpr_t *decl);
int8_t _z_undecl_kexpr_decode(_z_undecl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_decl_subscriber_encode(_z_wbuf_t *wbf, const _z_decl_subscriber_t *decl);
int8_t _z_decl_subscriber_decode(_z_decl_subscriber_t *decl, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_undecl_subscriber_encode(_z_wbuf_t *wbf, const _z_undecl_subscriber_t *decl);
int8_t _z_undecl_subscriber_decode(_z_undecl_subscriber_t *decl, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_decl_queryable_encode(_z_wbuf_t *wbf, const _z_decl_queryable_t *decl);
int8_t _z_decl_queryable_decode(_z_decl_queryable_t *decl, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_undecl_queryable_encode(_z_wbuf_t *wbf, const _z_undecl_queryable_t *decl);
int8_t _z_undecl_queryable_decode(_z_undecl_queryable_t *decl, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_decl_token_encode(_z_wbuf_t *wbf, const _z_decl_token_t *decl);
int8_t _z_decl_token_decode(_z_decl_token_t *decl, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_undecl_token_encode(_z_wbuf_t *wbf, const _z_undecl_token_t *decl);
int8_t _z_undecl_token_decode(_z_undecl_token_t *decl, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_decl_interest_encode(_z_wbuf_t *wbf, const _z_decl_interest_t *decl);
int8_t _z_decl_interest_decode(_z_decl_interest_t *decl, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_final_interest_encode(_z_wbuf_t *wbf, const _z_final_interest_t *decl);
int8_t _z_final_interest_decode(_z_final_interest_t *decl, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_undecl_interest_encode(_z_wbuf_t *wbf, const _z_undecl_interest_t *decl);
int8_t _z_undecl_interest_decode(_z_undecl_interest_t *decl, _z_zbuf_t *zbf, uint8_t header);

int8_t _z_declaration_encode(_z_wbuf_t *wbf, const _z_declaration_t *decl);
int8_t _z_declaration_decode(_z_declaration_t *decl, _z_zbuf_t *zbf);

Expand Down
3 changes: 3 additions & 0 deletions include/zenoh-pico/protocol/codec/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ int8_t _z_err_decode(_z_msg_err_t *err, _z_zbuf_t *zbf, uint8_t header);
int8_t _z_ack_encode(_z_wbuf_t *wbf, const _z_msg_ack_t *ack);
int8_t _z_ack_decode(_z_msg_ack_t *ack, _z_zbuf_t *zbf, uint8_t header);

int8_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb);
int8_t _z_push_body_decode(_z_push_body_t *body, _z_zbuf_t *zbf, uint8_t header);

int8_t _z_put_encode(_z_wbuf_t *wbf, const _z_msg_put_t *put);
int8_t _z_put_decode(_z_msg_put_t *put, _z_zbuf_t *zbf, uint8_t header);

Expand Down
13 changes: 12 additions & 1 deletion include/zenoh-pico/protocol/definitions/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,26 @@ typedef struct {
uint16_t _id;
_z_keyexpr_t _keyexpr;
} _z_decl_kexpr_t;
_z_decl_kexpr_t _z_decl_kexpr_null(void);
typedef struct {
uint16_t _id;
} _z_undecl_kexpr_t;
_z_undecl_kexpr_t _z_undecl_kexpr_null(void);

typedef struct {
_z_keyexpr_t _keyexpr;
uint32_t _id;
struct {
_Bool _pull_mode;
_Bool _reliable;
} _ext_subscriber_info;
} _ext_subinfo;
} _z_decl_subscriber_t;
_z_decl_subscriber_t _z_decl_subscriber_null(void);
typedef struct {
uint32_t _id;
_z_keyexpr_t _ext_keyexpr;
} _z_undecl_subscriber_t;
_z_undecl_subscriber_t _z_undecl_subscriber_null(void);

typedef struct {
_z_keyexpr_t _keyexpr;
Expand All @@ -49,19 +53,23 @@ typedef struct {
uint32_t _distance;
} _ext_queryable_info;
} _z_decl_queryable_t;
_z_decl_queryable_t _z_decl_queryable_null(void);
typedef struct {
uint32_t _id;
_z_keyexpr_t _ext_keyexpr;
} _z_undecl_queryable_t;
_z_undecl_queryable_t _z_undecl_queryable_null(void);

typedef struct {
_z_keyexpr_t _keyexpr;
uint32_t _id;
} _z_decl_token_t;
_z_decl_token_t _z_decl_token_null(void);
typedef struct {
uint32_t _id;
_z_keyexpr_t _ext_keyexpr;
} _z_undecl_token_t;
_z_undecl_token_t _z_undecl_token_null(void);

#define _Z_INTEREST_FLAG_KEYEXPRS (1)
#define _Z_INTEREST_FLAG_SUBSCRIBERS (1 << 1)
Expand All @@ -75,13 +83,16 @@ typedef struct {
uint32_t _id;
uint8_t interest_flags;
} _z_decl_interest_t;
_z_decl_interest_t _z_decl_interest_null(void);
typedef struct {
uint32_t _id;
} _z_final_interest_t;
_z_final_interest_t _z_final_interest_null(void);
typedef struct {
uint32_t _id;
_z_keyexpr_t _ext_keyexpr;
} _z_undecl_interest_t;
_z_undecl_interest_t _z_undecl_interest_null(void);

typedef struct {
enum {
Expand Down
8 changes: 4 additions & 4 deletions include/zenoh-pico/protocol/definitions/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#define _Z_FLAG_Z_I 0x40 // 1 << 6 | DataInfo if I==1 then DataInfo is present
#define _Z_FLAG_Z_K 0x80 // 1 << 7 | ResourceKey if K==1 then keyexpr is string
#define _Z_FLAG_Z_N 0x40 // 1 << 6 | MaxSamples if N==1 then the MaxSamples is indicated
#define _Z_FLAG_Z_P 0x80 // 1 << 7 | Period if P==1 then a period is present
#define _Z_FLAG_Z_P 0x20 // 1 << 7 | Period if P==1 then a period is present
#define _Z_FLAG_Z_Q 0x40 // 1 << 6 | QueryableKind if Q==1 then the queryable kind is present
#define _Z_FLAG_Z_R \
0x20 // 1 << 5 | Reliable if R==1 then it concerns the reliable channel, best-effort otherwise
Expand Down Expand Up @@ -169,9 +169,9 @@ void _z_msg_put_clear(_z_msg_put_t *);
#define _Z_FLAG_Z_Q_P 0x20 // 1 << 6 | Period if P==1 then a period is present
typedef struct {
_z_bytes_t _parameters;
_z_source_info_t _info;
_z_value_t _value;
z_consolidation_mode_t _consolidation;
_z_source_info_t _ext_info;
_z_value_t _ext_value;
z_consolidation_mode_t _ext_consolidation;
} _z_msg_query_t;
typedef struct {
_Bool info;
Expand Down
16 changes: 8 additions & 8 deletions include/zenoh-pico/protocol/definitions/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ typedef struct {
typedef struct {
_z_zint_t _rid;
_z_keyexpr_t _key;
_z_timestamp_t ext_tstamp;
_z_n_qos_t ext_qos;
z_query_target_t ext_target;
uint32_t ext_budget;
uint32_t ext_timeout_ms;
_z_timestamp_t _ext_timestamp;
_z_n_qos_t _ext_qos;
z_query_target_t _ext_target;
uint32_t _ext_budget;
uint32_t _ext_timeout_ms;
enum { _Z_REQUEST_QUERY, _Z_REQUEST_PUT, _Z_REQUEST_DEL, _Z_REQUEST_PULL } _tag;
union {
_z_msg_query_t _query;
_z_msg_put_t put;
_z_msg_del_t del;
_z_msg_pull_t pull;
_z_msg_put_t _put;
_z_msg_del_t _del;
_z_msg_pull_t _pull;
} _body;
} _z_n_msg_request_t;
typedef struct {
Expand Down
3 changes: 2 additions & 1 deletion include/zenoh-pico/protocol/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define ZENOH_PICO_PROTOCOL_EXTENSION_H

#include <stdbool.h>
#include <stdint.h>

#include "zenoh-pico/protocol/core.h"

Expand Down Expand Up @@ -61,7 +62,7 @@ void _z_msg_ext_clear_unit(_z_msg_ext_unit_t *ext);

/*------------------ ZID Extension ------------------*/
typedef struct {
_z_zint_t _val;
uint64_t _val;
} _z_msg_ext_zint_t;
void _z_msg_ext_clear_zint(_z_msg_ext_zint_t *ext);

Expand Down
3 changes: 3 additions & 0 deletions include/zenoh-pico/protocol/keyexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ void _z_keyexpr_copy(_z_keyexpr_t *dst, const _z_keyexpr_t *src);
_z_keyexpr_t _z_keyexpr_duplicate(_z_keyexpr_t src);
_z_keyexpr_t _z_keyexpr_alias(_z_keyexpr_t src);
_z_keyexpr_t _z_keyexpr_steal(_Z_MOVE(_z_keyexpr_t) src);
static inline _z_keyexpr_t _z_keyexpr_null(void) {
return (_z_keyexpr_t){._id = 0, ._owns_suffix = false, ._suffix = NULL, ._uses_remote_mapping = false};
}
_z_timestamp_t _z_timestamp_duplicate(const _z_timestamp_t *tstamp);
void _z_timestamp_clear(_z_timestamp_t *tstamp);
void _z_keyexpr_clear(_z_keyexpr_t *rk);
Expand Down
3 changes: 0 additions & 3 deletions include/zenoh-pico/protocol/msgcodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
int8_t _z_payload_encode(_z_wbuf_t *buf, const _z_bytes_t *pld);
int8_t _z_payload_decode(_z_bytes_t *pld, _z_zbuf_t *buf);
int8_t _z_payload_decode_na(_z_bytes_t *pld, _z_zbuf_t *buf);

int8_t _z_subinfo_encode(_z_wbuf_t *buf, const _z_subinfo_t *si);
int8_t _z_subinfo_decode(_z_subinfo_t *si, _z_zbuf_t *buf, uint8_t header);
int8_t _z_subinfo_decode_na(_z_subinfo_t *si, _z_zbuf_t *buf, uint8_t header);

int8_t _z_data_info_encode(_z_wbuf_t *buf, const _z_data_info_t *di);
Expand Down
38 changes: 38 additions & 0 deletions src/protocol/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ int8_t _z_uint64_decode(uint64_t *u64, _z_zbuf_t *zbf) {
}

/*------------------ z_zint ------------------*/
uint8_t _z_zint_len(_z_zint_t v) {
uint8_t len = 1;
while (v > 0x7f) {
v >>= 7;
len++;
}
return len;
}
int8_t _z_zint_encode(_z_wbuf_t *wbf, _z_zint_t v) {
_z_zint_t lv = v;

Expand All @@ -214,6 +222,18 @@ int8_t _z_zint_encode(_z_wbuf_t *wbf, _z_zint_t v) {
uint8_t c = lv & 0xff;
return _z_wbuf_write(wbf, c);
}
int8_t _z_zint64_encode(_z_wbuf_t *wbf, uint64_t v) {
uint64_t lv = v;

while (lv > 0x7f) {
uint8_t c = (lv & 0x7f) | 0x80;
_Z_RETURN_IF_ERR(_z_wbuf_write(wbf, c))
lv = lv >> (uint64_t)7;
}

uint8_t c = lv & 0xff;
return _z_wbuf_write(wbf, c);
}
int8_t _z_zint16_decode(uint16_t *zint, _z_zbuf_t *zbf) {
int8_t ret = _Z_RES_OK;
_z_zint_t buf;
Expand Down Expand Up @@ -253,6 +273,23 @@ int8_t _z_zint_decode(_z_zint_t *zint, _z_zbuf_t *zbf) {

return ret;
}
int8_t _z_zint64_decode(uint64_t *zint, _z_zbuf_t *zbf) {
int8_t ret = _Z_RES_OK;
*zint = 0;

uint8_t i = 0;
uint8_t u8 = 0;
do {
if (_z_uint8_decode(&u8, zbf) == _Z_RES_OK) {
*zint = *zint | (((uint64_t)u8 & 0x7f) << i);
i = i + (uint8_t)7;
} else {
ret |= _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
}
} while (u8 > (uint8_t)0x7f);

return ret;
}

/*------------------ uint8_array ------------------*/
int8_t _z_bytes_val_encode(_z_wbuf_t *wbf, const _z_bytes_t *bs) {
Expand All @@ -275,6 +312,7 @@ int8_t _z_bytes_encode(_z_wbuf_t *wbf, const _z_bytes_t *bs) {

return ret;
}
size_t _z_bytes_encode_len(const _z_bytes_t *bs) { return _z_zint_len(bs->len) + bs->len; }

int8_t _z_bytes_val_decode_na(_z_bytes_t *bs, _z_zbuf_t *zbf) {
int8_t ret = _Z_RES_OK;
Expand Down
Loading

0 comments on commit 7fe228b

Please sign in to comment.