Skip to content

Commit

Permalink
add server/client stub usage example to generated code spec (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscheong01 authored Mar 7, 2024
1 parent b272199 commit 3c8f80a
Showing 1 changed file with 27 additions and 0 deletions.
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")
)
```

0 comments on commit 3c8f80a

Please sign in to comment.