Discussion:
[BitPim-devel] Packet definition variable length list on output
Stephen Wood
2005-09-21 04:07:28 UTC
Permalink
The Samsung N200 phonebook read and write commands (AT#PBOKR/W) are variable
length, depending on the number of phone number types that are in use. Is
there a way for for the class (CSVSTRING) to know that it is the last item
in a packet definition so that it can not write a "," terminator?

Stephen
Joe Pham
2005-09-21 04:43:35 UTC
Permalink
Post by Stephen Wood
The Samsung N200 phonebook read and write commands (AT#PBOKR/W) are
variable length, depending on the number of phone number types that
are in use. Is there a way for for the class (CSVSTRING) to know
that it is the last item in a packet definition so that it can not
write a "," terminator?
Assuming you know that it's the last one (while building the object), one approach could be:

* LIST {'createdefault': True} +numbers:
P BOOL { 'default': false } last_number
* CSVINT +numbertype
if self.last_number:
* CSVSTRING {'quotechar': None, 'default': "", 'terminator': None } +number
if not self.last_number:
* CSVSTRING {'quotechar': None, 'default': ""} +number

-Joe Pham



______________________________________________________________________
NetZero Is Giving Away $3,000 A Day!
Sign up for NetZero HiSpeed 3G with Instant On!
Visit http://www.netzero.com/3Gsweeps TODAY for your chance to win!
Stephen Wood
2005-09-22 04:19:32 UTC
Permalink
Post by Joe Pham
Assuming you know that it's the last one (while building the object), one
P BOOL { 'default': false } last_number
* CSVINT +numbertype
* CSVSTRING {'quotechar': None, 'default': "", 'terminator': None } +number
* CSVSTRING {'quotechar': None, 'default': ""} +number
-Joe Pham
That works!

Thanks, Stephen
Joe Pham
2005-09-23 01:37:40 UTC
Permalink
I ran into a similar situation earlier, and I think a more elegant solution would be to provide the capability of optionally setting/changing the attributes of a protocol field. For example:

* LIST {'createdefault': True} +numbers:
* CSVINT +numbertype
* CSVSTRING {'quotechar': None, 'default': ""} +number

would become something like:

* LIST {'createdefault': True} +numbers:
* CSVINT +numbertype
* CSVSTRING {'quotechar': None, 'default': ""} ++number

The '++' modifier indicates that the attributes of this field can be set. Internally, this would generate a method called 'set_number_attr(**kwargs)'. Then later in users code:

some_obj.set_number_attr(terminator=None) # turn off terminator

This approach would not impact existing protocol files & generated code, yet provides the capability to set/change protocol field attributes.

Suggestions and comments are welcome.

-Joe Pham




______________________________________________________________________
NetZero Is Giving Away $3,000 A Day!
Sign up for NetZero HiSpeed 3G with Instant On!
Visit http://www.netzero.com/3Gsweeps TODAY for your chance to win!
Stephen Wood
2005-09-23 03:17:55 UTC
Permalink
some_obj.set_number_attr(terminator=None) # turn off terminator
That would be nice. I think I was initially hoping I could do something like
that.

Stephen
Stephen Wood
2005-09-23 03:52:10 UTC
Permalink
Actually, if the CSV classes could somehow know when they are the last item
in a buffer being written, then I wouldn't have to put {'terminator': None}
on that last item of each packet, either statically or dynamically. Would
make things look a bit neater.

Actually, on reading, by default, end of string is accepted in liu of ",",
so the terminator none is not required on readonly packet definitions. This
came handy for reading the N200 phonebook with it's variable field count
entries.

Stephen
Roger Binns
2005-09-23 04:46:11 UTC
Permalink
Post by Joe Pham
The '++' modifier indicates that the attributes of this field can be set. Internally, this would generate a method called
some_obj.set_number_attr(terminator=None) # turn off terminator
You can already do this although only by creating a new instance. If the .p
has

* CSVSTRING {'quotechar': None, 'default': ""} +number

Then you can do this:

foo.number=CSVSTRING('terminator': 'X')

This is a quite yucky though but safer. This will also work:

foo.number._update('terminator': 'X')

Another option to have some sort of EOL type. On writing we could make it remove any preceding
comma.

Originally was thinking about automatically giving each item some knowledge about
where it is in the sequence. There is probably some elegant way of doing this.

Roger
Joe Pham
2005-09-24 02:33:40 UTC
Permalink
Post by Roger Binns
foo.number._update('terminator': 'X')
This syntax does not seem to work since foo.number return a value string in this example.

-Joe Pham




______________________________________________________________________
NetZero Is Giving Away $3,000 A Day!
Sign up for NetZero HiSpeed 3G with Instant On!
Visit http://www.netzero.com/3Gsweeps TODAY for your chance to win!
Roger Binns
2005-09-24 04:25:14 UTC
Permalink
Post by Joe Pham
Post by Roger Binns
foo.number._update('terminator': 'X')
This syntax does not seem to work since foo.number return a value string in this example.
Ah yes, it would seem that property getter is called squashing that.
Alternatively you could add a method to 'foo' that would call the
_update method behind the scenes. For example:

foo.set_args("number", terminator='X')

Roger

Loading...