@classmethod
def deserialize(cls, b: bytes):
    """Deserializes bytes to a packet."""
    packet = cls()
    pos = 0
    for name in packet.serializable_fields:
        field = getattr(type(packet), name)
        if field.is_dynamic_length:
            bslice = b[pos:pos + 4]
            pos = pos + 4
            field_len = int.from_bytes(bslice, 'big')
        else:
            field_len = len(field.serialize(getattr(packet, name)))
        bslice = b[pos:pos + field_len]
        pos = pos + field_len
        setattr(packet, name, field.deserialize(bslice))
    return packet
