Files
chia-blockchain/chia/util/ints.py
T
7c91f470f4 simplify SizedBytes and StructStream (#11429)
* simplify SizedBytes and StructStream

* lint

* super()  !!!

* do not pass parameter up to super().__init__()

* Update chia/util/struct_stream.py

Co-authored-by: Arvid Norberg <arvid@libtorrent.org>

* parse fixed-width int data from class name

* add int512 and uint128 .from_bytes(), test .parse() failures

* test serialization against struct.pack()

* use typing_extensions for final

* override ignore

* stop using struct for StructStream

oh the irony

* fixup .to_bytes() to accept parameters again for where we use that

* bring back signed parameter

* format

* adjust tests for new exception

* eliminate custom coding for uint128 and int512

* tidy

* remove unused StructStream.PACK attribute

* add direct tests for parse_metadata_from_name()

* stricter hinting

* remove no-longer-needed typeshed work-around

* apply strict type checking to all touched files

* remove StructStream override of .to_bytes()

* tidy

* types touchup

* add unused parameter comments

Co-authored-by: Arvid Norberg <arvid@libtorrent.org>
Co-authored-by: wjblanke <wjb98672@gmail.com>
2022-05-14 02:05:27 -07:00

64 lines
1.0 KiB
Python

from __future__ import annotations
from chia.util.struct_stream import StructStream, parse_metadata_from_name
@parse_metadata_from_name
class int8(StructStream):
pass
@parse_metadata_from_name
class uint8(StructStream):
pass
@parse_metadata_from_name
class int16(StructStream):
pass
@parse_metadata_from_name
class uint16(StructStream):
pass
@parse_metadata_from_name
class int32(StructStream):
pass
@parse_metadata_from_name
class uint32(StructStream):
pass
@parse_metadata_from_name
class int64(StructStream):
pass
@parse_metadata_from_name
class uint64(StructStream):
pass
@parse_metadata_from_name
class uint128(StructStream):
pass
class int512(StructStream):
PACK = None
# Uses 65 bytes to fit in the sign bit
SIZE = 65
BITS = 512
SIGNED = True
# note that the boundaries for int512 is not what you might expect. We
# encode these with one extra byte, but only allow a range of
# [-INT512_MAX, INT512_MAX]
MAXIMUM_EXCLUSIVE = 2 ** BITS
MINIMUM = -(2 ** BITS) + 1