This commit is contained in:
mykola2312 2022-05-03 01:13:03 +03:00
parent c3b659dce8
commit 1418709bdf
3 changed files with 66 additions and 0 deletions

View file

@ -8,6 +8,7 @@ set(HEADERS
array.h
bitmap.h
endian.h
struct.h
)
set(SOURCES
@ -16,6 +17,7 @@ set(SOURCES
array.c
bitmap.c
endian.c
struct.c
)
add_library(cutil STATIC ${SOURCES} ${HEADERS})

16
struct.c Normal file
View file

@ -0,0 +1,16 @@
#include "struct.h"
struct cu_value_s test_struct[] = {
{.type = Sequence, .sequence = {.size = 6}},
{.type = Array, .array = {.item = 4, .count = 12, .index = 0}},
{.type = Int16},
{.type = Array, .array = {.item = 14, .count = 3, .index = 1}},
{.type = NoValue}
};
/*CU_STRUCT_BEGIN(test)
CU_VALUE_SEQUENCE(6)
CU_VALUE_ARRAY(4, 12)
CU_VALUE_INT16()
CU_VALUE_ARRAY_INDEX(14, 3)
CU_STRUCT_END()*/

48
struct.h Normal file
View file

@ -0,0 +1,48 @@
#ifndef __STRUCT_H
#define __STRUCT_H
#include "cutypes.h"
enum cu_value_type_e {
NoValue,
Sequence,
Array,
Int8,
Int16,
Int32,
Int64
};
struct cu_value_s {
enum cu_value_type_e type;
union {
struct {
uint size;
} sequence;
struct {
uint item;
uint count : 31;
uint index : 1;
} array;
};
};
#define CU_STRUCT_BEGIN(name) \
struct cu_value_s cu_struct_##name[] = {
#define CU_STRUCT_END() \
{.type = NoValue}};
#define CU_VALUE_INT8() {.type = Int8},
#define CU_VALUE_INT16() {.type = Int16},
#define CU_VALUE_INT32() {.type = Int32},
#define CU_VALUE_INT64() {.type = Int64},
#define CU_VALUE_SEQUENCE(_size) \
{.type = Sequence, .sequence = {.size = (_size)},
#define CU_VALUE_ARRAY(_item, _count) \
{.type = Array, .array = {.item = (_item), .count = (_count), .index = 0}},
#define CU_VALUE_ARRAY_INDEX(_item, _index) \
{.type = Array, .array = {.item = (_item), .count = (_index), .index = 1}},
typedef void (*cu_value_operate)(struct cu_value_s* type,
uint8_t** in, uint8_t** out);
#endif