I was trying to implement a generic way to create ...
# announcements
c
I was trying to implement a generic way to create a message in gRPC without creating a Kotlin specific code generator. I wondered if there was a way to just pass SendRequest as a type and infer the SendRequest.Builder, indeed I cannot things like T.Builder
n
is it maybe possible to derive Messgae from Message.Builder ? so your only type arguemnt would be Message.Builder
or is builder having generic parameters that can be used ?
c
uhmm, let me check, maybe
I need to dig into the gRPC generated code
uhm, found: getDefaultInstanceForType I might be able to use that
ok I'll give it a shot and see
n
but that will not be available for getting the returntype probably...
c
yes, it's a bit difficult indeed
from Message, there is a way to get Message.Builder, but still then I don't have it's type
and viceversa
From Message.Builder I can get Message.
g
A bit offtopic, just want mention that there are a few projects that provide Kotlin specific generators for gRPC Like https://github.com/marcoferrer/kroto-plus
c
yes am aware of that, but he relies on code generation
g
yes, sure
same way as grpc for java
nothing wrong to write some helper for gRPC java code tho Just thought that it worth to mention
c
I suggested some helpers here at the end: https://github.com/Kotlin/kotlinx.coroutines/issues/360
hopefully they can pick as a suggestion for the integration proposal
g
I really against any gRPC integration in kotlinx.coroutines
c
ah, why?
g
Because each integration should depend on particular generation code
probably just better to keep it separately
also default Java generated code just doesn’t allow to write simple coroutine adapter
c
indeed I agree with you, I figured it out myself, code generators I try to avoid if I can...
g
I’m not really understand what you mean:
The idea of having the code automatically generated is very nice, but in my case, adding an extra step to the the build is more cumbersome
But you already have this step to generate Jva
it’s just impossible to use gRPC without code generation, this is whole point of gRPC to have generated services and data objects
c
Indeed I see, I stumbled into problems
g
good thing, that gRPC gradle plugin allows to have custom code generator plugin, so you can replace Java code generation with Kotlin code generation and provide data classes, coroutines and all other Kotlin features
bad thing that it’s really big project and hope community at some point focus on some single library, kroto-plus or grpc-kotlin
Maybe even gRPC team will help