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

Don't rely on Enum#ordinal() for serialization #20

Open
Trigary opened this issue Jan 27, 2020 · 3 comments
Open

Don't rely on Enum#ordinal() for serialization #20

Trigary opened this issue Jan 27, 2020 · 3 comments
Assignees

Comments

@Trigary
Copy link
Owner

Trigary commented Jan 27, 2020

The enum declaration order should not be used as a serialization ID. A system was previously in place that supported hardcoded IDs instead of ordinals but was removed due to me not liking all that overhead in the codebase. The boilerplate code in these serializable enums should be abstracted away and this system should be readded.

At the time of creating this issue, there are five enums that need to be serialized. Two of these are in the backend subproject: PacketType and GuiElementType. These are the ones that previously supported this system, and it's easy to implement it again for them.

The other three enums are more complicated because they reside in the api subproject and are inner classes. This means that the client- and server-side might have to have its own, separate enum classes for these data entries or the enums have to be moved to the common subproject. I dislike this second idea because I believe that the quality of the API should be the top priority, and moving them to another subproject means that they can no longer be inner classes and would also expose implementation details that are irrelevant to the plugin developer. (This actually only holds true for ResizeMode, since both Anchor and Alignment define API-accessible "numpad number" IDs which are used for serialization.)

@Trigary
Copy link
Owner Author

Trigary commented Jan 29, 2020

ResizeMode has been removed, ignore what I said regarding it.

@Trigary Trigary self-assigned this Mar 5, 2020
@yannicklamprecht
Copy link

The easy way would be to send the name instead.
Other idea is to have a register mappings packet. Where you initially send an Enum.name <-> Enum.ordinal map.

What is your idea?

@Trigary
Copy link
Owner Author

Trigary commented Mar 14, 2020

Giving each enum value a hardcoded numerical ID.

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