Encode and decode XDR data using Python xdrlib

PythonServer Side ProgrammingProgramming

Encoders and decoders for the External Data Representation (XDR). When we transport data between different external sources, this is the commonly used format that is used. It useful for creation and transfer of complex data structures. XDR provides a service associated with the OSI Presentation Layer.

In the below program we see how the data is getting packed and unpacked using the xdrlib module.

Example

import xdrlib
p = xdrlib.Packer()
print(type(p))
lst = [1,2,3]
p.pack_list(lst, p.pack_int)
print(p)
u = xdrlib.Unpacker(p)
print(type(u))
print(lst)

Running the above code gives us the following result −

Output

<xdrlib.Packer object at 0x000002272F3D6FD0>

[1, 2, 3]
raja
Published on 28-Dec-2020 11:04:10
Advertisements