MCPcopy Create free account
hub / github.com/apache/fory / StructTypeIdVisitor

Class StructTypeIdVisitor

python/pyfory/struct.py:1303–1350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1301
1302
1303class StructTypeIdVisitor(TypeVisitor):
1304 def __init__(
1305 self,
1306 type_resolver,
1307 cls,
1308 ):
1309 self.type_resolver = type_resolver
1310 self.cls = cls
1311
1312 def visit_array(self, field_name, elem_type, carrier, types_path=None):
1313 return [_array_type_id(elem_type, carrier)]
1314
1315 def visit_list(self, field_name, elem_type, types_path=None):
1316 # Infer type recursively for type such as List[Dict[str, str]]
1317 elem_ids = infer_field("item", elem_type, self, types_path=types_path)
1318 return TypeId.LIST, elem_ids
1319
1320 def visit_set(self, field_name, elem_type, types_path=None):
1321 # Infer type recursively for type such as Set[Dict[str, str]]
1322 elem_ids = infer_field("item", elem_type, self, types_path=types_path)
1323 return TypeId.SET, elem_ids
1324
1325 def visit_tuple(self, field_name, elem_types, types_path=None):
1326 elem_type = get_homogeneous_tuple_elem_type(elem_types)
1327 if elem_type is None:
1328 return TypeId.LIST, [TypeId.UNKNOWN]
1329 elem_ids = infer_field("item", elem_type, self, types_path=types_path)
1330 return TypeId.LIST, elem_ids
1331
1332 def visit_dict(self, field_name, key_type, value_type, types_path=None):
1333 # Infer type recursively for type such as Dict[str, Dict[str, str]]
1334 key_ids = infer_field("key", key_type, self, types_path=types_path)
1335 value_ids = infer_field("value", value_type, self, types_path=types_path)
1336 return TypeId.MAP, key_ids, value_ids
1337
1338 def visit_customized(self, field_name, type_, types_path=None):
1339 typeinfo = self.type_resolver.get_type_info(type_, create=False)
1340 if typeinfo is None:
1341 return [TypeId.UNKNOWN]
1342 return [typeinfo.type_id]
1343
1344 def visit_other(self, field_name, type_, types_path=None):
1345 if is_subclass(type_, enum.Enum):
1346 return [self.type_resolver.get_type_info(type_).type_id]
1347 if type_ not in basic_types and not is_primitive_array_type(type_):
1348 return None, None
1349 typeinfo = self.type_resolver.get_type_info(type_)
1350 return [typeinfo.type_id]
1351
1352
1353class StructTypeVisitor(TypeVisitor):

Callers 2

build_field_infosFunction · 0.90
_extract_field_infosFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected