jamcodec 0.1.2__tar.gz → 0.1.3__tar.gz
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.
- {jamcodec-0.1.2 → jamcodec-0.1.3}/PKG-INFO +1 -1
- {jamcodec-0.1.2 → jamcodec-0.1.3}/jamcodec/types.py +20 -4
- {jamcodec-0.1.2 → jamcodec-0.1.3}/jamcodec.egg-info/PKG-INFO +1 -1
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_enum.py +9 -1
- {jamcodec-0.1.2 → jamcodec-0.1.3}/LICENSE +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/README.md +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/jamcodec/__init__.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/jamcodec/base.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/jamcodec/constants.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/jamcodec/exceptions.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/jamcodec/mixins.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/jamcodec.egg-info/SOURCES.txt +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/jamcodec.egg-info/dependency_links.txt +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/jamcodec.egg-info/requires.txt +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/jamcodec.egg-info/top_level.txt +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/pyproject.toml +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/requirements.txt +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/setup.cfg +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_array.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_bitarray.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_bitvec.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_boolean.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_bytes.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_compact.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_float.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_hashmap.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_integer.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_map.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_mixins.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_option.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_scale_types.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_scalebytes.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_string.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_struct.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_tuple.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_varint.py +0 -0
- {jamcodec-0.1.2 → jamcodec-0.1.3}/test/test_vec.py +0 -0
|
@@ -371,8 +371,11 @@ class Enum(JamCodecTypeDef):
|
|
|
371
371
|
|
|
372
372
|
for idx, (variant_name, variant_obj) in enumerate(self.variants.items()):
|
|
373
373
|
|
|
374
|
-
if
|
|
374
|
+
if type(variant_obj) is dict:
|
|
375
|
+
idx = variant_obj.get('id', idx)
|
|
376
|
+
variant_obj = variant_obj.get('type', variant_obj)
|
|
375
377
|
|
|
378
|
+
if enum_key == variant_name:
|
|
376
379
|
data = JamBytes(bytearray([idx]))
|
|
377
380
|
|
|
378
381
|
if variant_obj is not None:
|
|
@@ -387,9 +390,19 @@ class Enum(JamCodecTypeDef):
|
|
|
387
390
|
|
|
388
391
|
index = int.from_bytes(data.get_next_bytes(1), byteorder='little')
|
|
389
392
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
+
enum_key = None
|
|
394
|
+
enum_variant = None
|
|
395
|
+
|
|
396
|
+
for idx, (variant_key, variant_obj) in enumerate(self.variants.items()):
|
|
397
|
+
if type(variant_obj) is dict:
|
|
398
|
+
idx = variant_obj.get('id', idx)
|
|
399
|
+
variant_obj = variant_obj.get('type', variant_obj)
|
|
400
|
+
if index == idx:
|
|
401
|
+
enum_key = variant_key
|
|
402
|
+
enum_variant = variant_obj
|
|
403
|
+
break
|
|
404
|
+
|
|
405
|
+
if enum_key is None:
|
|
393
406
|
raise ScaleDecodeException(f"Index '{index}' not present in Enum type mapping")
|
|
394
407
|
|
|
395
408
|
if enum_variant is None:
|
|
@@ -434,6 +447,9 @@ class Enum(JamCodecTypeDef):
|
|
|
434
447
|
|
|
435
448
|
for idx, (variant_name, variant_obj) in enumerate(self.variants.items()):
|
|
436
449
|
|
|
450
|
+
if type(variant_obj) is dict:
|
|
451
|
+
variant_obj = variant_obj.get('type', variant_obj)
|
|
452
|
+
|
|
437
453
|
if enum_key == variant_name:
|
|
438
454
|
|
|
439
455
|
if variant_obj is not None:
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import unittest
|
|
19
19
|
|
|
20
|
-
from jamcodec.types import Enum, Bool, U32
|
|
20
|
+
from jamcodec.types import Enum, Bool, U32, String
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class TestEnum(unittest.TestCase):
|
|
@@ -60,6 +60,14 @@ class TestEnum(unittest.TestCase):
|
|
|
60
60
|
scale_obj.deserialize('None')
|
|
61
61
|
self.assertEqual(('None', None), scale_obj.value_object)
|
|
62
62
|
|
|
63
|
+
def test_enum_explicit_id(self):
|
|
64
|
+
scale_obj = Enum(Bool=Bool(), Number=U32, Error={'id': 255, 'type': String}).new()
|
|
65
|
+
jam_bytes = scale_obj.encode({'Error': 'test'})
|
|
66
|
+
self.assertEqual('0xff0474657374', jam_bytes.to_hex())
|
|
67
|
+
|
|
68
|
+
value = scale_obj.decode(jam_bytes)
|
|
69
|
+
self.assertEqual({'Error': 'test'}, value)
|
|
70
|
+
|
|
63
71
|
|
|
64
72
|
if __name__ == '__main__':
|
|
65
73
|
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|