[H]ow does the 'n n/A' know how many characters to take for the kategory and the counter. It would be easier to understand if it was something like 'n4 n4/A'.The number of bytes (not characters: the number of bytes in a character varies according to the character set - ASCII, Unicode, etc. - perhaps locale, etc.) is implicit in the template specification: for 'n' it is two bytes, or, per the documentation, '_exactly_ 16 bits' in '"network" (big-endian) order'. So 'n4' is "four unsigned shorts, each of which is exactly 16 bits and with the bytes of each in big-endian order". What I infer from the last example in your question is something like a string, and I would tend to use 'a', 'b', or 'B', although to control the endianity of the byte sequence within each packed or unpacked string, you might have to use reverse before packing or after unpacking.
In the manpage I found that n is in "big-endian order". Do I have to change the code to use 'v' on a Sparc (Sun) maschine? Or is all that matters the data and not the maschine it is running on?All that matters is the endianity of the data you are processing. The template specifiers 'n' and friends give you an 'absolute' endianity, independent of any platform, unlike 'i' and its ilk.
I am not sure if I understand the line 'unpack(qq(x$offset x4 A$len), $data);' Is it correct that the two 'x' parameters are just there to consume some characters and only 'A$len' is really used?The 'A$len' specifier is the only one that extracts anything, but of course the two 'x' specifiers are necessary to do the extraction from the right place!
In reply to Re^2: pack with count in the data
by AnomalousMonk
in thread pack with count in the data
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |