Hi Folks,

In my case i am passing the void pointer which will be assigned with some memory to the firmware; in return firmware will fill this void pointer and returns.
My requirement is i have parse this filled data. But data filled by the firmware is complex.

e.g it will have following type of data :

struct1{
   total_size_filled  4 byte;
   Num_param          4 byte;
   struct2             VARIABLE SIZE;
}

struct2{
   size       4byte;
   type       4 byte;
   if(type == type1)
      struct_type1;       VARIABLE SIZE
   else if(type == type2)
      struct_type2;       VARIABLE SIZE
}

// consider type == type1

struct_type1{
   some_struct      12 byte;
   struct_type1_1   VARIABLE;
   struct_type1_2   VARIABLE;
}


struct_type1_1{
   some_var         4 byte;
   some_struct      16 byte;
}


struct_type1_2{
   some_var         2 byte;
   some_var         2 byte;
   some_struct      20 byte;
}

Now i have to parse the above filled data.. Can you please suggest me something..
Can i use tree or vector to ???

Don't use structures before reading the data, create a program to parse the data and load them into your OWN structures which you made.

So you read the blocks of data one known element at a time, and only copy the data you NEED for your program into your structures.

void *FirmwareStruct2 = GetFromFirmware();
void *s2ptr = FirmwareStruct2;

int Size = ((int *)(s2ptr + 0))[0];
int Type = ((int *)(s2ptr + 4))[0];

s2ptr = s2ptr + 8; // Now s2ptr points to the following struct_type

switch (Type) {
  case 1: // struct_type1
    // Load data the same way I did before
  break;
  case 2: // struct_type2
    // Load data the same way I did before
  break;
}

Thank you very much NIGHTS for your suggestions..
Definitely it will help me...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.