File size: 618 Bytes
838f737 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | """
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",
]
@substitute_in_graph(struct.pack, can_constant_fold_through=True) # type: ignore[arg-type]
def pack(fmt: bytes | str, /, *v: Any) -> bytes:
return struct.pack(fmt, *v)
@substitute_in_graph(struct.unpack, can_constant_fold_through=True) # type: ignore[arg-type]
def unpack(format: bytes | str, buffer: Buffer, /) -> tuple[Any, ...]:
return struct.unpack(format, buffer)
|