12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

84 FLASH STREAM DECODER ANNOYANCE-FILTER §103<br />

103. Read the header for the next tag. Each tag begins with a 16 bit field which contains 10 bits<br />

of tag identifier and a 6 bit field specifying the number of argument bytes which follow. For tags with<br />

arguments of 0 to 62 bytes, the 6 bit field is the data length. For longer tags, the 6 bit length field is set<br />

of # 3F and a 32 bit quantity giving the tag data length immediately follows. Regardless of the format<br />

of the tag header, we store the tag type in tType and the number of data bytes in tDataLen .<br />

〈 Class implementations 11 〉 +≡<br />

bool flashStream ::nextTag (void)<br />

{<br />

unsigned short s = get16 ( );<br />

unsigned long l;<br />

}<br />

if (isOK ( )) {<br />

tType = static cast〈tagType 〉(s ≫ 6);<br />

l = s & # 3F;<br />

if (l ≡ # 3F) {<br />

l = get32 ( ); /∗ Long tag; read 32 bit length ∗/<br />

}<br />

if (isOK ( )) {<br />

tDataLen = l;<br />

return tType ≠ stagEnd ;<br />

}<br />

} /∗ In case of error dummy up end tag for sloppy callers ∗/<br />

tType = stagEnd ;<br />

tDataLen = 0;<br />

return false ;<br />

104. Having read the tag header, if we decide we aren’t interested in the tag, we can simply skip<br />

past tDataLen argument bytes to advance to the next tag header; ignoreTag performs this. If you’ve<br />

read into the tag data before deciding you wish to skip the tag, call ignoreTag with the lookedAhead<br />

argument specifying how many bytes of the tag data you’ve already read.<br />

〈 Class implementations 11 〉 +≡<br />

void flashStream ::ignoreTag (unsigned int lookedAhead )<br />

{<br />

if (isOK ( )) {<br />

/∗ assert(lookedAhead ¡= tDataLen); // (This assertion will fail if −−bsdfolder is set) ∗/<br />

for (unsigned int i = lookedAhead ; isOK ( ) ∧ (i < tDataLen ); i++) {<br />

get8 ( );<br />

}<br />

}<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!