![]() |
|
Think about Loose Coupling | |
PerlMonks |
Re: Reading (and parsing) a byte streamby BrowserUk (Patriarch) |
on Mar 05, 2006 at 04:06 UTC ( [id://534558]=note: print w/replies, xml ) | Need Help?? |
Take a look at the use of the '/' in the documentation for pack, you can also use this format character in unpack. Basically, an unpack format of 'C/a', will read the byte value represented by the C, and then use that as the length specifier for the character following the '/'; in this case 'A' for ascii data. As you also need the length of the metadata in order to remove it from the stream, you'll need a template of "a$DATASIZE C X C/A", which will capture the data to the first variable, the length to the second, backup over the length byte and then use it to capture the metadata to the third variable. I've used a datasize of 10 and an array to simulate the read in this example. The critical part is exiting the while loop when there is not enough data left to fulfill the data size, then read the next lump and append it to the residual:
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Seekers of Perl Wisdom
|
|