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

[discussion] compatible with two cases #16

Open
blackhuman opened this issue Jun 30, 2023 · 2 comments
Open

[discussion] compatible with two cases #16

blackhuman opened this issue Jun 30, 2023 · 2 comments

Comments

@blackhuman
Copy link

blackhuman commented Jun 30, 2023

There were some cases I encountered in wild, I will illustrate using the following code as an example.

message Persons {
  Person person = 1;
  Person person_2nd = 2;
  oneof TagCode {
    string tag = 3;
    string tag_2nd = 4;
  }
}

oneof type

In the provided code, if the type name of "oneof" is capitalized (which is technically not recommended and may be considered illegal), the "krotoDC" fails to generate the code correctly. However, if we compare it with the code generated by the Protoc Java plugin for the "oneof" type, we observe that making the first character lowercase produces the same result as the Java plugin.
image

special field name like xx_2nd

In the provided code, if the field name follows the pattern "_{digit}{first_alphabet}{other_alphabets}", the "protoc" Java plugin converts the first alphabet of "xx_2nd" to uppercase, resulting in "xx2Nd". However, in the current implementation of the "krotoDC" code, the field name is converted to "xx2nd", which is not compatible with the original Java code.
image

The draft PR serves as a reference, and it's important to note that the implementation is subject to change.

@mscheong01
Copy link
Owner

Hi, thanks for the detailed explanations!

  1. oneof names
    I'm aware with issues that can arise from oneof names, which was also reported in Problem when the name of a 'oneof' field matches the name of the message. #4. However, I'm still considering whether these cases should be handled. As you mentioned, this kind of proto definitions are against the basic conventions and will not likely be used. If we decide to take care of this, I think the solution will be to change the oneof sealed class names to ~Oneof (although it is breaking change)
  2. special field name like xx_2nd -> I was not aware of this issue. I'll look into your PR soon!

@blackhuman
Copy link
Author

Regarding point 1, while it is certainly a significant matter, I cannot recall any instances where the oneof field name generated by protobuf-java was directly referenced in actual code. From what I understand, the existence of the 'tagCode' field (as seen in the example above) is primarily intended to ensure successful compilation. Since my knowledge of protobuf is limited, I cannot say for certain whether this implementation would disrupt existing code.

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