Skip to content

Commit

Permalink
Merge pull request #2292 from fengzeroz/main
Browse files Browse the repository at this point in the history
support array type
  • Loading branch information
fengzeroz authored Nov 6, 2024
2 parents 2f04a34 + 8d90cb7 commit ec8d7c8
Show file tree
Hide file tree
Showing 11 changed files with 1,530 additions and 116 deletions.
92 changes: 81 additions & 11 deletions include/neuron/json/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
138 changes: 132 additions & 6 deletions include/neuron/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit ec8d7c8

Please sign in to comment.