Skip to content

Move more packet formatting code to dataio#2848

Open
lmoureaux wants to merge 22 commits intolongturn:masterfrom
lmoureaux:refactor/packets
Open

Move more packet formatting code to dataio#2848
lmoureaux wants to merge 22 commits intolongturn:masterfrom
lmoureaux:refactor/packets

Conversation

@lmoureaux
Copy link
Contributor

This builds on #2845 to move basic packet serialization logic out of generate_packets.py. Enums and arrays no longer need explicitly generated code; they rely on template functions in dataio instead. For instance, reading a packet now looks like this regardless of the data types involved:

  ...
  /* field 5 is folded into the header */
  /* field 6 is folded into the header */
  if (BV_ISSET(fields, 7)) {
    log_packet_detailed("  field 'name' has changed");
    dio_put(dout, packet->name);
  }
  if (BV_ISSET(fields, 8)) {
    log_packet_detailed("  field 'hp' has changed");
    dio_put(dout, packet->hp, std::uint8_t{});
  }
  if (BV_ISSET(fields, 9)) {
    log_packet_detailed("  field 'activity' has changed");
    dio_put(dout, packet->activity, std::uint8_t{});
  }
  ...

The generated code used to contain a lot of logic such as loops. This is now entirely gone (as far as the dio_* part is concerned).

I was a bit ambitious and ported everything at once. It builds but
connection fails. This will get fixed in later commits.
The switch happens before SEND_PACKET_END is run. We thus need to cache
it from SEND_PACKET_BEGIN.
This will facilitate serialization.
This allows all information to flow through function arguments, unifying
the interface between types.
This removes a special case from generate_packets.py
This removes a special case from generate_packets.py
This moves complexity from the generated code to normal source files.
The get_ and put_ interfaces are also getting even closer.
Use QByteArray features to manipulate attribute contents, avoiding
error-prone low-level dio calls.
With this change, all dio_get calls in packets_gen.cpp share the same
syntax: dio_get(din, field, args...). Only the arguments differ. This
simplifies the generated code.
This allows unifying all dio_put calls with the same syntax.
After moving a lot of code to dataio, generate_packets can become
simpler.
@lmoureaux lmoureaux requested a review from jwrober February 28, 2026 01:36
@jwrober
Copy link
Collaborator

jwrober commented Feb 28, 2026

Looks like Codacy found some issues. I'd prefer to merge the referenced PR and then rebase this before I review this PR.

@lmoureaux
Copy link
Contributor Author

Agreed on the rebase. I fixed the unreachable code from codacy, the other checks trigger whenever one uses memcpy() (also when it is used correctly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants