Skip to content

Commit

Permalink
Merge pull request #2293 from fengzeroz/main
Browse files Browse the repository at this point in the history
uint8 array
  • Loading branch information
fengzeroz authored Nov 7, 2024
2 parents ec8d7c8 + 1982dac commit b5784a9
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 9 deletions.
12 changes: 12 additions & 0 deletions include/neuron/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,12 @@ static inline void neu_tag_value_to_json(neu_resp_tag_value_meta_t *tag_value,
tag_value->value.value.i8s.length;
tag_json->value.val_array_int8.i8s = tag_value->value.value.i8s.i8s;
break;
case NEU_TYPE_ARRAY_UINT8:
tag_json->t = NEU_JSON_ARRAY_UINT8;
tag_json->value.val_array_uint8.length =
tag_value->value.value.u8s.length;
tag_json->value.val_array_uint8.u8s = tag_value->value.value.u8s.u8s;
break;
case NEU_TYPE_ARRAY_INT16:
tag_json->t = NEU_JSON_ARRAY_INT16;
tag_json->value.val_array_int16.length =
Expand Down Expand Up @@ -1190,6 +1196,12 @@ neu_tag_value_to_json_paginate(neu_resp_tag_value_meta_paginate_t *tag_value,
tag_value->value.value.i8s.length;
tag_json->value.val_array_int8.i8s = tag_value->value.value.i8s.i8s;
break;
case NEU_TYPE_ARRAY_UINT8:
tag_json->t = NEU_JSON_ARRAY_UINT8;
tag_json->value.val_array_uint8.length =
tag_value->value.value.u8s.length;
tag_json->value.val_array_uint8.u8s = tag_value->value.value.u8s.u8s;
break;
case NEU_TYPE_ARRAY_INT16:
tag_json->t = NEU_JSON_ARRAY_INT16;
tag_json->value.val_array_int16.length =
Expand Down
27 changes: 18 additions & 9 deletions include/neuron/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ typedef enum {
NEU_TYPE_DATA_AND_TIME = 21,
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_ARRAY_UINT8 = 24,
NEU_TYPE_ARRAY_INT16 = 25,
NEU_TYPE_ARRAY_UINT16 = 26,
NEU_TYPE_ARRAY_INT32 = 27,
NEU_TYPE_ARRAY_UINT32 = 28,
NEU_TYPE_ARRAY_INT64 = 29,
NEU_TYPE_ARRAY_UINT64 = 30,
NEU_TYPE_ARRAY_FLOAT = 31,
NEU_TYPE_ARRAY_DOUBLE = 32,
NEU_TYPE_ARRAY_BOOL = 33,
NEU_TYPE_CUSTOM = 40,
} neu_type_e;

Expand Down Expand Up @@ -117,6 +118,8 @@ inline static const char *neu_type_string(neu_type_e type)
return "NEU_TYPE_ARRAY_CHAR";
case NEU_TYPE_ARRAY_INT8:
return "NEU_TYPE_ARRAY_INT8";
case NEU_TYPE_ARRAY_UINT8:
return "NEU_TYPE_ARRAY_UINT8";
case NEU_TYPE_ARRAY_INT16:
return "NEU_TYPE_ARRAY_INT16";
case NEU_TYPE_ARRAY_UINT16:
Expand Down Expand Up @@ -160,6 +163,11 @@ typedef struct {
uint8_t length;
} neu_value_array_int8_t;

typedef struct {
uint8_t u8s[NEU_VALUE_SIZE];
uint8_t length;
} neu_value_array_uint8_t;

typedef struct {
int16_t i16s[NEU_VALUE_SIZE];
uint8_t length;
Expand Down Expand Up @@ -222,6 +230,7 @@ typedef union {
neu_value_ptr_t ptr;
json_t * json;
neu_value_array_int8_t i8s;
neu_value_array_uint8_t u8s;
neu_value_array_int16_t i16s;
neu_value_array_uint16_t u16s;
neu_value_array_int32_t i32s;
Expand Down
32 changes: 32 additions & 0 deletions src/adapter/driver/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
}
}
break;
case NEU_TYPE_ARRAY_UINT8:
if (elem->value_old.value.u8s.length !=
value.value.u8s.length) {
elem->changed = true;
} else {
if (memcmp(elem->value_old.value.u8s.u8s,
value.value.u8s.u8s,
value.value.u8s.length) != 0) {
elem->changed = true;
}
}
break;
case NEU_TYPE_ARRAY_INT16:
if (elem->value_old.value.i16s.length !=
value.value.i16s.length) {
Expand Down Expand Up @@ -492,6 +504,16 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
}
}
break;
case NEU_TYPE_ARRAY_UINT8:
if (elem->value.value.u8s.length != value.value.u8s.length) {
elem->changed = true;
} else {
if (memcmp(elem->value.value.u8s.u8s, value.value.u8s.u8s,
value.value.u8s.length) != 0) {
elem->changed = true;
}
}
break;
case NEU_TYPE_ARRAY_INT16:
if (elem->value.value.i16s.length != value.value.i16s.length) {
elem->changed = true;
Expand Down Expand Up @@ -746,6 +768,11 @@ int neu_driver_cache_meta_get(neu_driver_cache_t *cache, const char *group,
memcpy(value->value.value.i8s.i8s, elem->value.value.i8s.i8s,
elem->value.value.i8s.length);
break;
case NEU_TYPE_ARRAY_UINT8:
value->value.value.u8s.length = elem->value.value.u8s.length;
memcpy(value->value.value.u8s.u8s, elem->value.value.u8s.u8s,
elem->value.value.u8s.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,
Expand Down Expand Up @@ -885,6 +912,11 @@ int neu_driver_cache_meta_get_changed(neu_driver_cache_t *cache,
memcpy(value->value.value.i8s.i8s, elem->value.value.i8s.i8s,
elem->value.value.i8s.length);
break;
case NEU_TYPE_ARRAY_UINT8:
value->value.value.u8s.length = elem->value.value.u8s.length;
memcpy(value->value.value.u8s.u8s, elem->value.value.u8s.u8s,
elem->value.value.u8s.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,
Expand Down
Loading

0 comments on commit b5784a9

Please sign in to comment.