struct.pack
has many issues:
- The format string consists of characters that may be confusing and may need to be looked up in the documentation, as opposed to using easy to understand self-documenting code.
This lead to many test bugs, which weren’t hit, which is fine, but still confusing. Ref: #29400, #29399, #29363, fa3886b7c69cbbe564478f30bb2c35e9e6b1cffa, …
Fix all issues by using the built-in int
helpers to_bytes
via a scripted diff.
Review notes:
- For
struct.pack
andint.to_bytes
the error behavior is the same, although the error messages are not identical. - Two
struct.pack
remain. One for float serialization in a C++ code comment, and one for native serialization.