[Python-bugs-list] [ python-Bugs-461674 ] struct 'p' format doesn't work (maybe)

noreply@sourceforge.net noreply@sourceforge.net
Fri, 14 Sep 2001 14:32:41 -0700


Bugs item #461674, was opened at 2001-09-14 14:32
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=461674&group_id=5470

Category: Python Library
Group: Python 2.1.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Gregory Smith (gregsmith)
Assigned to: Nobody/Anonymous (nobody)
Summary: struct 'p' format doesn't work (maybe)

Initial Comment:
Doc says: """
The "p" format character can be used to encode a Pascal string. The first byte is the length of the 
stored string, with the bytes of the string following. If count is given, it is
used as the total number of bytes used, including the length byte. If the string passed in to pack() 
is too long, the stored representation is truncated. If the string is too
short, padding is used to ensure that exactly enough bytes are used to satisfy the count. 
"""

The behaviour implied (to me, anyway) is
(1) pack('p','abc') -> '\x03abc'
(2) pack('3p','abc') ->'\x02ab'
(3) pack('5p','abc') ->'\x03abc\x00'
(4) pack('p','a') -> '\x01a'
(5) pack('p','') -> '\x00'
(6) pack('p','abcdefg')  -> '\x07abcdefg'

etc, etc. In fact, only (2) and (3) work like this; the rest return empty string.
and the corresponding unpack will return empty string.
"If count is given" This implies (arguably) that 'p' by itself is useful
and behaves as described in the first two sentences.
This variable-length string storage would be very useful and it
is too bad that it isn't supported. 
Of course, calcsize() would have to raise an exception if 'p' were
used without a count, or return the min size.



----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=461674&group_id=5470