This commit is contained in:
mykola2312 2022-05-03 07:18:21 +03:00
parent de923a2a0d
commit f2b04e7514
2 changed files with 37 additions and 0 deletions

View file

@ -1,3 +1,32 @@
#include "struct.h" #include "struct.h"
#include "cutil.h"
uint struct_size(struct cu_struct_s* st, uint idx, uint8_t* in)
{
struct cu_value_s* value = &st->members[idx];
switch (value->type)
{
case NoValue: return 0;
case Sequence: return value->sequence.size;
//case Array:
case Int8: return VALUE_INT8_SIZE;
case Int16: return VALUE_INT16_SIZE;
case Int32: return VALUE_INT32_SIZE;
case Int64: return VALUE_INT64_SIZE;
default: return 0;
}
}
uint struct_offset(struct cu_struct_s* st, uint idx, uint8_t* in)
{
uint offset = 0;
do {
offset += struct_size(st, idx, in);
} while (idx--);
return offset;
}
uint struct_value(struct cu_struct_s* st, uint idx, uint8_t* in, uint8_t* out)
{
}

View file

@ -4,6 +4,11 @@
#include "cutypes.h" #include "cutypes.h"
#include "endian.h" #include "endian.h"
#define VALUE_INT8_SIZE sizeof(uint8_t)
#define VALUE_INT16_SIZE sizeof(uint16_t)
#define VALUE_INT32_SIZE sizeof(uint32_t)
#define VALUE_INT64_SIZE sizeof(uint64_t)
enum cu_value_type_e { enum cu_value_type_e {
NoValue, NoValue,
Sequence, Sequence,
@ -55,6 +60,9 @@ struct cu_struct_s {
typedef void (*cu_value_process_t)(struct cu_value_s* type, typedef void (*cu_value_process_t)(struct cu_value_s* type,
uint8_t* in, uint8_t* out); uint8_t* in, uint8_t* out);
uint struct_size(struct cu_struct_s* st, uint idx, uint8_t* in);
uint struct_offset(struct cu_struct_s* st, uint idx, uint8_t* in);
uint struct_value(struct cu_struct_s* st, uint idx, uint8_t* in, uint8_t* out);
void struct_process(struct cu_struct_s* st, cu_value_process_t p, void struct_process(struct cu_struct_s* st, cu_value_process_t p,
uint8_t* in, uint8_t* out); uint8_t* in, uint8_t* out);