I have an interesting file format to decode. Its based off C structs, but with tons of null terminated strings, UTF16LE strings are mixed with ASCII strings, all null terminated. The string lengths are variable, but there is always the same number and position of strings and longs in the same pattern (struct-ish). A sample of what the record looks like is below and my attempts to far to decode it.
$s = encode('UTF-16LE', "first name string\0").encode('UTF-16LE', "mi
+ddle name string\0").
encode('UTF-16LE', "last name string\0").pack('V', 3654877182).pack('V
+', 1).encode('UTF-16LE', "address string\0")."zip code ascii\0".pack(
+'V',1);
$decodedStr = decode('UTF-16LE', $s, Encode::FB_CROAK);
print Dumper([unpack('Z*Z*Z*VVZ*Z*V',$decodedStr)]);
UTF-16LE:Unicode character fffe is illegal at C:/perl512/lib/Encode.pm line 174.
removing FB_CROAK gave me
$VAR1 = [
"first name string",
"middle name string",
"last name string",
"1627454973",
"1701995620",
"ss string",
"\x{697a}\x{2070}\x{6f63}\x{6564}\x{6120}\x{6373}\x{6969}\x{
+100}"
];
and warning, "Character(s) in 'V' format wrapped in unpack"
Is there any way to use pack to decode this, or any other template style way of decoding this without writing a byte level parser using substr and index and a current character position integer?
as far as I understand, pack doesn't understand what a null terminated UTF16 string is, right?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.