tsrkit-types 0.1.5__py3-none-any.whl → 0.1.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tsrkit_types/bytearray.py +3 -1
- tsrkit_types/bytes.py +5 -1
- tsrkit_types/integers.py +9 -8
- {tsrkit_types-0.1.5.dist-info → tsrkit_types-0.1.7.dist-info}/METADATA +1 -1
- {tsrkit_types-0.1.5.dist-info → tsrkit_types-0.1.7.dist-info}/RECORD +8 -8
- {tsrkit_types-0.1.5.dist-info → tsrkit_types-0.1.7.dist-info}/WHEEL +0 -0
- {tsrkit_types-0.1.5.dist-info → tsrkit_types-0.1.7.dist-info}/licenses/LICENSE +0 -0
- {tsrkit_types-0.1.5.dist-info → tsrkit_types-0.1.7.dist-info}/top_level.txt +0 -0
tsrkit_types/bytearray.py
CHANGED
|
@@ -28,10 +28,12 @@ class ByteArray(bytearray, Codable, BytesMixin):
|
|
|
28
28
|
current_offset = offset
|
|
29
29
|
_len, _inc_offset = Uint.decode_from(buffer, offset)
|
|
30
30
|
current_offset += _inc_offset
|
|
31
|
+
if len(buffer[current_offset:current_offset+_len]) < _len:
|
|
32
|
+
raise TypeError("Insufficient buffer")
|
|
31
33
|
return cls(buffer[current_offset:current_offset+_len]), current_offset + _len - offset
|
|
32
34
|
|
|
33
35
|
# ---------------------------------------------------------------------------- #
|
|
34
36
|
# JSON Serialization #
|
|
35
37
|
# ---------------------------------------------------------------------------- #
|
|
36
38
|
# JSON methods inherited from BytesMixin
|
|
37
|
-
|
|
39
|
+
|
tsrkit_types/bytes.py
CHANGED
|
@@ -51,9 +51,13 @@ class Bytes(bytes, Codable, BytesMixin, metaclass=BytesCheckMeta):
|
|
|
51
51
|
def decode_from(cls, buffer: Union[bytes, bytearray, memoryview], offset: int = 0) -> Tuple["Bytes", int]:
|
|
52
52
|
current_offset = offset
|
|
53
53
|
_len = cls._length
|
|
54
|
+
|
|
54
55
|
if _len is None:
|
|
55
56
|
_len, _inc_offset = Uint.decode_from(buffer, offset)
|
|
56
57
|
current_offset += _inc_offset
|
|
58
|
+
|
|
59
|
+
if len(buffer[current_offset:current_offset+_len]) < _len:
|
|
60
|
+
raise TypeError("Insufficient buffer")
|
|
57
61
|
return cls(buffer[current_offset:current_offset+_len]), current_offset + _len - offset
|
|
58
62
|
|
|
59
63
|
# ---------------------------------------------------------------------------- #
|
|
@@ -67,4 +71,4 @@ Bytes64 = Bytes[64]
|
|
|
67
71
|
Bytes128 = Bytes[128]
|
|
68
72
|
Bytes256 = Bytes[256]
|
|
69
73
|
Bytes512 = Bytes[512]
|
|
70
|
-
Bytes1024 = Bytes[1024]
|
|
74
|
+
Bytes1024 = Bytes[1024]
|
tsrkit_types/integers.py
CHANGED
|
@@ -53,9 +53,9 @@ class Int(int, Codable, metaclass=IntCheckMeta):
|
|
|
53
53
|
# Otherwise, the integer is General Integer (supports up to 2**64 - 1)
|
|
54
54
|
byte_size: int = 0
|
|
55
55
|
signed = False
|
|
56
|
-
_bound =
|
|
56
|
+
_bound = 1 << 64
|
|
57
57
|
|
|
58
|
-
def __class_getitem__(cls, data: int | tuple):
|
|
58
|
+
def __class_getitem__(cls, data: int | tuple | bool | None):
|
|
59
59
|
"""
|
|
60
60
|
Args:
|
|
61
61
|
data: either byte_size or (byte_size, signed)
|
|
@@ -69,7 +69,8 @@ class Int(int, Codable, metaclass=IntCheckMeta):
|
|
|
69
69
|
else:
|
|
70
70
|
size, signed = 0, bool(data)
|
|
71
71
|
else:
|
|
72
|
-
size, signed = data
|
|
72
|
+
size, signed = data
|
|
73
|
+
|
|
73
74
|
return type(f"U{size}" if size else "Int", (cls,), {
|
|
74
75
|
"byte_size": size // 8,
|
|
75
76
|
"signed": signed,
|
|
@@ -85,7 +86,7 @@ class Int(int, Codable, metaclass=IntCheckMeta):
|
|
|
85
86
|
min_v = -1 * cls._bound // 2 if cls.signed else 0
|
|
86
87
|
max_v = cls._bound // 2 if cls.signed else cls._bound - 1
|
|
87
88
|
|
|
88
|
-
if not (min_v <= value
|
|
89
|
+
if not (min_v <= value < max_v):
|
|
89
90
|
raise ValueError(f"Int: {cls.__name__} out of range: {value!r} "
|
|
90
91
|
f"not in [{min_v}, {max_v}]")
|
|
91
92
|
return super().__new__(cls, value)
|
|
@@ -238,7 +239,7 @@ class Int(int, Codable, metaclass=IntCheckMeta):
|
|
|
238
239
|
|
|
239
240
|
|
|
240
241
|
Uint = Int
|
|
241
|
-
U8 =
|
|
242
|
-
U16 =
|
|
243
|
-
U32 =
|
|
244
|
-
U64 =
|
|
242
|
+
U8 = Int[8]
|
|
243
|
+
U16 = Int[16]
|
|
244
|
+
U32 = Int[32]
|
|
245
|
+
U64 = Int[64]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tsrkit-types
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
4
4
|
Summary: Performant Python Typings library for type-safe binary serialization, JSON encoding, and data validation with zero dependencies
|
|
5
5
|
Author-email: chainscore-labs <hello@chainscore.finance>, prasad-kumkar <prasad@chainscore.finance>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
tsrkit_types/__init__.py,sha256=PlhqxNwjXaJU5vTIqJdLvC5BBfExLAoKQ57peNG2Opc,1900
|
|
2
2
|
tsrkit_types/bits.py,sha256=33WLfuUYdzGscoc-E3InTYdbJRIDeixoe_pG0XAv71c,4213
|
|
3
3
|
tsrkit_types/bool.py,sha256=Veu6KLIeiRFnIW1sbawJ0haF0veyaL-As5mBiypq-uE,1280
|
|
4
|
-
tsrkit_types/bytearray.py,sha256=
|
|
5
|
-
tsrkit_types/bytes.py,sha256=
|
|
4
|
+
tsrkit_types/bytearray.py,sha256=5uBK_5bHVxRAocfRHDojCTtS2ysUh-8bFdWglO-ZM48,1781
|
|
5
|
+
tsrkit_types/bytes.py,sha256=tsyeItlI4LZPnkxFY-5_kgoDs04Zk_Xuan1erkG4Ff0,2863
|
|
6
6
|
tsrkit_types/bytes_common.py,sha256=b1Zqh_NhkCX718QaZC52J3nEzKAi1Fe8E0nefWVwwmo,2301
|
|
7
7
|
tsrkit_types/choice.py,sha256=OVHxIr2PcnaTpo5sAMjipCArc5oATNsyYkqZNRqU7bA,5253
|
|
8
8
|
tsrkit_types/dictionary.py,sha256=GcUvaHC1VOEc3OzUVAH0id--ncLqTJ6ZRz-lucMNRdY,5618
|
|
9
9
|
tsrkit_types/enum.py,sha256=3MyLW15_ToQQdctJjcMY8Xb3OsS_Ad997OOEo8FjVeA,4256
|
|
10
|
-
tsrkit_types/integers.py,sha256=
|
|
10
|
+
tsrkit_types/integers.py,sha256=pQBQ4IAMaS81dJBOSKK3op0WCxng1CPJljP3uV0QVAs,8857
|
|
11
11
|
tsrkit_types/null.py,sha256=vzobz4-xJrUeky8pzbg-Qmz4N6b7GsCNf8TafbstlgY,1372
|
|
12
12
|
tsrkit_types/option.py,sha256=xwtaAFN20GjaGqzYZAAo1fZqqUZnCYHdy2bjshhY620,1631
|
|
13
13
|
tsrkit_types/sequences.py,sha256=KOT5-4mia5Lc0CMjIF7Yqe34Sei92ZQ2s6GaP13soUg,8090
|
|
14
14
|
tsrkit_types/string.py,sha256=8rvg0BwvyhQnbMW3qornmBFTQHeTQFUfwD7OC0eVgcY,2575
|
|
15
15
|
tsrkit_types/struct.py,sha256=GoXWFc1OqO9CXnxFS7Xkms7J-rtZe8h32LkAIBlzdSM,3497
|
|
16
16
|
tsrkit_types/itf/codable.py,sha256=agx8YSVWGBeEiLrU9eqh3ZoeTgpJsmmIlW622xIKqPI,2810
|
|
17
|
-
tsrkit_types-0.1.
|
|
18
|
-
tsrkit_types-0.1.
|
|
19
|
-
tsrkit_types-0.1.
|
|
20
|
-
tsrkit_types-0.1.
|
|
21
|
-
tsrkit_types-0.1.
|
|
17
|
+
tsrkit_types-0.1.7.dist-info/licenses/LICENSE,sha256=TwnDvVCPwHadHWLUuY1sPx03XNw1jzh_ZmoDBNai9Uc,1072
|
|
18
|
+
tsrkit_types-0.1.7.dist-info/METADATA,sha256=IfpeZ63P_3GDTRR23f4Dl0HeNalvbaZwcT5fjrZBf9Y,22755
|
|
19
|
+
tsrkit_types-0.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
20
|
+
tsrkit_types-0.1.7.dist-info/top_level.txt,sha256=pnVhnUsnZ_A0FIj1zHwDw3suMGrfMJwusp-4GPVY1CM,13
|
|
21
|
+
tsrkit_types-0.1.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|