From 8d90cb7d08e4e2277ede557c822effdff3357b29 Mon Sep 17 00:00:00 2001 From: fengzero Date: Wed, 6 Nov 2024 08:01:32 +0000 Subject: [PATCH] support array type --- include/neuron/json/json.h | 92 +++++++- include/neuron/msg.h | 138 +++++++++++- include/neuron/type.h | 127 +++++++++-- plugins/ekuiper/read_write.c | 25 ++- plugins/modbus/modbus_req.c | 43 ++-- plugins/mqtt/mqtt_handle.c | 25 ++- plugins/restful/rw_handle.c | 111 ++++++++-- src/adapter/driver/cache.c | 342 +++++++++++++++++++++++++++++ src/adapter/driver/driver.c | 414 +++++++++++++++++++++++++++++++++++ src/parser/neu_json_rw.c | 135 +++++++++++- src/utils/json.c | 194 ++++++++++++++-- 11 files changed, 1530 insertions(+), 116 deletions(-) diff --git a/include/neuron/json/json.h b/include/neuron/json/json.h index 8a1dcf1cf..a9a1a617c 100644 --- a/include/neuron/json/json.h +++ b/include/neuron/json/json.h @@ -37,24 +37,94 @@ typedef enum neu_json_type { NEU_JSON_FLOAT, NEU_JSON_BOOL, NEU_JSON_OBJECT, - NEU_JSON_BYTES, + NEU_JSON_ARRAY_INT8, + NEU_JSON_ARRAY_UINT8, + NEU_JSON_ARRAY_INT16, + NEU_JSON_ARRAY_UINT16, + NEU_JSON_ARRAY_INT32, + NEU_JSON_ARRAY_UINT32, + NEU_JSON_ARRAY_INT64, + NEU_JSON_ARRAY_UINT64, + NEU_JSON_ARRAY_FLOAT, + NEU_JSON_ARRAY_DOUBLE, + NEU_JSON_ARRAY_BOOL, NEU_JSON_VALUE = NEU_JSON_UNDEFINE } neu_json_type_e; typedef struct { - uint8_t *bytes; + int8_t *i8s; + uint8_t length; +} neu_json_value_array_int8_t; + +typedef struct { + uint8_t *u8s; + uint8_t length; +} neu_json_value_array_uint8_t; + +typedef struct { + int16_t *i16s; + uint8_t length; +} neu_json_value_array_int16_t; + +typedef struct { + uint16_t *u16s; + uint8_t length; +} neu_json_value_array_uint16_t; + +typedef struct { + int32_t *i32s; uint8_t length; -} neu_json_value_bytes_t; +} neu_json_value_array_int32_t; + +typedef struct { + uint32_t *u32s; + uint8_t length; +} neu_json_value_array_uint32_t; + +typedef struct { + int64_t *i64s; + uint8_t length; +} neu_json_value_array_int64_t; + +typedef struct { + uint64_t *u64s; + uint8_t length; +} neu_json_value_array_uint64_t; + +typedef struct { + float * f32s; + uint8_t length; +} neu_json_value_array_float_t; + +typedef struct { + double *f64s; + uint8_t length; +} neu_json_value_array_double_t; + +typedef struct { + bool * bools; + uint8_t length; +} neu_json_value_array_bool_t; typedef union neu_json_value { - int64_t val_int; - uint8_t val_bit; - float val_float; - double val_double; - bool val_bool; - char * val_str; - void * val_object; - neu_json_value_bytes_t val_bytes; + int64_t val_int; + uint8_t val_bit; + float val_float; + double val_double; + bool val_bool; + char * val_str; + void * val_object; + neu_json_value_array_int8_t val_array_int8; + neu_json_value_array_uint8_t val_array_uint8; + neu_json_value_array_int16_t val_array_int16; + neu_json_value_array_uint16_t val_array_uint16; + neu_json_value_array_int32_t val_array_int32; + neu_json_value_array_uint32_t val_array_uint32; + neu_json_value_array_int64_t val_array_int64; + neu_json_value_array_uint64_t val_array_uint64; + neu_json_value_array_float_t val_array_float; + neu_json_value_array_double_t val_array_double; + neu_json_value_array_bool_t val_array_bool; } neu_json_value_u; typedef enum neu_json_attribute { diff --git a/include/neuron/msg.h b/include/neuron/msg.h index c5d3f3496..a7f34277d 100644 --- a/include/neuron/msg.h +++ b/include/neuron/msg.h @@ -980,6 +980,7 @@ static inline void neu_tag_value_to_json(neu_resp_tag_value_meta_t *tag_value, case NEU_TYPE_STRING: case NEU_TYPE_TIME: case NEU_TYPE_DATA_AND_TIME: + case NEU_TYPE_ARRAY_CHAR: tag_json->t = NEU_JSON_STR; tag_json->value.val_str = tag_value->value.value.str; break; @@ -988,9 +989,69 @@ static inline void neu_tag_value_to_json(neu_resp_tag_value_meta_t *tag_value, tag_json->value.val_str = (char *) tag_value->value.value.ptr.ptr; break; case NEU_TYPE_BYTES: - tag_json->t = NEU_JSON_BYTES; - tag_json->value.val_bytes.length = tag_value->value.value.bytes.length; - tag_json->value.val_bytes.bytes = tag_value->value.value.bytes.bytes; + tag_json->t = NEU_JSON_ARRAY_UINT8; + tag_json->value.val_array_uint8.length = + tag_value->value.value.bytes.length; + tag_json->value.val_array_uint8.u8s = + tag_value->value.value.bytes.bytes; + break; + case NEU_TYPE_ARRAY_INT8: + tag_json->t = NEU_JSON_ARRAY_INT8; + tag_json->value.val_array_int8.length = + tag_value->value.value.i8s.length; + tag_json->value.val_array_int8.i8s = tag_value->value.value.i8s.i8s; + break; + case NEU_TYPE_ARRAY_INT16: + tag_json->t = NEU_JSON_ARRAY_INT16; + tag_json->value.val_array_int16.length = + tag_value->value.value.i16s.length; + tag_json->value.val_array_int16.i16s = tag_value->value.value.i16s.i16s; + break; + case NEU_TYPE_ARRAY_UINT16: + tag_json->t = NEU_JSON_ARRAY_UINT16; + tag_json->value.val_array_uint16.length = + tag_value->value.value.u16s.length; + tag_json->value.val_array_uint16.u16s = + tag_value->value.value.u16s.u16s; + break; + case NEU_TYPE_ARRAY_INT32: + tag_json->t = NEU_JSON_ARRAY_INT32; + tag_json->value.val_array_int32.length = + tag_value->value.value.i32s.length; + tag_json->value.val_array_int32.i32s = tag_value->value.value.i32s.i32s; + break; + case NEU_TYPE_ARRAY_UINT32: + tag_json->t = NEU_JSON_ARRAY_UINT32; + tag_json->value.val_array_uint32.length = + tag_value->value.value.u32s.length; + tag_json->value.val_array_uint32.u32s = + tag_value->value.value.u32s.u32s; + break; + case NEU_TYPE_ARRAY_INT64: + tag_json->t = NEU_JSON_ARRAY_INT64; + tag_json->value.val_array_int64.length = + tag_value->value.value.i64s.length; + tag_json->value.val_array_int64.i64s = tag_value->value.value.i64s.i64s; + break; + case NEU_TYPE_ARRAY_UINT64: + tag_json->t = NEU_JSON_ARRAY_UINT64; + tag_json->value.val_array_uint64.length = + tag_value->value.value.u64s.length; + tag_json->value.val_array_uint64.u64s = + tag_value->value.value.u64s.u64s; + break; + case NEU_TYPE_ARRAY_FLOAT: + tag_json->t = NEU_JSON_ARRAY_FLOAT; + tag_json->value.val_array_float.length = + tag_value->value.value.f32s.length; + tag_json->value.val_array_float.f32s = tag_value->value.value.f32s.f32s; + break; + case NEU_TYPE_ARRAY_DOUBLE: + tag_json->t = NEU_JSON_ARRAY_DOUBLE; + tag_json->value.val_array_double.length = + tag_value->value.value.f64s.length; + tag_json->value.val_array_double.f64s = + tag_value->value.value.f64s.f64s; break; case NEU_TYPE_CUSTOM: tag_json->t = NEU_JSON_OBJECT; @@ -1108,6 +1169,7 @@ neu_tag_value_to_json_paginate(neu_resp_tag_value_meta_paginate_t *tag_value, case NEU_TYPE_STRING: case NEU_TYPE_TIME: case NEU_TYPE_DATA_AND_TIME: + case NEU_TYPE_ARRAY_CHAR: tag_json->t = NEU_JSON_STR; tag_json->value.val_str = tag_value->value.value.str; break; @@ -1116,9 +1178,73 @@ neu_tag_value_to_json_paginate(neu_resp_tag_value_meta_paginate_t *tag_value, tag_json->value.val_str = (char *) tag_value->value.value.ptr.ptr; break; case NEU_TYPE_BYTES: - tag_json->t = NEU_JSON_BYTES; - tag_json->value.val_bytes.length = tag_value->value.value.bytes.length; - tag_json->value.val_bytes.bytes = tag_value->value.value.bytes.bytes; + tag_json->t = NEU_JSON_ARRAY_UINT8; + tag_json->value.val_array_uint8.length = + tag_value->value.value.bytes.length; + tag_json->value.val_array_uint8.u8s = + tag_value->value.value.bytes.bytes; + break; + case NEU_TYPE_ARRAY_INT8: + tag_json->t = NEU_JSON_ARRAY_INT8; + tag_json->value.val_array_int8.length = + tag_value->value.value.i8s.length; + tag_json->value.val_array_int8.i8s = tag_value->value.value.i8s.i8s; + break; + case NEU_TYPE_ARRAY_INT16: + tag_json->t = NEU_JSON_ARRAY_INT16; + tag_json->value.val_array_int16.length = + tag_value->value.value.i16s.length; + tag_json->value.val_array_int16.i16s = tag_value->value.value.i16s.i16s; + break; + case NEU_TYPE_ARRAY_UINT16: + tag_json->t = NEU_JSON_ARRAY_UINT16; + tag_json->value.val_array_uint16.length = + tag_value->value.value.u16s.length; + tag_json->value.val_array_uint16.u16s = + tag_value->value.value.u16s.u16s; + break; + case NEU_TYPE_ARRAY_INT32: + tag_json->t = NEU_JSON_ARRAY_INT32; + tag_json->value.val_array_int32.length = + tag_value->value.value.i32s.length; + tag_json->value.val_array_int32.i32s = tag_value->value.value.i32s.i32s; + break; + case NEU_TYPE_ARRAY_UINT32: + tag_json->t = NEU_JSON_ARRAY_UINT32; + tag_json->value.val_array_uint32.length = + tag_value->value.value.u32s.length; + tag_json->value.val_array_uint32.u32s = + tag_value->value.value.u32s.u32s; + break; + case NEU_TYPE_ARRAY_INT64: + tag_json->t = NEU_JSON_ARRAY_INT64; + tag_json->value.val_array_int64.length = + tag_value->value.value.i64s.length; + tag_json->value.val_array_int64.i64s = tag_value->value.value.i64s.i64s; + break; + case NEU_TYPE_ARRAY_UINT64: + tag_json->t = NEU_JSON_ARRAY_UINT64; + tag_json->value.val_array_uint64.length = + tag_value->value.value.u64s.length; + tag_json->value.val_array_uint64.u64s = + tag_value->value.value.u64s.u64s; + break; + case NEU_TYPE_ARRAY_FLOAT: + tag_json->t = NEU_JSON_ARRAY_FLOAT; + tag_json->value.val_array_float.length = + tag_value->value.value.f32s.length; + tag_json->value.val_array_float.f32s = tag_value->value.value.f32s.f32s; + break; + case NEU_TYPE_ARRAY_DOUBLE: + tag_json->t = NEU_JSON_ARRAY_DOUBLE; + tag_json->value.val_array_double.length = + tag_value->value.value.f64s.length; + tag_json->value.val_array_double.f64s = + tag_value->value.value.f64s.f64s; + break; + case NEU_TYPE_CUSTOM: + tag_json->t = NEU_JSON_OBJECT; + tag_json->value.val_object = tag_value->value.value.json; break; default: break; diff --git a/include/neuron/type.h b/include/neuron/type.h index f2e6bd1d8..895c029e3 100644 --- a/include/neuron/type.h +++ b/include/neuron/type.h @@ -54,7 +54,18 @@ typedef enum { NEU_TYPE_PTR = 19, NEU_TYPE_TIME = 20, NEU_TYPE_DATA_AND_TIME = 21, - NEU_TYPE_CUSTOM = 22, + NEU_TYPE_ARRAY_CHAR = 22, + NEU_TYPE_ARRAY_INT8 = 23, + NEU_TYPE_ARRAY_INT16 = 24, + NEU_TYPE_ARRAY_UINT16 = 25, + NEU_TYPE_ARRAY_INT32 = 26, + NEU_TYPE_ARRAY_UINT32 = 27, + NEU_TYPE_ARRAY_INT64 = 28, + NEU_TYPE_ARRAY_UINT64 = 29, + NEU_TYPE_ARRAY_FLOAT = 30, + NEU_TYPE_ARRAY_DOUBLE = 31, + NEU_TYPE_ARRAY_BOOL = 32, + NEU_TYPE_CUSTOM = 40, } neu_type_e; inline static const char *neu_type_string(neu_type_e type) @@ -102,6 +113,28 @@ inline static const char *neu_type_string(neu_type_e type) return "NEU_TYPE_TIME"; case NEU_TYPE_DATA_AND_TIME: return "NEU_TYPE_DATA_AND_TIME"; + case NEU_TYPE_ARRAY_CHAR: + return "NEU_TYPE_ARRAY_CHAR"; + case NEU_TYPE_ARRAY_INT8: + return "NEU_TYPE_ARRAY_INT8"; + case NEU_TYPE_ARRAY_INT16: + return "NEU_TYPE_ARRAY_INT16"; + case NEU_TYPE_ARRAY_UINT16: + return "NEU_TYPE_ARRAY_UINT16"; + case NEU_TYPE_ARRAY_INT32: + return "NEU_TYPE_ARRAY_INT32"; + case NEU_TYPE_ARRAY_UINT32: + return "NEU_TYPE_ARRAY_UINT32"; + case NEU_TYPE_ARRAY_INT64: + return "NEU_TYPE_ARRAY_INT64"; + case NEU_TYPE_ARRAY_UINT64: + return "NEU_TYPE_ARRAY_UINT64"; + case NEU_TYPE_ARRAY_FLOAT: + return "NEU_TYPE_ARRAY_FLOAT"; + case NEU_TYPE_ARRAY_DOUBLE: + return "NEU_TYPE_ARRAY_FLOAT"; + case NEU_TYPE_ARRAY_BOOL: + return "NEU_TYPE_ARRAY_BOOL"; case NEU_TYPE_CUSTOM: return "NEU_TYPE_CUSTOM"; } @@ -120,24 +153,84 @@ typedef struct { typedef struct { uint8_t bytes[NEU_VALUE_SIZE]; uint8_t length; -} __attribute__((packed)) neu_value_bytes_t; +} neu_value_bytes_t; + +typedef struct { + int8_t i8s[NEU_VALUE_SIZE]; + uint8_t length; +} neu_value_array_int8_t; + +typedef struct { + int16_t i16s[NEU_VALUE_SIZE]; + uint8_t length; +} neu_value_array_int16_t; + +typedef struct { + uint16_t u16s[NEU_VALUE_SIZE]; + uint8_t length; +} neu_value_array_uint16_t; + +typedef struct { + int32_t i32s[NEU_VALUE_SIZE]; + uint8_t length; +} neu_value_array_int32_t; + +typedef struct { + uint32_t u32s[NEU_VALUE_SIZE]; + uint8_t length; +} neu_value_array_uint32_t; + +typedef struct { + int64_t i64s[NEU_VALUE_SIZE]; + uint8_t length; +} neu_value_array_int64_t; + +typedef struct { + uint64_t u64s[NEU_VALUE_SIZE]; + uint8_t length; +} neu_value_array_uint64_t; + +typedef struct { + float f32s[NEU_VALUE_SIZE]; + uint8_t length; +} neu_value_array_float_t; + +typedef struct { + double f64s[NEU_VALUE_SIZE]; + uint8_t length; +} neu_value_array_double_t; + +typedef struct { + bool bools[NEU_VALUE_SIZE]; + uint8_t length; +} neu_value_array_bool_t; typedef union { - bool boolean; - int8_t i8; - uint8_t u8; - int16_t i16; - uint16_t u16; - int32_t i32; - uint32_t u32; - int64_t i64; - uint64_t u64; - float f32; - double d64; - char str[NEU_VALUE_SIZE]; - neu_value_bytes_t bytes; - neu_value_ptr_t ptr; - json_t * json; + bool boolean; + int8_t i8; + uint8_t u8; + int16_t i16; + uint16_t u16; + int32_t i32; + uint32_t u32; + int64_t i64; + uint64_t u64; + float f32; + double d64; + char str[NEU_VALUE_SIZE]; + neu_value_bytes_t bytes; + neu_value_ptr_t ptr; + json_t * json; + neu_value_array_int8_t i8s; + neu_value_array_int16_t i16s; + neu_value_array_uint16_t u16s; + neu_value_array_int32_t i32s; + neu_value_array_uint32_t u32s; + neu_value_array_int64_t i64s; + neu_value_array_uint64_t u64s; + neu_value_array_float_t f32s; + neu_value_array_double_t f64s; + neu_value_array_bool_t bools; } neu_value_u; static inline char *neu_value_str(neu_type_e type, neu_value_u value) diff --git a/plugins/ekuiper/read_write.c b/plugins/ekuiper/read_write.c index 0c463a3de..4ddced85e 100644 --- a/plugins/ekuiper/read_write.c +++ b/plugins/ekuiper/read_write.c @@ -269,11 +269,26 @@ static int json_value_to_tag_value(union neu_json_value *req, value->type = NEU_TYPE_BOOL; value->value.boolean = req->val_bool; break; - case NEU_JSON_BYTES: - value->type = NEU_TYPE_BYTES; - value->value.bytes.length = req->val_bytes.length; - memcpy(value->value.bytes.bytes, req->val_bytes.bytes, - req->val_bytes.length); + case NEU_JSON_ARRAY_BOOL: + value->type = NEU_TYPE_ARRAY_BOOL; + value->value.bools.length = req->val_array_bool.length; + for (int i = 0; i < req->val_array_bool.length; i++) { + value->value.bools.bools[i] = req->val_array_bool.bools[i]; + } + break; + case NEU_JSON_ARRAY_INT64: + value->type = NEU_TYPE_ARRAY_INT64; + value->value.i64s.length = req->val_array_int64.length; + for (int i = 0; i < req->val_array_int64.length; i++) { + value->value.i64s.i64s[i] = req->val_array_int64.i64s[i]; + } + break; + case NEU_JSON_ARRAY_DOUBLE: + value->type = NEU_TYPE_ARRAY_DOUBLE; + value->value.f64s.length = req->val_array_double.length; + for (int i = 0; i < req->val_array_double.length; i++) { + value->value.f64s.f64s[i] = req->val_array_double.f64s[i]; + } break; default: return -1; diff --git a/plugins/modbus/modbus_req.c b/plugins/modbus/modbus_req.c index c5a6e923f..268e963bc 100644 --- a/plugins/modbus/modbus_req.c +++ b/plugins/modbus/modbus_req.c @@ -517,15 +517,13 @@ int modbus_value_handle_test(neu_plugin_t *plugin, void *req, (void) req; neu_json_value_u jvalue = { 0 }; neu_json_type_e jtype; + uint8_t recv_bytes[256] = { 0 }; switch (point->area) { case MODBUS_AREA_HOLD_REGISTER: case MODBUS_AREA_INPUT_REGISTER: if (n_byte >= point->n_register * 2) { - jvalue.val_bytes.bytes = - (uint8_t *) malloc(point->n_register * 2 + 1); - memcpy(jvalue.val_bytes.bytes, bytes, point->n_register * 2); - jvalue.val_bytes.length = point->n_register * 2; + memcpy(recv_bytes, bytes, point->n_register * 2); } break; case MODBUS_AREA_COIL: @@ -539,23 +537,20 @@ int modbus_value_handle_test(neu_plugin_t *plugin, void *req, case NEU_TYPE_UINT16: { jtype = NEU_JSON_INT; uint16_t tmp_val16; - memcpy(&tmp_val16, jvalue.val_bytes.bytes, sizeof(uint16_t)); - free(jvalue.val_bytes.bytes); + memcpy(&tmp_val16, recv_bytes, sizeof(uint16_t)); jvalue.val_int = ntohs(tmp_val16); break; } case NEU_TYPE_INT16: { jtype = NEU_JSON_INT; int16_t tmp_val16; - memcpy(&tmp_val16, jvalue.val_bytes.bytes, sizeof(int16_t)); - free(jvalue.val_bytes.bytes); + memcpy(&tmp_val16, recv_bytes, sizeof(int16_t)); jvalue.val_int = (int16_t) ntohs(tmp_val16); break; } case NEU_TYPE_FLOAT: { uint32_t tmp_valf; - memcpy(&tmp_valf, jvalue.val_bytes.bytes, sizeof(uint32_t)); - free(jvalue.val_bytes.bytes); + memcpy(&tmp_valf, recv_bytes, sizeof(uint32_t)); jtype = NEU_JSON_FLOAT; jvalue.val_int = ntohl(tmp_valf); break; @@ -563,23 +558,20 @@ int modbus_value_handle_test(neu_plugin_t *plugin, void *req, case NEU_TYPE_INT32: { jtype = NEU_JSON_INT; int32_t tmp_val32; - memcpy(&tmp_val32, jvalue.val_bytes.bytes, sizeof(int32_t)); - free(jvalue.val_bytes.bytes); + memcpy(&tmp_val32, recv_bytes, sizeof(int32_t)); jvalue.val_int = (int32_t) ntohl(tmp_val32); break; } case NEU_TYPE_UINT32: { jtype = NEU_JSON_INT; uint32_t tmp_val32; - memcpy(&tmp_val32, jvalue.val_bytes.bytes, sizeof(uint32_t)); - free(jvalue.val_bytes.bytes); + memcpy(&tmp_val32, recv_bytes, sizeof(uint32_t)); jvalue.val_int = ntohl(tmp_val32); break; } case NEU_TYPE_DOUBLE: { uint64_t tmp_vald; - memcpy(&tmp_vald, jvalue.val_bytes.bytes, sizeof(uint64_t)); - free(jvalue.val_bytes.bytes); + memcpy(&tmp_vald, recv_bytes, sizeof(uint64_t)); jtype = NEU_JSON_DOUBLE; jvalue.val_int = neu_ntohll(tmp_vald); break; @@ -587,16 +579,14 @@ int modbus_value_handle_test(neu_plugin_t *plugin, void *req, case NEU_TYPE_INT64: { jtype = NEU_JSON_INT; int64_t tmp_val64; - memcpy(&tmp_val64, jvalue.val_bytes.bytes, sizeof(int64_t)); - free(jvalue.val_bytes.bytes); + memcpy(&tmp_val64, recv_bytes, sizeof(int64_t)); jvalue.val_int = (int64_t) neu_ntohll(tmp_val64); break; } case NEU_TYPE_UINT64: { jtype = NEU_JSON_INT; uint64_t tmp_val64; - memcpy(&tmp_val64, jvalue.val_bytes.bytes, sizeof(uint64_t)); - free(jvalue.val_bytes.bytes); + memcpy(&tmp_val64, recv_bytes, sizeof(uint64_t)); jvalue.val_int = neu_ntohll(tmp_val64); break; } @@ -606,9 +596,8 @@ int modbus_value_handle_test(neu_plugin_t *plugin, void *req, case MODBUS_AREA_INPUT_REGISTER: { jtype = NEU_JSON_BIT; neu_value16_u v16 = { 0 }; - v16.value = htons(*(uint16_t *) jvalue.val_bytes.bytes); - free(jvalue.val_bytes.bytes); - jvalue.val_bit = neu_value16_get_bit(v16, point->option.bit.bit); + v16.value = htons(*(uint16_t *) recv_bytes); + jvalue.val_bit = neu_value16_get_bit(v16, point->option.bit.bit); break; } case MODBUS_AREA_COIL: @@ -619,10 +608,10 @@ int modbus_value_handle_test(neu_plugin_t *plugin, void *req, break; } case NEU_TYPE_STRING: { - jtype = NEU_JSON_STR; - size_t str_length = point->n_register * 2; - jvalue.val_str = (char *) jvalue.val_bytes.bytes; - jvalue.val_str[str_length] = '\0'; + jtype = NEU_JSON_STR; + size_t str_length = point->n_register * 2; + jvalue.val_str = calloc(1, str_length + 1); + strncpy(jvalue.val_str, (char *) recv_bytes, str_length); switch (point->option.string.type) { case NEU_DATATAG_STRING_TYPE_H: diff --git a/plugins/mqtt/mqtt_handle.c b/plugins/mqtt/mqtt_handle.c index ac54f9f9d..b1de56b2a 100644 --- a/plugins/mqtt/mqtt_handle.c +++ b/plugins/mqtt/mqtt_handle.c @@ -229,11 +229,26 @@ static int json_value_to_tag_value(union neu_json_value *req, value->type = NEU_TYPE_BOOL; value->value.boolean = req->val_bool; break; - case NEU_JSON_BYTES: - value->type = NEU_TYPE_BYTES; - value->value.bytes.length = req->val_bytes.length; - memcpy(value->value.bytes.bytes, req->val_bytes.bytes, - req->val_bytes.length); + case NEU_JSON_ARRAY_BOOL: + value->type = NEU_TYPE_ARRAY_BOOL; + value->value.bools.length = req->val_array_bool.length; + for (int i = 0; i < req->val_array_bool.length; i++) { + value->value.bools.bools[i] = req->val_array_bool.bools[i]; + } + break; + case NEU_JSON_ARRAY_DOUBLE: + value->type = NEU_TYPE_ARRAY_DOUBLE; + value->value.f64s.length = req->val_array_double.length; + for (int i = 0; i < req->val_array_double.length; i++) { + value->value.f64s.f64s[i] = req->val_array_double.f64s[i]; + } + break; + case NEU_JSON_ARRAY_INT64: + value->type = NEU_TYPE_ARRAY_INT64; + value->value.i64s.length = req->val_array_int64.length; + for (int i = 0; i < req->val_array_int64.length; i++) { + value->value.i64s.i64s[i] = req->val_array_int64.i64s[i]; + } break; default: return -1; diff --git a/plugins/restful/rw_handle.c b/plugins/restful/rw_handle.c index e24f2fcdb..855874998 100644 --- a/plugins/restful/rw_handle.c +++ b/plugins/restful/rw_handle.c @@ -283,8 +283,8 @@ void handle_write(nng_aio *aio) return; } - if (req->t == NEU_JSON_BYTES && - req->value.val_bytes.length > NEU_VALUE_SIZE) { + if (req->t == NEU_JSON_ARRAY_INT64 && + req->value.val_array_int64.length > NEU_VALUE_SIZE) { NEU_JSON_RESPONSE_ERROR(NEU_ERR_STRING_TOO_LONG, { neu_http_response(aio, NEU_ERR_STRING_TOO_LONG, result_error); @@ -330,21 +330,39 @@ void handle_write(nng_aio *aio) cmd.value.type = NEU_TYPE_STRING; strcpy(cmd.value.value.str, req->value.val_str); break; - case NEU_JSON_BYTES: - cmd.value.type = NEU_TYPE_BYTES; - cmd.value.value.bytes.length = req->value.val_bytes.length; - memcpy(cmd.value.value.bytes.bytes, req->value.val_bytes.bytes, - req->value.val_bytes.length); - break; case NEU_JSON_DOUBLE: cmd.value.type = NEU_TYPE_DOUBLE; cmd.value.value.d64 = req->value.val_double; - break; case NEU_JSON_BOOL: cmd.value.type = NEU_TYPE_BOOL; cmd.value.value.boolean = req->value.val_bool; break; + case NEU_JSON_ARRAY_INT64: + cmd.value.type = NEU_TYPE_ARRAY_INT64; + cmd.value.value.i64s.length = req->value.val_array_int64.length; + for (int i = 0; i < req->value.val_array_int64.length; i++) { + cmd.value.value.i64s.i64s[i] = + req->value.val_array_int64.i64s[i]; + } + break; + case NEU_JSON_ARRAY_DOUBLE: + cmd.value.type = NEU_TYPE_ARRAY_DOUBLE; + cmd.value.value.f64s.length = + req->value.val_array_double.length; + for (int i = 0; i < req->value.val_array_double.length; i++) { + cmd.value.value.f64s.f64s[i] = + req->value.val_array_double.f64s[i]; + } + break; + case NEU_JSON_ARRAY_BOOL: + cmd.value.type = NEU_TYPE_ARRAY_BOOL; + cmd.value.value.bools.length = req->value.val_array_bool.length; + for (int i = 0; i < req->value.val_array_bool.length; i++) { + cmd.value.value.bools.bools[i] = + req->value.val_array_bool.bools[i]; + } + break; default: assert(false); break; @@ -512,13 +530,35 @@ void handle_write_tags(nng_aio *aio) cmd.tags[i].value.value.boolean = req->tags[i].value.val_bool; break; - case NEU_JSON_BYTES: - cmd.tags[i].value.type = NEU_TYPE_BYTES; - cmd.tags[i].value.value.bytes.length = - req->tags[i].value.val_bytes.length; - memcpy(cmd.tags[i].value.value.bytes.bytes, - req->tags[i].value.val_bytes.bytes, - req->tags[i].value.val_bytes.length); + case NEU_JSON_ARRAY_INT64: + cmd.tags[i].value.type = NEU_TYPE_ARRAY_INT64; + cmd.tags[i].value.value.i64s.length = + req->tags[i].value.val_array_int64.length; + for (int k = 0; + k < req->tags[i].value.val_array_int64.length; k++) { + cmd.tags[i].value.value.i64s.i64s[k] = + req->tags[i].value.val_array_int64.i64s[k]; + } + break; + case NEU_JSON_ARRAY_DOUBLE: + cmd.tags[i].value.type = NEU_TYPE_ARRAY_DOUBLE; + cmd.tags[i].value.value.f64s.length = + req->tags[i].value.val_array_double.length; + for (int k = 0; + k < req->tags[i].value.val_array_double.length; k++) { + cmd.tags[i].value.value.f64s.f64s[k] = + req->tags[i].value.val_array_double.f64s[k]; + } + break; + case NEU_JSON_ARRAY_BOOL: + cmd.tags[i].value.type = NEU_TYPE_ARRAY_BOOL; + cmd.tags[i].value.value.bools.length = + req->tags[i].value.val_array_bool.length; + for (int k = 0; + k < req->tags[i].value.val_array_bool.length; k++) { + cmd.tags[i].value.value.bools.bools[k] = + req->tags[i].value.val_array_bool.bools[k]; + } break; default: assert(false); @@ -598,13 +638,38 @@ static void trans(neu_json_write_gtags_req_t *req, neu_req_write_gtags_t *cmd) cmd->groups[i].tags[k].value.value.boolean = req->groups[i].tags[k].value.val_bool; break; - case NEU_JSON_BYTES: - cmd->groups[i].tags[k].value.type = NEU_TYPE_BYTES; - cmd->groups[i].tags[k].value.value.bytes.length = - req->groups[i].tags[k].value.val_bytes.length; - memcpy(cmd->groups[i].tags[k].value.value.bytes.bytes, - req->groups[i].tags[k].value.val_bytes.bytes, - req->groups[i].tags[k].value.val_bytes.length); + case NEU_JSON_ARRAY_INT64: + cmd->groups[i].tags[k].value.type = NEU_TYPE_ARRAY_INT64; + cmd->groups[i].tags[k].value.value.i64s.length = + req->groups[i].tags[k].value.val_array_int64.length; + for (int j = 0; + j < req->groups[i].tags[k].value.val_array_int64.length; + j++) { + cmd->groups[i].tags[k].value.value.i64s.i64s[j] = + req->groups[i].tags[k].value.val_array_int64.i64s[j]; + } + break; + case NEU_JSON_ARRAY_DOUBLE: + cmd->groups[i].tags[k].value.type = NEU_TYPE_ARRAY_DOUBLE; + cmd->groups[i].tags[k].value.value.f64s.length = + req->groups[i].tags[k].value.val_array_double.length; + for (int j = 0; + j < req->groups[i].tags[k].value.val_array_double.length; + j++) { + cmd->groups[i].tags[k].value.value.f64s.f64s[j] = + req->groups[i].tags[k].value.val_array_double.f64s[j]; + } + break; + case NEU_JSON_ARRAY_BOOL: + cmd->groups[i].tags[k].value.type = NEU_TYPE_ARRAY_BOOL; + cmd->groups[i].tags[k].value.value.bools.length = + req->groups[i].tags[k].value.val_array_bool.length; + for (int j = 0; + j < req->groups[i].tags[k].value.val_array_bool.length; + j++) { + cmd->groups[i].tags[k].value.value.bools.bools[j] = + req->groups[i].tags[k].value.val_array_bool.bools[j]; + } break; default: assert(false); diff --git a/src/adapter/driver/cache.c b/src/adapter/driver/cache.c index 0c7373cfe..14e35c387 100644 --- a/src/adapter/driver/cache.c +++ b/src/adapter/driver/cache.c @@ -243,6 +243,7 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache, case NEU_TYPE_WORD: case NEU_TYPE_DWORD: case NEU_TYPE_LWORD: + case NEU_TYPE_ARRAY_CHAR: if (memcmp(&elem->value_old.value, &value.value, sizeof(value.value)) != 0) { elem->changed = true; @@ -260,6 +261,132 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache, } } break; + case NEU_TYPE_ARRAY_BOOL: + if (elem->value_old.value.bools.length != + value.value.bools.length) { + elem->changed = true; + } else { + if (memcmp(elem->value_old.value.bools.bools, + value.value.bools.bools, + value.value.bools.length) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_INT8: + if (elem->value_old.value.i8s.length != + value.value.i8s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value_old.value.i8s.i8s, + value.value.i8s.i8s, + value.value.i8s.length) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_INT16: + if (elem->value_old.value.i16s.length != + value.value.i16s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value_old.value.i16s.i16s, + value.value.i16s.i16s, + value.value.i16s.length * sizeof(int16_t)) != + 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_UINT16: + if (elem->value_old.value.u16s.length != + value.value.u16s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value_old.value.u16s.u16s, + value.value.u16s.u16s, + value.value.u16s.length * sizeof(uint16_t)) != + 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_INT32: + if (elem->value_old.value.i32s.length != + value.value.i32s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value_old.value.i32s.i32s, + value.value.i32s.i32s, + value.value.i32s.length * sizeof(int32_t)) != + 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_UINT32: + if (elem->value_old.value.u32s.length != + value.value.u32s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value_old.value.u32s.u32s, + value.value.u32s.u32s, + value.value.u32s.length * sizeof(uint32_t)) != + 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_INT64: + if (elem->value_old.value.i64s.length != + value.value.i64s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value_old.value.i64s.i64s, + value.value.i64s.i64s, + value.value.i64s.length * sizeof(int64_t)) != + 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_UINT64: + if (elem->value_old.value.u64s.length != + value.value.u64s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value_old.value.u64s.u64s, + value.value.u64s.u64s, + value.value.u64s.length * sizeof(uint64_t)) != + 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_FLOAT: + if (elem->value_old.value.f32s.length != + value.value.f32s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value_old.value.f32s.f32s, + value.value.f32s.f32s, + value.value.f32s.length * sizeof(float)) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_DOUBLE: + if (elem->value_old.value.f64s.length != + value.value.f64s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value_old.value.f64s.f64s, + value.value.f64s.f64s, + value.value.f64s.length * sizeof(double)) != 0) { + elem->changed = true; + } + } + break; case NEU_TYPE_CUSTOM: { if (json_equal(elem->value_old.value.json, value.value.json) != 0) { @@ -325,6 +452,7 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache, case NEU_TYPE_WORD: case NEU_TYPE_DWORD: case NEU_TYPE_LWORD: + case NEU_TYPE_ARRAY_CHAR: if (memcmp(&elem->value.value, &value.value, sizeof(value.value)) != 0) { elem->changed = true; @@ -342,6 +470,116 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache, } } break; + case NEU_TYPE_ARRAY_BOOL: + if (elem->value.value.bools.length != + value.value.bools.length) { + elem->changed = true; + } else { + if (memcmp(elem->value.value.bools.bools, + value.value.bools.bools, + value.value.bools.length) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_INT8: + if (elem->value.value.i8s.length != value.value.i8s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value.value.i8s.i8s, value.value.i8s.i8s, + value.value.i8s.length) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_INT16: + if (elem->value.value.i16s.length != value.value.i16s.length) { + elem->changed = true; + } else { + if (memcmp( + elem->value.value.i16s.i16s, value.value.i16s.i16s, + value.value.i16s.length * sizeof(int16_t)) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_UINT16: + if (elem->value.value.u16s.length != value.value.u16s.length) { + elem->changed = true; + } else { + if (memcmp( + elem->value.value.u16s.u16s, value.value.u16s.u16s, + value.value.u16s.length * sizeof(uint16_t)) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_INT32: + if (elem->value.value.i32s.length != value.value.i32s.length) { + elem->changed = true; + } else { + if (memcmp( + elem->value.value.i32s.i32s, value.value.i32s.i32s, + value.value.i32s.length * sizeof(int32_t)) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_UINT32: + if (elem->value.value.u32s.length != value.value.u32s.length) { + elem->changed = true; + } else { + if (memcmp( + elem->value.value.u32s.u32s, value.value.u32s.u32s, + value.value.u32s.length * sizeof(uint32_t)) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_INT64: + if (elem->value.value.i64s.length != value.value.i64s.length) { + elem->changed = true; + } else { + if (memcmp( + elem->value.value.i64s.i64s, value.value.i64s.i64s, + value.value.i64s.length * sizeof(int64_t)) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_UINT64: + if (elem->value.value.u64s.length != value.value.u64s.length) { + elem->changed = true; + } else { + if (memcmp( + elem->value.value.u64s.u64s, value.value.u64s.u64s, + value.value.u64s.length * sizeof(uint64_t)) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_FLOAT: + if (elem->value.value.f32s.length != value.value.f32s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value.value.f32s.f32s, + value.value.f32s.f32s, + value.value.f32s.length * sizeof(float)) != 0) { + elem->changed = true; + } + } + break; + case NEU_TYPE_ARRAY_DOUBLE: + if (elem->value.value.f64s.length != value.value.f64s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value.value.f64s.f64s, + value.value.f64s.f64s, + value.value.f64s.length * sizeof(double)) != 0) { + elem->changed = true; + } + } + break; case NEU_TYPE_PTR: { if (elem->value.value.ptr.length != value.value.ptr.length) { elem->changed = true; @@ -487,6 +725,7 @@ int neu_driver_cache_meta_get(neu_driver_cache_t *cache, const char *group, case NEU_TYPE_STRING: case NEU_TYPE_TIME: case NEU_TYPE_DATA_AND_TIME: + case NEU_TYPE_ARRAY_CHAR: memcpy(value->value.value.str, elem->value.value.str, sizeof(elem->value.value.str)); break; @@ -496,6 +735,57 @@ int neu_driver_cache_meta_get(neu_driver_cache_t *cache, const char *group, elem->value.value.bytes.bytes, elem->value.value.bytes.length); break; + case NEU_TYPE_ARRAY_BOOL: + value->value.value.bools.length = elem->value.value.bools.length; + memcpy(value->value.value.bools.bools, + elem->value.value.bools.bools, + elem->value.value.bools.length); + break; + case NEU_TYPE_ARRAY_INT8: + value->value.value.i8s.length = elem->value.value.i8s.length; + memcpy(value->value.value.i8s.i8s, elem->value.value.i8s.i8s, + elem->value.value.i8s.length); + break; + case NEU_TYPE_ARRAY_INT16: + value->value.value.i16s.length = elem->value.value.i16s.length; + memcpy(value->value.value.i16s.i16s, elem->value.value.i16s.i16s, + elem->value.value.i16s.length * sizeof(int16_t)); + break; + case NEU_TYPE_ARRAY_UINT16: + value->value.value.u16s.length = elem->value.value.u16s.length; + memcpy(value->value.value.u16s.u16s, elem->value.value.u16s.u16s, + elem->value.value.u16s.length * sizeof(uint16_t)); + break; + case NEU_TYPE_ARRAY_INT32: + value->value.value.i32s.length = elem->value.value.i32s.length; + memcpy(value->value.value.i32s.i32s, elem->value.value.i32s.i32s, + elem->value.value.i32s.length * sizeof(int32_t)); + break; + case NEU_TYPE_ARRAY_UINT32: + value->value.value.u32s.length = elem->value.value.u32s.length; + memcpy(value->value.value.u32s.u32s, elem->value.value.u32s.u32s, + elem->value.value.u32s.length * sizeof(uint32_t)); + break; + case NEU_TYPE_ARRAY_INT64: + value->value.value.i64s.length = elem->value.value.i64s.length; + memcpy(value->value.value.i64s.i64s, elem->value.value.i64s.i64s, + elem->value.value.i64s.length * sizeof(int64_t)); + break; + case NEU_TYPE_ARRAY_UINT64: + value->value.value.u64s.length = elem->value.value.u64s.length; + memcpy(value->value.value.u64s.u64s, elem->value.value.u64s.u64s, + elem->value.value.u64s.length * sizeof(uint64_t)); + break; + case NEU_TYPE_ARRAY_FLOAT: + value->value.value.f32s.length = elem->value.value.f32s.length; + memcpy(value->value.value.f32s.f32s, elem->value.value.f32s.f32s, + elem->value.value.f32s.length * sizeof(float)); + break; + case NEU_TYPE_ARRAY_DOUBLE: + value->value.value.f64s.length = elem->value.value.f64s.length; + memcpy(value->value.value.f64s.f64s, elem->value.value.f64s.f64s, + elem->value.value.f64s.length * sizeof(double)); + break; case NEU_TYPE_PTR: value->value.value.ptr.length = elem->value.value.ptr.length; value->value.value.ptr.type = elem->value.value.ptr.type; @@ -574,6 +864,7 @@ int neu_driver_cache_meta_get_changed(neu_driver_cache_t *cache, case NEU_TYPE_STRING: case NEU_TYPE_TIME: case NEU_TYPE_DATA_AND_TIME: + case NEU_TYPE_ARRAY_CHAR: memcpy(value->value.value.str, elem->value.value.str, sizeof(elem->value.value.str)); break; @@ -583,6 +874,57 @@ int neu_driver_cache_meta_get_changed(neu_driver_cache_t *cache, elem->value.value.bytes.bytes, elem->value.value.bytes.length); break; + case NEU_TYPE_ARRAY_BOOL: + value->value.value.bools.length = elem->value.value.bools.length; + memcpy(value->value.value.bools.bools, + elem->value.value.bools.bools, + elem->value.value.bools.length); + break; + case NEU_TYPE_ARRAY_INT8: + value->value.value.i8s.length = elem->value.value.i8s.length; + memcpy(value->value.value.i8s.i8s, elem->value.value.i8s.i8s, + elem->value.value.i8s.length); + break; + case NEU_TYPE_ARRAY_INT16: + value->value.value.i16s.length = elem->value.value.i16s.length; + memcpy(value->value.value.i16s.i16s, elem->value.value.i16s.i16s, + elem->value.value.i16s.length * sizeof(int16_t)); + break; + case NEU_TYPE_ARRAY_UINT16: + value->value.value.u16s.length = elem->value.value.u16s.length; + memcpy(value->value.value.u16s.u16s, elem->value.value.u16s.u16s, + elem->value.value.u16s.length * sizeof(uint16_t)); + break; + case NEU_TYPE_ARRAY_INT32: + value->value.value.i32s.length = elem->value.value.i32s.length; + memcpy(value->value.value.i32s.i32s, elem->value.value.i32s.i32s, + elem->value.value.i32s.length * sizeof(int32_t)); + break; + case NEU_TYPE_ARRAY_UINT32: + value->value.value.u32s.length = elem->value.value.u32s.length; + memcpy(value->value.value.u32s.u32s, elem->value.value.u32s.u32s, + elem->value.value.u32s.length * sizeof(uint32_t)); + break; + case NEU_TYPE_ARRAY_INT64: + value->value.value.i64s.length = elem->value.value.i64s.length; + memcpy(value->value.value.i64s.i64s, elem->value.value.i64s.i64s, + elem->value.value.i64s.length * sizeof(int64_t)); + break; + case NEU_TYPE_ARRAY_UINT64: + value->value.value.u64s.length = elem->value.value.u64s.length; + memcpy(value->value.value.u64s.u64s, elem->value.value.u64s.u64s, + elem->value.value.u64s.length * sizeof(uint64_t)); + break; + case NEU_TYPE_ARRAY_FLOAT: + value->value.value.f32s.length = elem->value.value.f32s.length; + memcpy(value->value.value.f32s.f32s, elem->value.value.f32s.f32s, + elem->value.value.f32s.length * sizeof(float)); + break; + case NEU_TYPE_ARRAY_DOUBLE: + value->value.value.f64s.length = elem->value.value.f64s.length; + memcpy(value->value.value.f64s.f64s, elem->value.value.f64s.f64s, + elem->value.value.f64s.length * sizeof(double)); + break; case NEU_TYPE_PTR: value->value.value.ptr.length = elem->value.value.ptr.length; value->value.value.ptr.type = elem->value.value.ptr.type; diff --git a/src/adapter/driver/driver.c b/src/adapter/driver/driver.c index 6021bf85d..049cd7315 100644 --- a/src/adapter/driver/driver.c +++ b/src/adapter/driver/driver.c @@ -1117,6 +1117,131 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver, (double) cmd->tags[i].value.value.i64; } } + if (tag->type == NEU_TYPE_BYTES) { + if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + for (int j = 0; j < cmd->tags[i].value.value.i64s.length; + j++) { + cmd->tags[i].value.value.bytes.bytes[j] = + (uint8_t) cmd->tags[i].value.value.i64s.i64s[j]; + } + for (int j = cmd->tags[i].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->tags[i].value.value.bytes.bytes[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_INT8) { + if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + for (int j = 0; j < cmd->tags[i].value.value.i64s.length; + j++) { + cmd->tags[i].value.value.i8s.i8s[j] = + (int8_t) cmd->tags[i].value.value.i64s.i64s[j]; + } + for (int j = cmd->tags[i].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->tags[i].value.value.i8s.i8s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_INT16) { + if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + for (int j = 0; j < cmd->tags[i].value.value.i64s.length; + j++) { + cmd->tags[i].value.value.i16s.i16s[j] = + (int16_t) cmd->tags[i].value.value.i64s.i64s[j]; + } + for (int j = cmd->tags[i].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->tags[i].value.value.i16s.i16s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_UINT16) { + if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + for (int j = 0; j < cmd->tags[i].value.value.i64s.length; + j++) { + cmd->tags[i].value.value.u16s.u16s[j] = + (uint16_t) cmd->tags[i].value.value.i64s.i64s[j]; + } + for (int j = cmd->tags[i].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->tags[i].value.value.u16s.u16s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_INT32) { + if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + for (int j = 0; j < cmd->tags[i].value.value.i64s.length; + j++) { + cmd->tags[i].value.value.i32s.i32s[j] = + (int32_t) cmd->tags[i].value.value.i64s.i64s[j]; + } + for (int j = cmd->tags[i].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->tags[i].value.value.i32s.i32s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_UINT32) { + if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + for (int j = 0; j < cmd->tags[i].value.value.i64s.length; + j++) { + cmd->tags[i].value.value.u32s.u32s[j] = + (uint32_t) cmd->tags[i].value.value.i64s.i64s[j]; + } + for (int j = cmd->tags[i].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->tags[i].value.value.u32s.u32s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_UINT64) { + if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + for (int j = 0; j < cmd->tags[i].value.value.i64s.length; + j++) { + cmd->tags[i].value.value.u64s.u64s[i] = + (uint64_t) cmd->tags[i].value.value.i64s.i64s[j]; + } + for (int j = cmd->tags[i].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->tags[i].value.value.u64s.u64s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_FLOAT) { + if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_DOUBLE) { + for (int j = 0; j < cmd->tags[i].value.value.f64s.length; + j++) { + cmd->tags[i].value.value.f32s.f32s[j] = + (float) cmd->tags[i].value.value.f64s.f64s[j]; + } + for (int j = cmd->tags[i].value.value.f64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->tags[i].value.value.f32s.f32s[j] = 0; + } + } + if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + for (int j = 0; j < cmd->tags[i].value.value.f64s.length; + j++) { + cmd->tags[i].value.value.f32s.f32s[j] = + (float) cmd->tags[i].value.value.i64s.i64s[j]; + } + for (int j = cmd->tags[i].value.value.f64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->tags[i].value.value.f32s.f32s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_DOUBLE) { + if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + for (int j = 0; j < cmd->tags[i].value.value.i64s.length; + j++) { + cmd->tags[i].value.value.f64s.f64s[j] = + (double) cmd->tags[i].value.value.i64s.i64s[j]; + } + } + } + if (tag->decimal != 0) { cal_decimal(tag->type, cmd->tags[i].value.type, &cmd->tags[i].value.value, tag->decimal); @@ -1232,6 +1357,181 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver, (double) cmd->groups[i].tags[k].value.value.i64; } } + if (tag->type == NEU_TYPE_BYTES) { + if (cmd->groups[i].tags[k].value.type == + NEU_TYPE_ARRAY_INT64) { + for (int j = 0; + j < cmd->groups[i].tags[k].value.value.i64s.length; + j++) { + cmd->groups[i].tags[k].value.value.bytes.bytes[j] = + (uint8_t) cmd->groups[i] + .tags[k] + .value.value.i64s.i64s[j]; + } + for (int j = + cmd->groups[i].tags[k].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->groups[i].tags[k].value.value.bytes.bytes[j] = + 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_INT8) { + if (cmd->groups[i].tags[k].value.type == + NEU_TYPE_ARRAY_INT64) { + for (int j = 0; + j < cmd->groups[i].tags[k].value.value.i64s.length; + j++) { + cmd->groups[i].tags[k].value.value.i8s.i8s[j] = + (int8_t) cmd->groups[i] + .tags[k] + .value.value.i64s.i64s[j]; + } + for (int j = + cmd->groups[i].tags[k].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->groups[i].tags[k].value.value.i8s.i8s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_INT16) { + if (cmd->groups[i].tags[k].value.type == + NEU_TYPE_ARRAY_INT64) { + for (int j = 0; + j < cmd->groups[i].tags[k].value.value.i64s.length; + j++) { + cmd->groups[i].tags[k].value.value.i16s.i16s[j] = + (int16_t) cmd->groups[i] + .tags[k] + .value.value.i64s.i64s[j]; + } + for (int j = + cmd->groups[i].tags[k].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->groups[i].tags[k].value.value.i16s.i16s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_UINT16) { + if (cmd->groups[i].tags[k].value.type == + NEU_TYPE_ARRAY_INT64) { + for (int j = 0; + j < cmd->groups[i].tags[k].value.value.i64s.length; + j++) { + cmd->groups[i].tags[k].value.value.u16s.u16s[j] = + (uint16_t) cmd->groups[i] + .tags[k] + .value.value.i64s.i64s[j]; + } + for (int j = + cmd->groups[i].tags[k].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->groups[i].tags[k].value.value.u16s.u16s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_INT32) { + if (cmd->groups[i].tags[k].value.type == + NEU_TYPE_ARRAY_INT64) { + for (int j = 0; + j < cmd->groups[i].tags[k].value.value.i64s.length; + j++) { + cmd->groups[i].tags[k].value.value.i32s.i32s[j] = + (int32_t) cmd->groups[i] + .tags[k] + .value.value.i64s.i64s[j]; + } + for (int j = + cmd->groups[i].tags[k].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->groups[i].tags[k].value.value.i32s.i32s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_UINT32) { + if (cmd->groups[i].tags[k].value.type == + NEU_TYPE_ARRAY_INT64) { + for (int j = 0; + j < cmd->groups[i].tags[k].value.value.i64s.length; + j++) { + cmd->groups[i].tags[k].value.value.u32s.u32s[j] = + (uint32_t) cmd->groups[i] + .tags[k] + .value.value.i64s.i64s[j]; + } + for (int j = + cmd->groups[i].tags[k].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->groups[i].tags[k].value.value.u32s.u32s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_UINT64) { + if (cmd->groups[i].tags[k].value.type == + NEU_TYPE_ARRAY_INT64) { + for (int j = 0; + j < cmd->groups[i].tags[k].value.value.i64s.length; + j++) { + cmd->groups[i].tags[k].value.value.u64s.u64s[j] = + (uint64_t) cmd->groups[i] + .tags[k] + .value.value.i64s.i64s[j]; + } + for (int j = + cmd->groups[i].tags[k].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->groups[i].tags[k].value.value.u64s.u64s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_FLOAT) { + if (cmd->groups[i].tags[k].value.type == + NEU_TYPE_ARRAY_DOUBLE) { + for (int j = 0; + j < cmd->groups[i].tags[k].value.value.f64s.length; + j++) { + cmd->groups[i].tags[k].value.value.f32s.f32s[j] = + (float) cmd->groups[i] + .tags[k] + .value.value.f64s.f64s[j]; + } + for (int j = + cmd->groups[i].tags[k].value.value.f64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->groups[i].tags[k].value.value.f32s.f32s[j] = 0; + } + } + if (cmd->groups[i].tags[k].value.type == + NEU_TYPE_ARRAY_INT64) { + for (int j = 0; + j < cmd->groups[i].tags[k].value.value.f64s.length; + j++) { + cmd->groups[i].tags[k].value.value.f32s.f32s[j] = + (float) cmd->groups[i] + .tags[k] + .value.value.i64s.i64s[j]; + } + for (int j = + cmd->groups[i].tags[k].value.value.f64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->groups[i].tags[k].value.value.f32s.f32s[j] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_DOUBLE) { + if (cmd->groups[i].tags[k].value.type == + NEU_TYPE_ARRAY_INT64) { + for (int j = 0; + j < cmd->groups[i].tags[k].value.value.i64s.length; + j++) { + cmd->groups[i].tags[k].value.value.f64s.f64s[j] = + (double) cmd->groups[i] + .tags[k] + .value.value.i64s.i64s[j]; + } + } + } + if (tag->decimal != 0) { cal_decimal(tag->type, cmd->groups[i].tags[k].value.type, &cmd->groups[i].tags[k].value.value, @@ -1338,6 +1638,120 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver, cmd->value.value.d64 = (double) cmd->value.value.i64; } } + if (tag->type == NEU_TYPE_BYTES) { + if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + for (int i = 0; i < cmd->value.value.i64s.length; i++) { + cmd->value.value.bytes.bytes[i] = + (uint8_t) cmd->value.value.i64s.i64s[i]; + } + for (int i = cmd->value.value.i64s.length; i < NEU_VALUE_SIZE; + i++) { + cmd->value.value.bytes.bytes[i] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_INT8) { + if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + for (int i = 0; i < cmd->value.value.i64s.length; i++) { + cmd->value.value.i8s.i8s[i] = + (int8_t) cmd->value.value.i64s.i64s[i]; + } + for (int i = cmd->value.value.i64s.length; i < NEU_VALUE_SIZE; + i++) { + cmd->value.value.i8s.i8s[i] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_INT16) { + if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + for (int i = 0; i < cmd->value.value.i64s.length; i++) { + cmd->value.value.i16s.i16s[i] = + (int16_t) cmd->value.value.i64s.i64s[i]; + } + for (int i = cmd->value.value.i64s.length; i < NEU_VALUE_SIZE; + i++) { + cmd->value.value.i16s.i16s[i] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_UINT16) { + if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + for (int i = 0; i < cmd->value.value.i64s.length; i++) { + cmd->value.value.u16s.u16s[i] = + (uint16_t) cmd->value.value.i64s.i64s[i]; + } + for (int i = cmd->value.value.i64s.length; i < NEU_VALUE_SIZE; + i++) { + cmd->value.value.u16s.u16s[i] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_INT32) { + if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + for (int i = 0; i < cmd->value.value.i64s.length; i++) { + cmd->value.value.i32s.i32s[i] = + (int32_t) cmd->value.value.i64s.i64s[i]; + } + for (int i = cmd->value.value.i64s.length; i < NEU_VALUE_SIZE; + i++) { + cmd->value.value.i32s.i32s[i] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_UINT32) { + if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + for (int i = 0; i < cmd->value.value.i64s.length; i++) { + cmd->value.value.u32s.u32s[i] = + (uint32_t) cmd->value.value.i64s.i64s[i]; + } + for (int i = cmd->value.value.i64s.length; i < NEU_VALUE_SIZE; + i++) { + cmd->value.value.u32s.u32s[i] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_UINT64) { + if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + for (int i = 0; i < cmd->value.value.i64s.length; i++) { + cmd->value.value.u64s.u64s[i] = + (uint64_t) cmd->value.value.i64s.i64s[i]; + } + for (int i = cmd->value.value.i64s.length; i < NEU_VALUE_SIZE; + i++) { + cmd->value.value.u64s.u64s[i] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_FLOAT) { + if (cmd->value.type == NEU_TYPE_ARRAY_DOUBLE) { + for (int i = 0; i < cmd->value.value.f64s.length; i++) { + cmd->value.value.f32s.f32s[i] = + (float) cmd->value.value.f64s.f64s[i]; + } + for (int i = cmd->value.value.f64s.length; i < NEU_VALUE_SIZE; + i++) { + cmd->value.value.f32s.f32s[i] = 0; + } + } + if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + for (int i = 0; i < cmd->value.value.f64s.length; i++) { + cmd->value.value.f32s.f32s[i] = + (float) cmd->value.value.i64s.i64s[i]; + } + for (int i = cmd->value.value.i64s.length; i < NEU_VALUE_SIZE; + i++) { + cmd->value.value.f32s.f32s[i] = 0; + } + } + } + if (tag->type == NEU_TYPE_ARRAY_DOUBLE) { + if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + for (int i = 0; i < cmd->value.value.i64s.length; i++) { + cmd->value.value.f64s.f64s[i] = + (double) cmd->value.value.i64s.i64s[i]; + } + } + } if (tag->decimal != 0) { cal_decimal(tag->type, cmd->value.type, &cmd->value.value, diff --git a/src/parser/neu_json_rw.c b/src/parser/neu_json_rw.c index 87a2d61b7..f14e7e394 100644 --- a/src/parser/neu_json_rw.c +++ b/src/parser/neu_json_rw.c @@ -383,8 +383,47 @@ void neu_json_decode_write_req_free(neu_json_write_req_t *req) if (req->t == NEU_JSON_STR) { free(req->value.val_str); } - if (req->t == NEU_JSON_BYTES && req->value.val_bytes.length > 0) { - free(req->value.val_bytes.bytes); + if (req->t == NEU_JSON_ARRAY_INT8 && req->value.val_array_int8.length > 0) { + free(req->value.val_array_int8.i8s); + } + if (req->t == NEU_JSON_ARRAY_UINT8 && + req->value.val_array_uint8.length > 0) { + free(req->value.val_array_uint8.u8s); + } + if (req->t == NEU_JSON_ARRAY_INT16 && + req->value.val_array_int16.length > 0) { + free(req->value.val_array_int16.i16s); + } + if (req->t == NEU_JSON_ARRAY_UINT16 && + req->value.val_array_uint16.length > 0) { + free(req->value.val_array_uint16.u16s); + } + if (req->t == NEU_JSON_ARRAY_INT32 && + req->value.val_array_int32.length > 0) { + free(req->value.val_array_int32.i32s); + } + if (req->t == NEU_JSON_ARRAY_UINT32 && + req->value.val_array_uint32.length > 0) { + free(req->value.val_array_uint32.u32s); + } + if (req->t == NEU_JSON_ARRAY_INT64 && + req->value.val_array_int64.length > 0) { + free(req->value.val_array_int64.i64s); + } + if (req->t == NEU_JSON_ARRAY_UINT64 && + req->value.val_array_uint64.length > 0) { + free(req->value.val_array_uint64.u64s); + } + if (req->t == NEU_JSON_ARRAY_FLOAT && + req->value.val_array_float.length > 0) { + free(req->value.val_array_float.f32s); + } + if (req->t == NEU_JSON_ARRAY_DOUBLE && + req->value.val_array_double.length > 0) { + free(req->value.val_array_double.f64s); + } + if (req->t == NEU_JSON_ARRAY_BOOL && req->value.val_array_bool.length > 0) { + free(req->value.val_array_bool.bools); } free(req); @@ -503,9 +542,49 @@ void neu_json_decode_write_tags_req_free(neu_json_write_tags_req_t *req) if (req->tags[i].t == NEU_JSON_STR) { free(req->tags[i].value.val_str); } - if (req->tags[i].t == NEU_JSON_BYTES && - req->tags[i].value.val_bytes.length > 0) { - free(req->tags[i].value.val_bytes.bytes); + if (req->tags[i].t == NEU_JSON_ARRAY_INT8 && + req->tags[i].value.val_array_int8.length > 0) { + free(req->tags[i].value.val_array_int8.i8s); + } + if (req->tags[i].t == NEU_JSON_ARRAY_UINT8 && + req->tags[i].value.val_array_uint8.length > 0) { + free(req->tags[i].value.val_array_uint8.u8s); + } + if (req->tags[i].t == NEU_JSON_ARRAY_INT16 && + req->tags[i].value.val_array_int16.length > 0) { + free(req->tags[i].value.val_array_int16.i16s); + } + if (req->tags[i].t == NEU_JSON_ARRAY_UINT16 && + req->tags[i].value.val_array_uint16.length > 0) { + free(req->tags[i].value.val_array_uint16.u16s); + } + if (req->tags[i].t == NEU_JSON_ARRAY_INT32 && + req->tags[i].value.val_array_int32.length > 0) { + free(req->tags[i].value.val_array_int32.i32s); + } + if (req->tags[i].t == NEU_JSON_ARRAY_UINT32 && + req->tags[i].value.val_array_uint32.length > 0) { + free(req->tags[i].value.val_array_uint32.u32s); + } + if (req->tags[i].t == NEU_JSON_ARRAY_INT64 && + req->tags[i].value.val_array_int64.length > 0) { + free(req->tags[i].value.val_array_int64.i64s); + } + if (req->tags[i].t == NEU_JSON_ARRAY_UINT64 && + req->tags[i].value.val_array_uint64.length > 0) { + free(req->tags[i].value.val_array_uint64.u64s); + } + if (req->tags[i].t == NEU_JSON_ARRAY_FLOAT && + req->tags[i].value.val_array_float.length > 0) { + free(req->tags[i].value.val_array_float.f32s); + } + if (req->tags[i].t == NEU_JSON_ARRAY_DOUBLE && + req->tags[i].value.val_array_double.length > 0) { + free(req->tags[i].value.val_array_double.f64s); + } + if (req->tags[i].t == NEU_JSON_ARRAY_BOOL && + req->tags[i].value.val_array_bool.length > 0) { + free(req->tags[i].value.val_array_bool.bools); } } free(req->tags); @@ -1171,9 +1250,49 @@ void neu_json_decode_write_gtags_req_free(neu_json_write_gtags_req_t *req) if (req->groups[i].tags[k].t == NEU_JSON_STR) { free(req->groups[i].tags[k].value.val_str); } - if (req->groups[i].tags[k].t == NEU_JSON_BYTES && - req->groups[i].tags[k].value.val_bytes.length > 0) { - free(req->groups[i].tags[k].value.val_bytes.bytes); + if (req->groups[i].tags[k].t == NEU_JSON_ARRAY_INT8 && + req->groups[i].tags[k].value.val_array_int8.length > 0) { + free(req->groups[i].tags[k].value.val_array_int8.i8s); + } + if (req->groups[i].tags[k].t == NEU_JSON_ARRAY_UINT8 && + req->groups[i].tags[k].value.val_array_uint8.length > 0) { + free(req->groups[i].tags[k].value.val_array_uint8.u8s); + } + if (req->groups[i].tags[k].t == NEU_JSON_ARRAY_INT16 && + req->groups[i].tags[k].value.val_array_int16.length > 0) { + free(req->groups[i].tags[k].value.val_array_int16.i16s); + } + if (req->groups[i].tags[k].t == NEU_JSON_ARRAY_UINT16 && + req->groups[i].tags[k].value.val_array_uint16.length > 0) { + free(req->groups[i].tags[k].value.val_array_uint16.u16s); + } + if (req->groups[i].tags[k].t == NEU_JSON_ARRAY_INT32 && + req->groups[i].tags[k].value.val_array_int32.length > 0) { + free(req->groups[i].tags[k].value.val_array_int32.i32s); + } + if (req->groups[i].tags[k].t == NEU_JSON_ARRAY_UINT32 && + req->groups[i].tags[k].value.val_array_uint32.length > 0) { + free(req->groups[i].tags[k].value.val_array_uint32.u32s); + } + if (req->groups[i].tags[k].t == NEU_JSON_ARRAY_INT64 && + req->groups[i].tags[k].value.val_array_int64.length > 0) { + free(req->groups[i].tags[k].value.val_array_int64.i64s); + } + if (req->groups[i].tags[k].t == NEU_JSON_ARRAY_UINT64 && + req->groups[i].tags[k].value.val_array_uint64.length > 0) { + free(req->groups[i].tags[k].value.val_array_uint64.u64s); + } + if (req->groups[i].tags[k].t == NEU_JSON_ARRAY_FLOAT && + req->groups[i].tags[k].value.val_array_float.length > 0) { + free(req->groups[i].tags[k].value.val_array_float.f32s); + } + if (req->groups[i].tags[k].t == NEU_JSON_ARRAY_DOUBLE && + req->groups[i].tags[k].value.val_array_double.length > 0) { + free(req->groups[i].tags[k].value.val_array_double.f64s); + } + if (req->groups[i].tags[k].t == NEU_JSON_ARRAY_BOOL && + req->groups[i].tags[k].value.val_array_bool.length > 0) { + free(req->groups[i].tags[k].value.val_array_bool.bools); } } if (req->groups[i].n_tag > 0) { diff --git a/src/utils/json.c b/src/utils/json.c index c8f731539..ef4e2424c 100644 --- a/src/utils/json.c +++ b/src/utils/json.c @@ -128,15 +128,125 @@ static json_t *encode_object(json_t *object, neu_json_elem_t ele) case NEU_JSON_BOOL: json_object_set_new(ob, ele.name, json_boolean(ele.v.val_bool)); break; - case NEU_JSON_BYTES: { - void *bytes = json_array(); + case NEU_JSON_ARRAY_BOOL: { + void *array = json_array(); - for (int i = 0; i < ele.v.val_bytes.length; i++) { - json_array_append_new(bytes, - json_integer(ele.v.val_bytes.bytes[i])); + for (int i = 0; i < ele.v.val_array_bool.length; i++) { + json_array_append_new(array, + json_boolean(ele.v.val_array_bool.bools[i])); } - json_object_set_new(ob, ele.name, bytes); + json_object_set_new(ob, ele.name, array); + break; + } + case NEU_JSON_ARRAY_INT8: { + void *array = json_array(); + + for (int i = 0; i < ele.v.val_array_int8.length; i++) { + json_array_append_new(array, + json_integer(ele.v.val_array_int8.i8s[i])); + } + + json_object_set_new(ob, ele.name, array); + break; + } + case NEU_JSON_ARRAY_UINT8: { + void *array = json_array(); + + for (int i = 0; i < ele.v.val_array_uint8.length; i++) { + json_array_append_new(array, + json_integer(ele.v.val_array_uint8.u8s[i])); + } + + json_object_set_new(ob, ele.name, array); + break; + } + case NEU_JSON_ARRAY_INT16: { + void *array = json_array(); + + for (int i = 0; i < ele.v.val_array_int16.length; i++) { + json_array_append_new(array, + json_integer(ele.v.val_array_int16.i16s[i])); + } + + json_object_set_new(ob, ele.name, array); + break; + } + case NEU_JSON_ARRAY_UINT16: { + void *array = json_array(); + + for (int i = 0; i < ele.v.val_array_uint16.length; i++) { + json_array_append_new(array, + json_integer(ele.v.val_array_uint16.u16s[i])); + } + + json_object_set_new(ob, ele.name, array); + break; + } + case NEU_JSON_ARRAY_INT32: { + void *array = json_array(); + + for (int i = 0; i < ele.v.val_array_int32.length; i++) { + json_array_append_new(array, + json_integer(ele.v.val_array_int32.i32s[i])); + } + + json_object_set_new(ob, ele.name, array); + break; + } + case NEU_JSON_ARRAY_UINT32: { + void *array = json_array(); + + for (int i = 0; i < ele.v.val_array_uint32.length; i++) { + json_array_append_new(array, + json_integer(ele.v.val_array_uint32.u32s[i])); + } + + json_object_set_new(ob, ele.name, array); + break; + } + case NEU_JSON_ARRAY_INT64: { + void *array = json_array(); + + for (int i = 0; i < ele.v.val_array_int64.length; i++) { + json_array_append_new(array, + json_integer(ele.v.val_array_int64.i64s[i])); + } + + json_object_set_new(ob, ele.name, array); + break; + } + case NEU_JSON_ARRAY_UINT64: { + void *array = json_array(); + + for (int i = 0; i < ele.v.val_array_uint64.length; i++) { + json_array_append_new(array, + json_integer(ele.v.val_array_uint64.u64s[i])); + } + + json_object_set_new(ob, ele.name, array); + break; + } + case NEU_JSON_ARRAY_FLOAT: { + void *array = json_array(); + + for (int i = 0; i < ele.v.val_array_float.length; i++) { + json_array_append_new(array, + json_real(ele.v.val_array_float.f32s[i])); + } + + json_object_set_new(ob, ele.name, array); + break; + } + case NEU_JSON_ARRAY_DOUBLE: { + void *array = json_array(); + + for (int i = 0; i < ele.v.val_array_double.length; i++) { + json_array_append_new(array, + json_real(ele.v.val_array_double.f64s[i])); + } + + json_object_set_new(ob, ele.name, array); break; } case NEU_JSON_OBJECT: @@ -181,7 +291,20 @@ static int decode_object(json_t *root, neu_json_elem_t *ele) } else if (json_is_integer(ob)) { ele->t = NEU_JSON_INT; } else if (json_is_array(ob)) { - ele->t = NEU_JSON_BYTES; + json_t *value = NULL; + int index = 0; + ele->t = NEU_JSON_ARRAY_INT64; + json_array_foreach(ob, index, value) + { + if (json_is_real(value)) { + ele->t = NEU_JSON_ARRAY_DOUBLE; + break; + } + if (json_is_boolean(value)) { + ele->t = NEU_JSON_ARRAY_BOOL; + break; + } + } } } @@ -221,19 +344,62 @@ static int decode_object(json_t *root, neu_json_elem_t *ele) case NEU_JSON_BOOL: ele->v.val_bool = json_boolean_value(ob); break; - case NEU_JSON_BYTES: { + case NEU_JSON_ARRAY_BOOL: { + json_t *value = NULL; + + ele->v.val_array_bool.length = json_array_size(ob); + if (ele->v.val_array_bool.length > 0) { + int index = 0; + + ele->v.val_array_bool.bools = + calloc(ele->v.val_array_bool.length, sizeof(bool)); + json_array_foreach(ob, index, value) + { + ele->v.val_array_bool.bools[index] = json_boolean_value(value); + } + } + break; + } + case NEU_JSON_ARRAY_INT64: { + json_t *value = NULL; + + ele->v.val_array_int64.length = json_array_size(ob); + if (ele->v.val_array_int64.length > 0) { + int index = 0; + + ele->v.val_array_int64.i64s = + calloc(ele->v.val_array_int64.length, sizeof(int64_t)); + json_array_foreach(ob, index, value) + { + if (json_is_real(value)) { + ele->v.val_array_int64.i64s[index] = + (int64_t) json_real_value(value); + } else { + ele->v.val_array_int64.i64s[index] = + json_integer_value(value); + } + } + } + break; + } + case NEU_JSON_ARRAY_DOUBLE: { json_t *value = NULL; - ele->v.val_bytes.length = json_array_size(ob); - if (ele->v.val_bytes.length > 0) { + ele->v.val_array_double.length = json_array_size(ob); + if (ele->v.val_array_double.length > 0) { int index = 0; - ele->v.val_bytes.bytes = - calloc(ele->v.val_bytes.length, sizeof(uint8_t)); + ele->v.val_array_double.f64s = + calloc(ele->v.val_array_double.length, sizeof(double)); json_array_foreach(ob, index, value) { - ele->v.val_bytes.bytes[index] = - (uint8_t) json_integer_value(value); + if (json_is_integer(value)) { + ele->v.val_array_double.f64s[index] = + (double) json_integer_value(value); + } else { + ele->v.val_array_double.f64s[index] = + json_real_value(value); + } } } break;