0

I have recently started to use Python's xdrlib module. I was surprised to see that Packer and Unpacker are classes that you need to instanciate and contains method like reset and get_buffer. Calls to Packer and Unpacker instance methods accumulate data in the buffer until you use it. The standard usage seems to be that you create one Packer and one Unpacker instance per Client, but this is not thread safe/

I said I was surprise because I was expecting to have just functions to pack the data into bytes and then write things like:

mybuffer += pack_int(3)

or having a Message class (a buffer with methods like append_int) and disposing the Message instance after usage.

The current design seems to put persistency in the wrong place. Is it really like this or there is some important feature that I am missing? What is the rationale of this design?

  • [Here is a demonstration](http://stackoverflow.com/a/17299760/190597) that `x += 1` is not thread safe. Presumably, if `x += 1` is not thread safe, `mybuffer += pack_int(3)` could not be either. – unutbu Aug 28 '13 at 18:15
  • @unutbu: I apologize for being unclear. I should have said that they way you use it might easily lead to problems. You want xdrlib to build a message. With the packer, you should not start building a message before you finish building the previous one. With functions or a Message class you do not really care about this, because each message is an independent object. – user1726868 Aug 28 '13 at 23:43

0 Answers0