mda-xdrlib

0.2.0 · active · verified Wed Apr 15

mda-xdrlib is a stand-alone Python module that provides the functionality of the `xdrlib` module, as it existed in CPython 3.10.8. It enables conversion between Python data types and the XDR (External Data Representation) format, which is useful for platform-independent binary data exchange. Currently at version 0.2.0, its releases are infrequent and primarily driven by the need to maintain XDR compatibility for projects like MDAnalysis after the standard library's `xdrlib` module was deprecated.

Warnings

Install

Imports

Quickstart

Demonstrates basic XDR packing of an integer, a string, and a double, followed by unpacking them in the correct order.

import mda_xdrlib

# 1. Pack data
packer = mda_xdrlib.Packer()
packer.pack_int(123)
packer.pack_string(b"hello xdr")
packer.pack_double(3.14159)
packed_data = packer.get_buffer()
print(f"Packed data (hex): {packed_data.hex()}")

# 2. Unpack data
unpacker = mda_xdrlib.Unpacker(packed_data)
unpacked_int = unpacker.unpack_int()
unpacked_string = unpacker.unpack_string()
unpacked_double = unpacker.unpack_double()
unpacker.done() # Verify all data has been unpacked

print(f"Unpacked int: {unpacked_int}")
print(f"Unpacked string: {unpacked_string.decode('utf-8')}")
print(f"Unpacked double: {unpacked_double}")

view raw JSON →