-
-
Notifications
You must be signed in to change notification settings - Fork 283
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
Different behavior from Google protoc generated message for accessing proto extensions #1583
Comments
Trying to understand the issue.
Like you indiciate, the ScalaPB extensions API works on ScalaPB descriptors/extensions. Is the expectation that it would work with Java descriptors? Can you somehow make the problem statement more clear? |
sry for being confusing. for 1, to be precisely, "by the protocol buffer compiler" in which I mean for 2, yes, I was expect ScalaPB generated descriptors' lens work with Java descriptors, it feels weird to me that ScalaPB generated descriptors' implementation for proto extensions differ from the Java one's. |
I am sorry I still don't follow. Can you provide a minimal project that demonstrate the problem and the expectation that is not met by ScalaPB? In any case, the implementation details do not have to match between ScalaPB and Java - the respective APIs for each should give the same results. |
I guess I can, but would you like to elaborate about which point confused you? I mean if it is like why setup a project like this anyway or what specific code structure I was made to make this situation? Also you actually answered my problem, and I would like to argue a little bit more about it. To be fair, I'm far from protobuf expert by any means, but from a user perspective, I see Descriptor as a data that represent the programmable structure of a proto, also the API And from implementation perspective, it looks reasonable to put extension into |
sry I was not make my point very clear, I've update the Problem section. |
I am still confused. The two screenshots you share show the Java protobufs, none of them is a ScalaPB object, but then you mention you try to access them through the ScalaPB extensions API which isn't supposed to work with the Java objects. |
uh, I knew what I was missed now, I mean I did manually transform Java protobufs( so just for sure, which I was misunderstand and you pointed is, ScalaPB extensions API(generated lens) isn't supposed to work with neither pbc generated Java classes or ScalaPB's if it's true, may I ask is that expected to have Java protobuf generated API(Annotations.http.getExtension) to work with ScalaPB's |
And for clarify what I want to achieve, akka-grpc support both javadsl and scaladsl, and for some reason, javadsl and scaladsl use different code generator, when you try to implement functionality like HTTP transcoding which requires you to parse HttpRule from Descriptors, naturally you would to choose the common part of both generated classes and use Scala API for accessing, and it's Even they're the same type, but the implementation is actually different as I pointed, so after the same transformation procedure(to ScalaPB class), one works and one doesn't. that's why I think it is an issue. |
Also to be fair, I do heard that |
The Java API's
Can you provide a minimal project that demonstrates what doesn't work? |
Bcs some weird issues of akka-grpc I couldn't get the Java API works(google common proto library's Java classes missing from the target), so I haven't test it yet, still working on that. And if that's the case, sry for misunderstanding the API, I will try it. |
Also I just realize that since I'm only copy |
I just update the reproduce project to show it seems |
Thanks for providing the reproduction. It helps understanding the issue you are seeing better. When ScalaPB generates the code for There are two solutions you can have:
The code in |
Thanks for your patience and comprehensive answer. I can see the limitation here now, since akka-grpc doesn't include java classes for scaladsl and vice verse, I guess reconstruct descriptor is the only option.
I was thinking that use Anyway, I have no further question, pls feel free to close this issue. |
Problem
I'm currently trying to implement gRPC HTTP transcoding feature for akka-grpc, but I found there is a weird issue for accessing proto extension.
for proto like this
if the proto class generated by the protocol buffer compiler, MethodDescriptor be like
and if it is generated by the Scala Plugin for the Protocol Buffer Compiler, MethodDescriptor be like
which I highlight the difference, seems pbc itself generated descriptor puts http option into
extension
instead ofunknownFields
.currently I'm using
AnnotationsProto.http.get(methDescriptor)
from ScalaBP generated class forcom.google.api.annotations.proto
, which has a lens that access extension fromunknownFields
, and doesn't work for javadsl(bcs it's using pbc generated java class).IMO, *Descriptor should be some kind of metadata that related only to the proto itself not the implementation, it's really weird to see that even
javaDescriptor
which return a class fromcom.google.protobuf
works differently from "official" implementation, and even in ScalaPB itself actually uses API fromcom.google.protobuf
, only bcs the way to use it causes the difference.So I think it's better to put extension into
extensions
field instead ofunknownSets
at least forjavaDescriptor
, it's more convenient to use under situation also looks more reasonable.Suggested Fixes
After deeper digging, I believe this is bcs when pbc generated class initialize it's
descriptor
there is some extra codes:and inside
internalUpdateFileDescriptor
is just a simple method:both are missing in Scalapb's plugin generated class, so in which I believe the fix should be construct registry for extensions and using another overloading for
com.google.protobuf.DescriptorProtos.FileDescriptorProto.parseFrom
, also changing lens accordingly.Alternative
It causes me really headache to think use difference code for accessing extension for different languages :(
Versions
Scala: 2.12
ScalaPB: 0.11.13
Protobuf: 3.21.9
The text was updated successfully, but these errors were encountered: