Parsing an Array and determining what is included

Hi, I'm trying to parse this hexadecimal array. I need to find the location of a "tag" which is followed by a data length byte. For example: 0x9F, 0x66, 0x04. 9F66 is the tag, and 04 is the data length. There are multiple tags in this array which have the same 1st byte, for example 9F66 and 9F02. I need to be able to generate a new array with the data each tag has requested in the order that the tags appear in the first array. I have uploaded the code I've managed to do so far, but it seems that the way I am using the for loop is incorrect. What I am trying to code is to go through the array, find a byte that matches 0x9F, then checking if the next byte equals 0x66 or 0x02, or any of the other second bytes. This code just assigns the length of the first tag to every other tag. Almost like it gets stuck on the first "i" that has success and just runs with it. Any help would be much appreciated as I've spent hours trying to figure this out.

int PDOL_response[] = {0x9F, 0x66, 0x04, 0x9F, 0x02, 0x06, 0x9F, 0x03, 0x06, 0x9F, 0x1A, 0x02};

void setup(){
  Serial.begin(9600);
}

void loop(){
for (int i = 0; i<sizeof(PDOL_response); i++){
if ((PDOL_response[i],HEX) == (0x9F,HEX) && (PDOL_response[i+1],HEX == (0x66,HEX))){
    Serial.println("9F66 Length:");
    Serial.println(PDOL_response[i+2],HEX);
    break;
  }
}

for (int i = 0; i<sizeof(PDOL_response); i++){
if ((PDOL_response[i],HEX) == (0x9F,HEX) && (PDOL_response[i+1],HEX == (0x02,HEX))){
    Serial.println("9F02 Length:");
    Serial.println(PDOL_response[i+2],HEX);
    break;
  }
}

for (int i = 0; i<sizeof(PDOL_response); i++){
if ((PDOL_response[i],HEX) == (0x9F,HEX) && (PDOL_response[i+1],HEX == (0x03,HEX))){
    Serial.println("9F03 Length:");
    Serial.println(PDOL_response[i+2],HEX);
    break;
  }
}
}

That's unusual syntax.

Numbers are numbers, there is no need to attempt to force comparison to happen in the hexadecimal realm.

    if (PDOL_response[i] == 0x9F) { // blah blah blah

a7

oh wow. your syntax change solved a whole lot of problems. Thankyou very much!

i've used TLVs a lot and trying to understand your application.

in my experience, that length is independent of the tag and simply indicate the size of the msg (either including the tag/length or not)

a big advantage of TLVs is that a search doesn't need to know anything about the other tags not being searched for, using the length to simply skip that tag.

and the length can vary for the same tag, for example a tag could identify a string describing something that may vary in length

in your case, it sounds like you array describes the length the of the message, the amount of data that needs to be put into the message instead of knowing the tag for a message and prepending it and the length when creating the msg.