develooper Front page | perl.perl5.porters | Postings from August 2012

Re: RFC: pack()ing long words

Thread Previous | Thread Next
From:
Salvador Fandino
Date:
August 27, 2012 03:34
Subject:
Re: RFC: pack()ing long words
Message ID:
503B4D27.8050703@yahoo.com
On 08/13/2012 01:51 PM, H.Merijn Brand wrote:
> On Mon, 13 Aug 2012 12:41:02 +0100, David Cantrell
> <david@cantrell.org.uk> wrote:
> 
>> pack() and unpack() can handle words of 1, 2, 4, and (if you built your
>> perl right) 8 bytes.  And I use the same magic characters (although
>> without using pack and unpack) in Data::Hexdumper.
>>
>> However, I want to extend it to support 16 byte words and, indeed, to
>> support any other length words.  3 byte words, for example.
>>
>> I'd like to remain as compatible as possible with the characters used in
>> pack()'s templates, but there's nothing there for what I want.
>>
>> So, can I propose that we pick a character for this purpose and at least
>> define some syntax for specifying a word length, endian-ness, and repeat
>> count for it, even if it isn't implemented yet?
>>
>> Something like this perhaps:
>>   X5,4>
>>
>> which means:
>>   X  - whatever letter we choose
>>   5  - word length
>>   ,4 - optional repeat count
>>   >  - optional endian-ness
> 
> Counterintuitive in that order
> 
> l4 is 4 longs, so if the 4 in your example matches the 4 in l4, I'd
> guess that
> 
>   X5>4
> 
> would be more intuitive
> 
> I kinda like your approach though. What about bits? Why restrict to
> multiple of 8 bits?
> 

but them, to make it really interesting, pack/unpack would have to
handle all the templates at arbitrary bit offsets.

For instance:

  pack("X{23}CX9");
  # should extract
  #   - a bitstring from bits 0 to 22
  #   - an unsigned char from bits 23 to 30
  #   - a bitstring from bits 31 to 39

Or at least, it should be possible to do that for X templates:

  pack("X{23}X8X9");
  # should extract
  #   - a bitstring from bits 0 to 22
  #   - a bitstring from bits 23 to 30
  #   - a bitstring from bits 31 to 39

Also, when considering bit strings and bit-offsets, "endianess" may be
interpreted in several ways: where do you place the byte boundaries? at
the byte boundaries in the string being unpacked? every 8 bits on the
sub-bitstring? starting from the left or from the right?



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About