Exercise: Encode Bi-Directional Streaming API
Implement a bidirectional streaming RPC in the text editor system which returns a stream of encoded strings in response to a stream of client requests.
Encode text RPC
In this exercise, your goal is to implement an encode
bi-directional streaming API in a TextEditorService
.
The function takes a stream of
Request
messages where each message contains a string.It returns a stream of
Result
messages where each message represents an encoded version of the input string.
Follow these steps:
Define the RPC in a .proto file: Define the RPC in the service definition in the proto file.
Implement the server code: Implement the server logic to handle the bi-directional streaming requests and return the encoded responses.
Test the server code by implementing the client: Ensure the client can send multiple strings and receive the encoded strings back.
Example:
The client will send a stream of strings (“hello”, “world”, “from”, “gRPC!”) and the server will respond with a stream of encoded strings (“ifmmp”, “xpsme”, “gspn”, “hSQD"”).
Good luck!
Step 1: Define the RPC in the .proto file
Add the encode
RPC to the TextEditorService
in the text-editor.proto
file. ...