import xdrlib
def f_packer(name, author, month, year):
data = xdrlib.Packer()
data.pack_string(name)
data.pack_string(author)
data.pack_uint(month)
data.pack_uint(year)
packed = data.get_buffer()
return packed
def f_unpacker(packer):
data = xdrlib.Unpacker(packer)
return data
print "The original values are: 'Andre', 'Author', 10, 2000"
print
packed = f_packer('Andre', 'Author', 10, 2000)
print "The packed data is now defined by:", repr(packed)
print
print "And now, the original data again. (After unpacking it!)"
unpacked = f_unpacker(packed)
print repr(unpacked.unpack_string()), ", ", \
repr(unpacked.unpack_string()), ", ", \
unpacked.unpack_uint(), ", ", \
unpacked.unpack_uint()
unpacked.done()
|