|
|
|
@ -15,7 +15,7 @@ class Int(Type[int]): |
|
|
|
|
|
|
|
|
|
def parse(self, context: Context, stream: Stream) -> int: |
|
|
|
|
n = context.get(self.bits) |
|
|
|
|
bs = stream.read(n // 8) |
|
|
|
|
bs = stream.read(n // 8 if n is not None else -1) |
|
|
|
|
return int.from_bytes(bs, byteorder=context.get(self.endian).to_python(), signed=context.get(self.signed)) |
|
|
|
|
|
|
|
|
|
def dump(self, context: Context, stream: Stream, value: U[int, float]) -> None: |
|
|
|
@ -40,7 +40,8 @@ class Int(Type[int]): |
|
|
|
|
def __str__(self) -> str: |
|
|
|
|
endian = {Endian.Big: 'be', Endian.Little: 'le'}.get(self.endian, self.endian) if self.bits != 8 else '' |
|
|
|
|
sign = {True: '', False: 'u'}.get(self.signed, self.signed) |
|
|
|
|
return f'{sign}int{self.bits}{endian}' |
|
|
|
|
bits = self.bits if self.bits is not None else '' |
|
|
|
|
return f'{sign}int{bits}{endian}' |
|
|
|
|
|
|
|
|
|
def __repr__(self) -> str: |
|
|
|
|
return f'{__name__}.Int({self.bits!r}, endian={self.endian!r}, signed={self.signed!r})' |
|
|
|
@ -73,6 +74,11 @@ uint64 = \ |
|
|
|
|
uint64le = Int(64, endian=Endian.Little, signed=False) |
|
|
|
|
uint64be = Int(64, endian=Endian.Big, signed=False) |
|
|
|
|
|
|
|
|
|
intle = Int(None, endian=Endian.Little, signed=True) |
|
|
|
|
intbe = Int(None, endian=Endian.Big, signed=True) |
|
|
|
|
uintle = Int(None, endian=Endian.Little, signed=False) |
|
|
|
|
uintbe = Int(None, endian=Endian.Big, signed=False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
T = TypeVar('T') |
|
|
|
|
|
|
|
|
|