From 7395826a6ae403c91cb3f4e2c7661f6112985aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Bj=C3=B6rkstr=C3=B6m?= Date: Sun, 24 Jan 2021 20:45:31 +0200 Subject: [PATCH] Change order for how FileDescriptors are returned in reflection service. - FileDescriptors should be returned with the service first and then all dependencies after. All dependencies should occur after a FileDescriptor. - See https://github.com/grpc/grpc-go/issues/2949 The Java implementation of the reflection service includes the entire transitive closure for a request file, in toplogical order such that a file's dependencies always appear after the file (so the requested file is first, with all of its dependencies after it). --- src/protobuf-net.Grpc.Reflection/ReflectionService.cs | 8 ++++---- .../ReflectionServiceTests.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/protobuf-net.Grpc.Reflection/ReflectionService.cs b/src/protobuf-net.Grpc.Reflection/ReflectionService.cs index dd46e050..c6f6b1b7 100644 --- a/src/protobuf-net.Grpc.Reflection/ReflectionService.cs +++ b/src/protobuf-net.Grpc.Reflection/ReflectionService.cs @@ -153,19 +153,19 @@ public int Compare(FileDescriptorProto? left, FileDescriptorProto? right) { if (left is null) { - return right is null ? 0 : -1; + return right is null ? 0 : 1; } if (right is null) { - return 1; + return -1; } if (GetTransitiveDependencies(left).Contains(right.Name)) { - return 1; + return -1; } if (GetTransitiveDependencies(right).Contains(left.Name)) { - return -1; + return 1; } return string.Compare(left.Name, right.Name, StringComparison.Ordinal); diff --git a/tests/protobuf-net.Grpc.Reflection.Test/ReflectionServiceTests.cs b/tests/protobuf-net.Grpc.Reflection.Test/ReflectionServiceTests.cs index 8fd77807..6c8093fa 100644 --- a/tests/protobuf-net.Grpc.Reflection.Test/ReflectionServiceTests.cs +++ b/tests/protobuf-net.Grpc.Reflection.Test/ReflectionServiceTests.cs @@ -74,9 +74,9 @@ async IAsyncEnumerable GetRequest() ".ReflectionTest.BclService", new[] { + "ReflectionTest.BclService.proto", "google/protobuf/empty.proto", - "protobuf-net/bcl.proto", - "ReflectionTest.BclService.proto" + "protobuf-net/bcl.proto" } , new[]