From f2b04e7514f68ab2878b2923eea431945c5ebe0e Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Tue, 3 May 2022 07:18:21 +0300 Subject: [PATCH] struct 3 --- struct.c | 29 +++++++++++++++++++++++++++++ struct.h | 8 ++++++++ 2 files changed, 37 insertions(+) diff --git a/struct.c b/struct.c index 6477f7e..bf4a17c 100644 --- a/struct.c +++ b/struct.c @@ -1,3 +1,32 @@ #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) +{ + +} diff --git a/struct.h b/struct.h index 576adf3..4464d68 100644 --- a/struct.h +++ b/struct.h @@ -4,6 +4,11 @@ #include "cutypes.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 { NoValue, Sequence, @@ -55,6 +60,9 @@ struct cu_struct_s { typedef void (*cu_value_process_t)(struct cu_value_s* type, 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, uint8_t* in, uint8_t* out);