Skip to content

Commit

Permalink
BaseTools: BinToPcd: Resolve xdrlib deprecation
Browse files Browse the repository at this point in the history
Removes the dependency on xdrlib and replaces it with custom logic to
pack a per the xdr requirements. Necessary as xdrlib is being deprecated
in python 3.13.

Cc: Rebecca Cran <[email protected]>
Cc: Liming Gao <[email protected]>
Cc: Bob Feng <[email protected]>
Cc: Yuwei Chen <[email protected]>
Cc: Michael D Kinney <[email protected]>
Signed-off-by: Joey Vagedes <[email protected]>
Reviewed-by: Liming Gao <[email protected]>
Reviewed-by: Michael D Kinney <[email protected]>
  • Loading branch information
Javagedes authored and mergify[bot] committed Aug 2, 2023
1 parent d11968f commit 5cadb8c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions BaseTools/Scripts/BinToPcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import argparse
import re
import xdrlib
import io
import struct
import math

#
# Globals for help information
Expand Down Expand Up @@ -46,16 +49,24 @@ def ValidateGuidName (Argument):
raise argparse.ArgumentTypeError (Message)
return Argument

def XdrPackBuffer (buffer):
packed_bytes = io.BytesIO()
for unpacked_bytes in buffer:
n = len(unpacked_bytes)
packed_bytes.write(struct.pack('>L',n))
data = unpacked_bytes[:n]
n = math.ceil(n/4)*4
data = data + (n - len(data)) * b'\0'
packed_bytes.write(data)
return packed_bytes.getvalue()

def ByteArray (Buffer, Xdr = False):
if Xdr:
#
# If Xdr flag is set then encode data using the Variable-Length Opaque
# Data format of RFC 4506 External Data Representation Standard (XDR).
#
XdrEncoder = xdrlib.Packer ()
for Item in Buffer:
XdrEncoder.pack_bytes (Item)
Buffer = bytearray (XdrEncoder.get_buffer ())
Buffer = bytearray (XdrPackBuffer (Buffer))
else:
#
# If Xdr flag is not set, then concatenate all the data
Expand Down

0 comments on commit 5cadb8c

Please sign in to comment.