Finds the largest (force_align: N) N value in flatbuffer schemas.
| 80 | |
| 81 | |
| 82 | class _SchemaMaxAlignmentGetter: |
| 83 | """Finds the largest (force_align: N) N value in flatbuffer schemas.""" |
| 84 | |
| 85 | def __init__(self) -> None: |
| 86 | self.max_alignment: int = 0 |
| 87 | |
| 88 | def __call__(self, schema: bytes) -> bytes: |
| 89 | """Finds all `(force_align: N)` instances and updates max_alignment. |
| 90 | |
| 91 | Returns the input schema unmodified. |
| 92 | """ |
| 93 | regex = re.compile(rb"\(\s*force_align\s*:\s*(\d+)\s*\)") |
| 94 | matches = regex.findall(schema) |
| 95 | for alignment in [int(match) for match in matches]: |
| 96 | if alignment > self.max_alignment: |
| 97 | self.max_alignment = alignment |
| 98 | return schema |
| 99 | |
| 100 | |
| 101 | class _SchemaFileIdentifierGetter: |