Discussion:
[Bitpim-devel] Strings in packet description
Stephen Wood
2003-10-30 04:17:36 UTC
Permalink
I have the following packet description:

PACKET {'readwrite': 0x0d} sanyoheader:
1 UINT readwrite
1 UINT command
1 UINT packettype

PACKET phonebookentry:
2 UINT slot
2 UINT slotdup
16 STRING name
* LIST {'length': 7} numbers:
1 UINT number_len
49 STRING number
1 UINT email_len
49 STRING email
1 UINT url_len
49 STRING url
1 UINT secret
1 UINT name_len

PACKET phonebookslotresponse:
* sanyoheader header
* phonebookentry entry
30 UNKNOWN pad

When I try to read a packet with names less than 16 characters, it works
(the phone pads fields with nulls). But on the following packet, with a
16 character name, I get an error. Are there some attributes to STRING
that I can add that will help? The length of the string is available in
the packet, but is not located adjacent to the string itself.

Steve
Roger Binns
2003-10-30 23:07:52 UTC
Permalink
Post by Stephen Wood
When I try to read a packet with names less than 16 characters, it works
(the phone pads fields with nulls). But on the following packet, with a
16 character name, I get an error.
You can set raiseonunterminatedread to False.
Post by Stephen Wood
Are there some attributes to STRING
that I can add that will help? The length of the string is available in
the packet, but is not located adjacent to the string itself.
I guess the problem here is that the field has a length in bytes
(including padding) as well as a length in characters. It even
looks like the length in characters can be in a later field
which makes things even nastier.

If the raiseonunterminatedread doesn't work for you, you could derive
a new string class (or add an argument to the existing one) that
lets you truncate the characters to a certain size. It won't be
much use when the length field is after the string field though.

Roger

Loading...