lundi 20 septembre 2021

How to create an enum class that I can use in Python and javascript

I am developing a web game. The server side is written in Python. The game itself is written in Javascript. Each time a game is requested, the game parameters are generated server side. This includes one property for which I have create an enum class.

Now I am trying to figure out an elegant way to pass this property from the python part to the javascript part while keeping the enum consistent. Optimally without having to create a separate enum both in python and javascript.

I already created an enum class in python and for each request pass the integer corresponding to the enum into a JSON which I pass to the application. Preferably I would just use the python enum class again to decode the integer so I know which enum that integer corresponds to. But I have not found a way to do so and I am looking for alternatives. Thank you.

Aucun commentaire:

Enregistrer un commentaire