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

add server/client stub usage example to generated code spec #30

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,30 @@ this is useful for interoperability with other libraries that use protobuf-java
for all protobuf services, the plugin will generate a Kotlin Class with a ~GrpcKroto suffix.
the class will contain a CoroutineServiceBase and a CoroutineStub.
Their functionality is identical to that of the grpc-kotlin library, but the method stubs use krotoDC generated protobuf dataclasses as request and response types

example usage:
server
```kotlin
// define
class SimpleServiceImpl : SimpleServiceGrpcKroto.SimpleServiceCoroutineImplBase() {
override suspend fun sayHello(request: HelloRequest): HelloResponse {
return HelloResponse(
greeting = "Hello, ${request.name}!"
)
}
}
// host
val server = ServerBuilder
.forPort(8080)
.addService(SimpleServiceImpl())
.build()
server.start()
```
client
```kotlin
val channel = ManagedChannelBuilder.forAddress("localhost", 8080).usePlaintext().build()
val stub = SimpleServiceGrpcKroto.SimpleServiceCoroutineStub(channel)
val response = stub.sayHello(
HelloRequest(name = "KrotoDC")
)
```
Loading