| 2538 | |
| 2539 | # Generate packet groups |
| 2540 | def _iterfields() -> Iterator[Tuple[str, int]]: |
| 2541 | for f in cls.fields_desc: |
| 2542 | # Fancy field name |
| 2543 | fname = f.name.upper().replace("_", " ") |
| 2544 | fsize = int(f.sz * 8) |
| 2545 | yield fname, fsize |
| 2546 | # Add padding optionally |
| 2547 | if isinstance(f, PadField): |
| 2548 | if isinstance(f._align, tuple): |
| 2549 | pad = - cur_len % (f._align[0] * 8) |
| 2550 | else: |
| 2551 | pad = - cur_len % (f._align * 8) |
| 2552 | if pad: |
| 2553 | yield "padding", pad |
| 2554 | for fname, flen in _iterfields(): |
| 2555 | cur_len += flen |
| 2556 | ident += 1 |