From 3d5f001f98a63d1969c7e0a8ec233a32305096b0 Mon Sep 17 00:00:00 2001 From: Khush Jain Date: Thu, 26 Jun 2025 22:07:46 +0530 Subject: [PATCH 1/2] Fix handling multiple groups with wrap --- sbe/__init__.py | 2 +- tests/dat/example-schema.xml | 9 +++++++++ tests/test_sbe.py | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/sbe/__init__.py b/sbe/__init__.py index 73a1081..4a1d8ff 100644 --- a/sbe/__init__.py +++ b/sbe/__init__.py @@ -373,7 +373,7 @@ def hydrate(self, offset: int): p1.offset = cursor p1.hydrate() self.pointers[k] = p1 - cursor += p1.numInGroup * p1.blockLength + cursor += p1.numInGroup * p1.blockLength + p.num_in_group_pointer.size + p.block_length_pointer.size seen_group = True else: assert not seen_group diff --git a/tests/dat/example-schema.xml b/tests/dat/example-schema.xml index c646a33..b6c5776 100644 --- a/tests/dat/example-schema.xml +++ b/tests/dat/example-schema.xml @@ -84,4 +84,13 @@ + + + + + + + + + diff --git a/tests/test_sbe.py b/tests/test_sbe.py index 587033b..5163301 100644 --- a/tests/test_sbe.py +++ b/tests/test_sbe.py @@ -38,3 +38,22 @@ def test_blockLength(): decoded = s.decode(encoded) assert decoded.value['year'] == 1990 assert decoded.value['AGroup'][1]['numbers'] == 456 + +def test_multiple_groups(): + with open("tests/dat/example-schema.xml", "r", encoding="utf-8") as f: + s = sbe.Schema.parse(f) + msg = s.messages[4] + + encoded = s.encode( + msg, + { + "year": 1990, + "AGroup": [{"numbers": 123}, {"numbers": 456}], + "BGroup": [{"numbers": 654}, {"numbers": 321}], + }, + ) + + decoded = s.wrap(encoded) + assert decoded.body["year"] == 1990 + assert decoded.body["AGroup"][1]["numbers"] == 456 + assert decoded.body["BGroup"][1]["numbers"] == 321 From 0b02b869203f3711c4b4a8182e2db4a0db0e8228 Mon Sep 17 00:00:00 2001 From: Khush Jain Date: Thu, 26 Jun 2025 22:25:34 +0530 Subject: [PATCH 2/2] Fix decoding primitive types --- sbe/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbe/__init__.py b/sbe/__init__.py index 4a1d8ff..f38a17b 100644 --- a/sbe/__init__.py +++ b/sbe/__init__.py @@ -1040,7 +1040,7 @@ def _walk_fields_decode(schema: Schema, rv: dict, fields: List[Union[Group, Fiel _walk_fields_decode_composite(schema, rv[f.name], f.type, vals, cursor) else: - if f.type.presence != Presence.CONSTANT: + if isinstance(f.type, PrimitiveType) or f.type.presence != Presence.CONSTANT: _decode_value(schema, rv, f.name, f.type, vals, cursor) def _parse_schema(f: TextIO) -> Schema: