diff options
| author | mat <github@matdoes.dev> | 2022-05-25 00:21:05 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-05-25 00:21:05 -0500 |
| commit | 479c05474704a5a2f68b79468d2cde05c0ceec62 (patch) | |
| tree | 59e7192b74caac1566993b202419824993167df0 /codegen/lib/utils.py | |
| parent | fb3b002d94076de463e2af776666387db9e75835 (diff) | |
| download | azalea-drasl-479c05474704a5a2f68b79468d2cde05c0ceec62.tar.xz | |
Migrate might be working
Diffstat (limited to 'codegen/lib/utils.py')
| -rw-r--r-- | codegen/lib/utils.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/codegen/lib/utils.py b/codegen/lib/utils.py index 051ffe51..ff1a5d36 100644 --- a/codegen/lib/utils.py +++ b/codegen/lib/utils.py @@ -1,5 +1,7 @@ import re +# utilities that could be used for things other than codegen + def to_snake_case(name: str): s = re.sub('([A-Z])', r'_\1', name) @@ -13,3 +15,26 @@ def to_camel_case(name: str): def padded_hex(n: int): return f'0x{n:02x}' + + +class PacketIdentifier: + def __init__(self, packet_id, direction, state): + self.packet_id = packet_id + self.direction = direction + self.state = state + + def __eq__(self, other): + return self.packet_id == other.packet_id and self.direction == other.direction and self.state == other.state + + def __hash__(self): + return hash((self.packet_id, self.direction, self.state)) + + +def group_packets(packets: list[PacketIdentifier]): + packet_groups: dict[tuple[str, str], list[int]] = {} + for packet in packets: + key = (packet.direction, packet.state) + if key not in packet_groups: + packet_groups[key] = [] + packet_groups[key].append(packet.packet_id) + return packet_groups |
