suggestion: Change wire format for enums to integer values #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Foreword
RIDL lets you specify integer values for enums.
On the Golang side, the generated code has access to enum values. e.g.
Problem
On the TypeScript side, there's no access to those values. e.g
This means it's impossible to access those enum kind constants defined in RIDL from any TS code.
Proposed Solution
I propose that we change the generated TS enum values to include the real enum values.
That's what this draft PR shows.
To make this work, the wire format for enum values in WebRPC must also be changed. Since you can't know if a value is an enum value in TypeScript at runtime, we can't decide to keep sending the strings in the WebRPC client code.
I therefore propose that all WebRPC generated bindings change from transmitting enums as strings (
"USER"
) to transmitting them as their enum values (1
).This will also have a side-effect of saving bytes on the wire, saving memory on the client side since there's less strings, and saving memory & CPU on the server side, since you don't have to do a reverse string lookup to find the real value again.
Required work
Change the code for reading/writing enums in TypeScript, Golang, JavaScript, and the generated Swagger/OpenAPI bindings to read/write raw enum integer values instead of strings.