Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88091aa

Browse files
committed
SF bug [#461674] struct 'p' format doesn't work (maybe)
Rewrote the 'p' description.
1 parent e000782 commit 88091aa

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Doc/lib/libstruct.tex

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,17 @@ \section{\module{struct} ---
9494
number of bytes. As a special case, \code{'0s'} means a single, empty
9595
string (while \code{'0c'} means 0 characters).
9696

97-
The \character{p} format character can be used to encode a Pascal
98-
string. The first byte is the length of the stored string, with the
99-
bytes of the string following. If count is given, it is used as the
100-
total number of bytes used, including the length byte. If the string
101-
passed in to \function{pack()} is too long, the stored representation
102-
is truncated. If the string is too short, padding is used to ensure
103-
that exactly enough bytes are used to satisfy the count.
97+
The \character{p} format character encodes a "Pascal string", meaning
98+
a short variable-length string stored in a fixed number of bytes.
99+
The count is the total number of bytes stored. The first byte stored is
100+
the length of the string, or 255, whichever is smaller. The bytes
101+
of the string follow. If the string passed in to \function{pack()} is too
102+
long (longer than the count minus 1), only the leading count-1 bytes of the
103+
string are stored, If the string is shorter than count-1, it is padded
104+
with null bytes so that exactly count bytes in all are used. Note that
105+
for \function{unpack()}, the \character{p} format character consumes count
106+
bytes, but that the string returned can never contain more than 255
107+
characters.
104108

105109
For the \character{I}, \character{L}, \character{q} and \character{Q}
106110
format characters, the return value is a Python long integer.

0 commit comments

Comments
 (0)