serializing data structures

P

Philippe C. Martin

Hi,

I am trying to figure out the traps/issues about sending data structures
through a TCP/IP socket under the following circumstances:

1) there could be a different O/S on both side of the socket
2) there could be a difference CPU architecure on both side of the
socket
3) there could be a different major release of python (ex 2.3 and 2.4)
on both side of the socket.


I once wrote something in C to do that, but since python usually has a
solution for me ....


Any clue ?

Regards,


Philippe





--
***************************
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
***************************
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Philippe said:
I once wrote something in C to do that, but since python usually has a
solution for me ....

If you use arbitrary data structures, you could use pickle or xmlrpclib
to marshal the data. If you know the data is restricted to a few
well-known data types, you could use XDR (Demo/rpc/xdr.py) or CORBA
(e.g. through fnorb.sf.net) to come up with a wire format.

Otherwise, if you want to define your own proprietary data format,
you can probably use the struct module to generate messages according
to this format.

However, in any case, you need to define the wire format. Once you made
a choice, Python can help implement it - but Python cannot chose a wire
format for you (although pickle comes really close, as does Dopy -
http://www.mindhog.net/~mmuller/projects/dopy/)

Regards,
Martin
 
P

Philippe C. Martin

Thanks a lot.

Regards,

Philippe




If you use arbitrary data structures, you could use pickle or xmlrpclib
to marshal the data. If you know the data is restricted to a few
well-known data types, you could use XDR (Demo/rpc/xdr.py) or CORBA
(e.g. through fnorb.sf.net) to come up with a wire format.

Otherwise, if you want to define your own proprietary data format,
you can probably use the struct module to generate messages according
to this format.

However, in any case, you need to define the wire format. Once you made
a choice, Python can help implement it - but Python cannot chose a wire
format for you (although pickle comes really close, as does Dopy -
http://www.mindhog.net/~mmuller/projects/dopy/)

Regards,
Martin
 
P

Paul Rubin

Philippe C. Martin said:
I am trying to figure out the traps/issues about sending data structures
through a TCP/IP socket under the following circumstances:

1) there could be a different O/S on both side of the socket
2) there could be a difference CPU architecure on both side of the
socket
3) there could be a different major release of python (ex 2.3 and 2.4)
on both side of the socket.

I once wrote something in C to do that, but since python usually has a
solution for me ....

What do you mean by data structures? If they're limited to basic
objects like strings and ints, try xdrlib. If you want longs, class
instances, etc., there's really no good way in the Python stdlib that
doesn't create security vulnerabilities if the source of data isn't
trusted. See SF bugs 471893 and 467384 for some discussion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top