| """ | |
| Python polyfills for struct | |
| """ | |
| from __future__ import annotations | |
| import struct | |
| from typing import Any | |
| from typing_extensions import Buffer | |
| from ..decorators import substitute_in_graph | |
| __all__ = [ | |
| "pack", | |
| "unpack", | |
| ] | |
| # type: ignore[arg-type] | |
| def pack(fmt: bytes | str, /, *v: Any) -> bytes: | |
| return struct.pack(fmt, *v) | |
| # type: ignore[arg-type] | |
| def unpack(format: bytes | str, buffer: Buffer, /) -> tuple[Any, ...]: | |
| return struct.unpack(format, buffer) | |