Skip to content

Commit e5e1f62

Browse files
committed
Handle composites with reference and set types
1 parent 5a3ab80 commit e5e1f62

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

sbe/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ class Set:
276276
semanticType: Optional[str] = None
277277
description: Optional[str] = None
278278
choices: List[SetChoice] = field(default_factory=list)
279+
padding = 0
279280

280281
def encode(self, vals: Iterable[str]) -> int:
281282
vals = set(vals)
@@ -638,6 +639,10 @@ def _unpack_format(
638639

639640
return _unpack_format(schema, type_.encodingType, '', buffer, buffer_cursor)
640641

642+
if isinstance(type_, RefType):
643+
t = schema.types[type_.type]
644+
return _unpack_format(schema, t, prefix, buffer, buffer_cursor)
645+
641646
if isinstance(type_, Composite):
642647
return prefix + ''.join(_unpack_format(schema, t, '', buffer, buffer_cursor) for t in type_.types)
643648

@@ -867,14 +872,22 @@ def _walk_fields_wrap_composite(
867872
assert isinstance(t.encodingType, EnumEncodingType)
868873
t1 = PrimitiveType(t.encodingType.value)
869874
l = 1
875+
elif isinstance(t, Set):
876+
if isinstance(t.encodingType, Type):
877+
t1 = t.encodingType.primitiveType
878+
l = t.encodingType.length
879+
else:
880+
assert isinstance(t.encodingType, SetEncodingType)
881+
t1 = PrimitiveType(t.encodingType.value)
882+
l = 1
870883
else:
871884
assert isinstance(t, Type)
872885
t1 = t.primitiveType
873886
l = t.length
874887

875888
cursor.val += t.padding
876889
if t1 == PrimitiveType.CHAR:
877-
if l> 1:
890+
if l > 1:
878891
rv[t.name] = Pointer(cursor.val, str(l) + "s", l)
879892
cursor.val += t.length
880893
else:

0 commit comments

Comments
 (0)