The variable-length hexadecimal data, how to parse processing good points:
01 4 00 00 00 00 00 03 00 00 00 00 00 05 . 3 00 00 00 00 00 00 00 00 08 3 . 00 00 00 00 00 08
Or
01 4 00 00 00 00 00 03 00 00 00 00 00 05 3 . 00 00 00 00 00 08
Part 1: red is the order 01,02,03
Part 2: green is a few 04 said is four values, 03 are three values, 02 said are two values (here is also changing)
3: behind every three to calculate a value; 00 00 00, 00 00 00 00 03, 00, 00 00 05
For example, 01 4 00 00 00 00 00 03 00 00 00 00 00 05
Format may exist in this command (01,02,03) also may not exist this command (01,02,03)
Now that I think about how to write a generic can parse apart the data, achieve this goal,
01 00 00 00 00 00 03, 00, 00 00 00 00 05
02 00 00 00 00 00 00 00 00 08
03 00 00 00 00 00 08
Please advice, thank you
CodePudding user response:
If is to determine the length and determine the position, can consider to create structure, then put these values (should be put in a cache, and the cache is char or unsigned char) cast structure variables, and then according to the change of value will decide how many bytes to read ~ behindCodePudding user response:
My main question is nowCodePudding user response:
Thank you, structures must use04 00 00 00 00 00 03 01 00 00 00 00 00 05 02 03 00 00 00 00 00 00 00 00 00 00 08 03 02 08 00 00 00
03 01, 02, there are probably there are likely to be one or two, how to determine the judgment, and exist, numerical number is not fixed, the command will also change, how the judgment is good, thank you
CodePudding user response:
Or this awkward situation:If you can describe the problem clearly, then you are solved,
Now that you describe is not clear, that others also don't know what the problem is, still can't solve,
CodePudding user response:
The tail yards or soStruct s {
Ch the tag;
int len;
Char * data;
}
while(! Eof)
//the begin
S s1;
Read (s1. The tag);
If (tag==1 | | tag==2 | | tag==3)
{
Read (s1. Len);
Read (s1) data, s1. Len);
}
//end;