Skip to content

Commit

Permalink
Additional review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone committed Oct 18, 2023
1 parent d7021e4 commit 71dae57
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/IceRpc.Protobuf/InvokerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class InvokerExtensions
[RequestFieldKey.Idempotent] = default
}.ToImmutableDictionary();

// <summary>Sends a request to a service and decodes the response.</summary>
/// <summary>Sends a request to a service and decodes the response.</summary>
/// <typeparam name="T">The response type.</typeparam>
/// <param name="invoker">The invoker used to send the request.</param>
/// <param name="serviceAddress">The address of the target service.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
</None>
<None Include="$(IntermediateOutputPath)/$(AssemblyName).dll" Pack="true" PackagePath="tasks/" Visible="false" />
<!-- Use the compilers from this source build. -->
<Content Include="../IceRpc.ProtocGen/bin/$(Configuration)/net8.0/*">
<Content Include="../IceRpc.ProtocGen/bin/$(Configuration)/net8.0/*"
Exclude="../IceRpc.ProtocGen/bin/$(Configuration)/net8.0/*.exe">
<PackagePath>tools/</PackagePath>
<Pack>true</Pack>
</Content>
Expand Down
4 changes: 2 additions & 2 deletions tools/protobuf/IceRpc.Protobuf.Tools/ProtocTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected override string GenerateCommandLineCommands()
{
string protocPluginExe =
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
"protoc-gen-icerpc-csharp.exe" : "protoc-gen-icerpc-csharp";
"protoc-gen-icerpc-csharp.bat" : "protoc-gen-icerpc-csharp.sh";

var builder = new CommandLineBuilder(false);

Expand All @@ -68,7 +68,7 @@ protected override string GenerateCommandLineCommands()

var importPath = new List<string>(ImportPath);
// Add the sources directories to the import path
var computedSources = new List<ITaskItem>();
var computedSources = new List<ITaskItem>();
foreach (ITaskItem source in Sources)
{
string fullPath = source.GetMetadata("FullPath");
Expand Down
21 changes: 12 additions & 9 deletions tools/protobuf/IceRpc.ProtocGen/ClientGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ internal static string GenerateInterface(ServiceDescriptor service)
global::System.Threading.CancellationToken cancellationToken = default);";
}
return @$"
/// <remarks>protoc-gen-icerpc-csharp generated this client-side interface from Protobuf service <c>{service.Name}</c>.
/// It's implemented by <c>{service.Name.ToPascalCase()}Client</c></remarks>
public partial interface I{service.Name.ToPascalCase()}
{{
{operations.Trim()}
Expand All @@ -49,18 +51,18 @@ internal static string GenerateImplementation(ServiceDescriptor service)
{inputType} message,
IceRpc.Features.IFeatureCollection? features = null,
global::System.Threading.CancellationToken cancellationToken = default) =>
IceRpc.Protobuf.InvokerExtensions.InvokeAsync(
InvokerExtensions.InvokeAsync(
Invoker,
ServiceAddress,
""{method.Name}"",
IceRpc.Protobuf.MessageExtensions.ToPipeReader(message),
message.ToPipeReader(),
payloadContinuation: null,
async (response, request, cancellationToken) =>
{{
if (response.StatusCode == IceRpc.StatusCode.Ok)
{{
var returnValue = new {returnType}();
await IceRpc.Protobuf.MessageExtensions.MergeFromAsync(returnValue, response.Payload).ConfigureAwait(false);
await returnValue.MergeFromAsync(response.Payload).ConfigureAwait(false);
return returnValue;
}}
else
Expand All @@ -79,24 +81,25 @@ internal static string GenerateImplementation(ServiceDescriptor service)
return @$"
/// <summary>Makes invocations on a remote IceRPC service. This remote service must implement Protobuf service
/// <c>{service.Name}</c>.</summary>
/// <remarks>The IceRpc.ProtocGen protoc plugin generated this client struct from the Protobuf service <c>{service.Name}</c>.</remarks>
public partial struct {clientImplementationName} : I{service.Name.ToPascalCase()}
/// <remarks>protoc-gen-icerpc-csharp generated this record struct from Protobuf service <c>{service.Name}</c>.</remarks>
public readonly partial record struct {clientImplementationName} : I{service.Name.ToPascalCase()}
{{
/// <summary>Gets the default service address for services that implement Protobuf service {service.FullName}.
/// Its protocol is <see cref=""IceRpc.Protocol.IceRpc"" /> and its path is computed from the name of the Protobuf service.
/// Its protocol is <c>icerpc</c> and its path is the Protobuf service name.
/// </summary>
public static IceRpc.ServiceAddress DefaultServiceAddress {{ get; }} =
new(IceRpc.Protocol.IceRpc) {{ Path = ""/{service.Name}"" }};
/// <summary>Gets or initializes the invocation pipeline of this client.</summary>
/// <summary>Gets or initializes the invoker of this client.</summary>
public IceRpc.IInvoker Invoker {{ get; init; }}
/// <summary>Gets or initializes the address of the remote service.</summary>
IceRpc.ServiceAddress ServiceAddress {{ get; init; }}
/// <summary>Constructs a client from an invoker and a service address.</summary>
/// <param name=""invoker"">The invocation pipeline of the proxy.</param>
/// <param name=""serviceAddress"">The service address. <see langword=""null"" /> is equivalent to <see cref=""DefaultServiceAddress"" />.</param>
/// <param name=""invoker"">The invoker of this client.</param>
/// <param name=""serviceAddress"">The service address. <see langword=""null"" /> is equivalent to
/// <see cref=""DefaultServiceAddress"" />.</param>
public {clientImplementationName}(
IceRpc.IInvoker invoker,
IceRpc.ServiceAddress? serviceAddress = null)
Expand Down
9 changes: 7 additions & 2 deletions tools/protobuf/IceRpc.ProtocGen/IceRpc.ProtocGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>protoc-gen-icerpc-csharp</AssemblyName>
</PropertyGroup>

<ItemGroup>
<Compile Include="../Common/IceRpc.CaseConverter.Internal/Converter.cs" />
<PackageReference Include="Google.Protobuf" Version="3.24.1" />
<PackageReference Include="Google.Protobuf" Version="3.24.4" />
<None Include="protoc-gen-icerpc-csharp.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="protoc-gen-icerpc-csharp.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
8 changes: 5 additions & 3 deletions tools/protobuf/IceRpc.ProtocGen/ServiceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public static string GenerateInterface(ServiceDescriptor service)
IceRpc.Features.IFeatureCollection features,
global::System.Threading.CancellationToken cancellationToken);";

// Add a static method for each service method, the implementation calls the
// abstract method and creates the outgoing response.
// Add a static method for each service method, the implementation calls the abstract method and creates
// the outgoing response.
methods += $@"
[ProtobufOperation(""{method.Name}"")]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
protected static async global::System.Threading.Tasks.ValueTask<IceRpc.OutgoingResponse> {methodName}(
protected static async global::System.Threading.Tasks.ValueTask<IceRpc.OutgoingResponse> ProtobufD{methodName}(
I{service.Name.ToPascalCase()}Service target,
IceRpc.IncomingRequest request,
global::System.Threading.CancellationToken cancellationToken)
Expand All @@ -44,6 +44,8 @@ public static string GenerateInterface(ServiceDescriptor service)
}

return @$"
/// <remarks>protoc-gen-icerpc-csharp generated this server-side interface from Protobuf service <c>{service.Name}</c>.
/// </remarks>
public partial interface I{service.Name.ToPascalCase()}Service
{{
{methods.Trim()}
Expand Down
3 changes: 3 additions & 0 deletions tools/protobuf/IceRpc.ProtocGen/protoc-gen-icerpc-csharp.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo OFF

call dotnet %~dp0\IceRpc.ProtocGen.dll -- %*
4 changes: 4 additions & 0 deletions tools/protobuf/IceRpc.ProtocGen/protoc-gen-icerpc-csharp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
dotnet $DIR/IceRpc.ProtocGen.dll -- "$@"

0 comments on commit 71dae57

Please sign in to comment.