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
Fix protobuf enums representation in generated scala. #100
Comments
Hi @toddburnside! Thanks for the report, that makes totally sense. Indeed, as you describe, they both seem not to form an isomorphism but an epimorphism. The first option you propose, adding new values to the AST (TSumIntegral/TSumValued) I'd avoid it in order to not grow the AST too big, since it's already a bit too much. The approach I'm following in the
Some examples of annotations I'm using in UAST are precision & sign in numeric values of protobuf (see https://github.com/higherkindness/skeuomorph/pull/61/files#diff-0d4b6356cd9fc5dfda83f34f307481e3R109) What do you think? |
@pepegar, those are some interesting suggestions and would be a definite improvement on my idea. I'll have to look through your code more and think about how I can make it work for this situation. Off the top of my head:
I'll look into it more tomorrow. |
Sorry for the long delay... I’ve been looking at the uast branch, and unless I’m missing something, the use of Maybe we could update the mu On the use of |
@pepegar: (side discussion) - while this solution is evolving is there any way to go around by using hand crafted enum class in Scala (with |
This is now fixed in the latest version, see higherkindness/mu-scala#611 (comment) |
This issue is a related to Mu issue higherkindness/mu-scala#611.
Given this protobuf enum:
This scala code is currently generated:
Not only does this lose the integral value assigned to each enum member, but it does not work correctly with PBDirect - an empty field is sent over the wire and deserialization produces the wrong value.
For PBDirect, the enum needs to be encoded like this:
One issue involved here is that, in mu/Transform.scala, both protobuf and avro enums are mapped to the
MuF
TSum
, where the integral value associated with the enum members.Since avro enums don't have the concept of assigned integral values, this makes them not isomorphic with the protobuf enums. So, one way forward would be to create a new
MuF
instance named something likeTSumIntegral
orTSumValued
that preserves the integer associated with the protobuf enums.This would be a fairly simple change, but it does mean that the code generated by skeumorph for the protobuf enums would be PBDirect specific. (
Pos
,Pos._1
, etc. are defined in PBDirect.) This would mean that the MuF representation would not be completely decoupled from protobuf.I would love to hear if someone has some better ideas.
Note: If we do add the
extends Pos
etc.,import pbdirect.Pos
will need to be added to the top of the generated source file. This is done by Mu in ProtoSrcGenerator.scala. The ProtoSrcGenTests would also need to be updated.The skeumorph readme also contains an example enum and generated code.
The text was updated successfully, but these errors were encountered: