I have python dict:
data = {
'foo': 'bar',
'hello': 'world'
}
How to can I pack this dict to XDR data format?
I have python dict:
data = {
'foo': 'bar',
'hello': 'world'
}
How to can I pack this dict to XDR data format?
This really depends on how you want it packed. As key
value
pairs, you could use the following:
Python 2.x:
import xdrlib
data = {'foo': 'bar', 'hello': 'world'}
p = xdrlib.Packer()
for key, value in data.items():
p.pack_string(key)
p.pack_string(value)
print p.get_buffer()
Python 3.x:
import xdrlib
data = {'foo': 'bar', 'hello': 'world'}
p = xdrlib.Packer()
for key, value in data.items():
p.pack_string(key.encode())
p.pack_string(value.encode())
print(p.get_buffer())
Which would display something like:
◦◦◦foo◦◦◦◦bar◦◦◦◦hello◦◦◦◦◦◦world◦◦◦