Skip to content

Commit

Permalink
Simplify GreeterProtobuf example (#3715)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Oct 19, 2023
1 parent dde1ad0 commit c26de40
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 47 deletions.
2 changes: 0 additions & 2 deletions examples/GreeterProtobuf/Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
<ProtoFile Include="../proto/greeter.proto">
<ProtoImportPath>../proto</ProtoImportPath>
</ProtoFile>
<PackageReference Include="Google.Protobuf" Version="3.24.4" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.24.4" />
<PackageReference Include="IceRpc" Version="$(Version)" />
<PackageReference Include="IceRpc.Protobuf" Version="$(Version)" />
<PackageReference Include="IceRpc.Protobuf.Tools" Version="$(Version)" PrivateAssets="All" />
</ItemGroup>
Expand Down
7 changes: 3 additions & 4 deletions examples/GreeterProtobuf/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
await using var connection = new ClientConnection(new Uri("icerpc://localhost"));

// GreeterClient is a struct generated by protoc-gen-icerpc-csharp.
var client = new GreeterClient(connection);
var request = new GreetRequest();
request.Name = Environment.UserName;
var greeter = new GreeterClient(connection);

GreetResponse response = await client.GreetAsync(request);
var request = new GreetRequest { Name = Environment.UserName };
GreetResponse response = await greeter.GreetAsync(request);

Console.WriteLine(response.Greeting);

Expand Down
29 changes: 0 additions & 29 deletions examples/GreeterProtobuf/Common/MessageExtensions.cs

This file was deleted.

8 changes: 3 additions & 5 deletions examples/GreeterProtobuf/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# GreeterProtobuf

The GreeterProtobuf example illustrates how to use [Protobuf][protobuf] to encode the payloads of IceRPC requests and
responses.

It's a variation of the [Greeter](Greeter) example that uses Protobuf instead of Slice. See also the
[GreeterCore](GreeterCore) example that uses the same core APIs to create requests and responses.
The GreeterProtobuf example is a variation of the [Greeter](Greeter) example. It sends the same request and receives
the same response, except it uses [Protobuf][protobuf] instead of Slice to define the contract between the client and
the server.

You can build the client and server applications with:

Expand Down
11 changes: 6 additions & 5 deletions examples/GreeterProtobuf/Server/Chatbot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ namespace GreeterProtobufServer;
[ProtobufService]
internal partial class Chatbot : IGreeterService
{
public ValueTask<GreetResponse> GreetAsync(GreetRequest message, IFeatureCollection? features, CancellationToken cancellationToken)
public ValueTask<GreetResponse> GreetAsync(
GreetRequest message,
IFeatureCollection features,
CancellationToken cancellationToken)
{
Console.WriteLine($"Dispatching greet request {{ name = '{message.Name}' }}");
var response = new GreetResponse();
response.Greeting = $"Hello, {message.Name}!";
return new(response);
Console.WriteLine($"Dispatching Greet request {{ name = '{message.Name}' }}");
return new(new GreetResponse { Greeting = $"Hello, {message.Name}!" });
}
}
2 changes: 0 additions & 2 deletions examples/GreeterProtobuf/Server/Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
<ProtoFile Include="../proto/greeter.proto">
<ProtoImportPath>../proto</ProtoImportPath>
</ProtoFile>
<PackageReference Include="Google.Protobuf" Version="3.24.4" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.24.4" />
<PackageReference Include="IceRpc" Version="$(Version)" />
<PackageReference Include="IceRpc.Protobuf" Version="$(Version)" />
<PackageReference Include="IceRpc.Protobuf.Tools" Version="$(Version)" PrivateAssets="All" />
<Compile Include="../../Common/Program.CancelKeyPressed.cs" Link="Program.CancelKeyPressed.cs" />
Expand Down

0 comments on commit c26de40

Please sign in to comment.