marcoferrer / kroto-plus

gRPC Kotlin Coroutines, Protobuf DSL, Scripting for Protoc
Apache License 2.0
494 stars 28 forks source link

Generating coroutines for existing Java stubs (without .proto)? #60

Closed peter-lyons-kehl closed 5 years ago

peter-lyons-kehl commented 5 years ago

May I admit ignorance of Kroto+ internals. Does Kroto+ require .proto file(s), or does it [after protoc and javac] load the Java classes, inspects them by reflection, and generates the coroutines from them only?

Say you have access to Java classes generated by protoc (for example, as artifacts from Maven). Removing a copy of .proto would mean one less step to maintain. (Of course, if the generated classes change, then the developer may have to update the coroutines, too.)

peter-lyons-kehl commented 5 years ago

An example is https://github.com/grpc/grpc-java/blob/master/services/src/main/proto/grpc/health/v1/health.proto, which has the generated Java classes on Maven Central.

marcoferrer commented 5 years ago

So kroto does in fact generate coroutines clients. There’s no reflection involved. Setting up the codegen to run for an existing artifact from maven is trivial. The process is explained in detail here https://github.com/google/protobuf-gradle-plugin/blob/master/README.md#protos-in-dependencies

If you didn’t want to configure code gen then you could technically use the call builders directly. The generated stubs do this internally similar to the code generated by the default grpc java plugin. https://github.com/marcoferrer/kroto-plus/blob/e88d06241a129665c584aae709ddda61eeb121ef/kroto-plus-coroutines/src/main/kotlin/com/github/marcoferrer/krotoplus/coroutines/client/ClientCalls.kt#L59

peter-lyons-kehl commented 5 years ago

Thank you.