Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protodef Switches are a confusing type #312

Closed
nickelpro opened this issue Jul 26, 2020 · 2 comments
Closed

Protodef Switches are a confusing type #312

nickelpro opened this issue Jul 26, 2020 · 2 comments

Comments

@nickelpro
Copy link
Member

nickelpro commented Jul 26, 2020

Protodef Switches are used to encode three distinct ideas right now and it's really burdensome to build a code generator that cleanly does all three.

The first and most natural use for the switch is a sum type, such as entity metadata.

The second is a multi-element switch, which is a set of consistent types some or all of which are en/decoded depending on the compareTo variable. An example for this is the Boss Bar packet.

The final type is an optional type, which is a single consistent type that is en/decoded based on compareTo. An example is the Advancements packet.

The way you naively want to approach serializing, deserializing, and representing these three in strongly typed languages is different. Sum types want to be stored in a union and accessed with a switch, multi-elements want to be stored as a struct/class and accessed with a switch, and optionals want to be stored as a single field and accessed with a conditional or something like std::optional.

I've built a (very poor) generator for C and am currently building a (hopefully better) one for C++. In both switches are by far the most complicated structure to parse, and require introspection to try to merge multi-element-type switches.

This issue is mostly me complaining, feel free to close. I don't think Protodef has the required machinery to describe the latter two types I've laid out here, and switches are being used as crude kludge. In JS it likely doesn't matter, so I can understand this being a non-priority.

@rom1504
Copy link
Member

rom1504 commented Jul 26, 2020 via email

@nickelpro
Copy link
Member Author

Not the repo to fix this in

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

No branches or pull requests

2 participants