(
proto_file: FileDescriptorProto,
)
| 46 | |
| 47 | |
| 48 | def traverse( |
| 49 | proto_file: FileDescriptorProto, |
| 50 | ) -> Generator[ |
| 51 | Tuple[Union[EnumDescriptorProto, DescriptorProto], List[int]], None, None |
| 52 | ]: |
| 53 | # Todo: Keep information about nested hierarchy |
| 54 | def _traverse( |
| 55 | path: List[int], |
| 56 | items: Union[List[EnumDescriptorProto], List[DescriptorProto]], |
| 57 | prefix: str = "", |
| 58 | ) -> Generator[ |
| 59 | Tuple[Union[EnumDescriptorProto, DescriptorProto], List[int]], None, None |
| 60 | ]: |
| 61 | for i, item in enumerate(items): |
| 62 | # Adjust the name since we flatten the hierarchy. |
| 63 | # Todo: don't change the name, but include full name in returned tuple |
| 64 | item.name = next_prefix = f"{prefix}_{item.name}" |
| 65 | yield item, [*path, i] |
| 66 | |
| 67 | if isinstance(item, DescriptorProto): |
| 68 | # Get nested types. |
| 69 | yield from _traverse([*path, i, 4], item.enum_type, next_prefix) |
| 70 | yield from _traverse([*path, i, 3], item.nested_type, next_prefix) |
| 71 | |
| 72 | yield from _traverse([5], proto_file.enum_type) |
| 73 | yield from _traverse([4], proto_file.message_type) |
| 74 | |
| 75 | |
| 76 | def generate_code(request: CodeGeneratorRequest) -> CodeGeneratorResponse: |
no test coverage detected