Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _choice(self, value, bounds, fields):
#assert isinstance(value, dict)
assert len(value) == 1
for tag, field in fields.items():
if field[0] in value:
self._int(tag, bounds)
self.instance(value[field[0]], field[1])
break
else:
raise IncompleteError(self) # unknown choice field name
def _struct(self, value, fields):
#assert isinstance(value, dict)
# encode each field
for field_name, field_type, _ in fields:
if field_name == '__parent':
# if there is a parent its fields are in the same value dict
self.instance(value, field_type)
elif field_name in value:
self.instance(value[field_name], field_type)
else:
raise IncompleteError(self) # missing field_name
def _choice(self, value, bounds, fields):
#assert isinstance(value, dict)
assert len(value) == 1
self._write_skip(3)
for tag, field in fields.items():
if field[0] in value:
self._vint(tag)
self.instance(value[field[0]], field[1])
break
else:
raise IncompleteError(self) # unknown choice field name