Skip to content

Commit 859749a

Browse files
committed
Update fetch and generate scripts for reflection
Motivation: To add the reflection service we need to fetch it and generate the appropriate code. Modifications: - Update proto fetching script to get v1 reflection service - Update proto generating script to generate reflection service code and messages - Also add protos used in tests for the reflection service and generate their descriptor sets Result: Generated code is in place
1 parent aadf8c9 commit 859749a

File tree

7 files changed

+1346
-3
lines changed

7 files changed

+1346
-3
lines changed

Sources/GRPCReflectionService/Generated/reflection.grpc.swift

Lines changed: 346 additions & 0 deletions
Large diffs are not rendered by default.

Sources/GRPCReflectionService/Generated/reflection.pb.swift

Lines changed: 775 additions & 0 deletions
Large diffs are not rendered by default.

dev/protos/fetch.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ rm -rf "$upstream"
3030
# Create new directories to poulate. These are based on proto package name
3131
# rather than source repository name.
3232
mkdir -p "$upstream/grpc/health/v1"
33+
mkdir -p "$upstream/grpc/reflection/v1"
3334

3435
# Copy over the grpc-proto protos.
3536
cp -rp "$checkouts/grpc-proto/grpc/health/v1/health.proto" "$upstream/grpc/health/v1/health.proto"
37+
cp -rp "$checkouts/grpc-proto/grpc/reflection/v1/reflection.proto" "$upstream/grpc/reflection/v1/reflection.proto"

dev/protos/generate.sh

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,65 @@ function generate_health_service {
9494
generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "Client=true" "Server=true" "UseAccessLevelOnImports=true"
9595
}
9696

97+
function generate_reflection_service {
98+
local proto="$here/upstream/grpc/reflection/v1/reflection.proto"
99+
local output="$root/Sources/GRPCReflectionService/Generated"
100+
101+
# Messages were accidentally leaked into public API, they shouldn't be but we
102+
# can't undo that change until the next major version.
103+
generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "UseAccessLevelOnImports=true"
104+
generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "UseAccessLevelOnImports=true"
105+
}
106+
107+
#- TEST DATA ------------------------------------------------------------------
108+
109+
function generate_reflection_service_descriptor_set {
110+
local proto="$here/upstream/grpc/reflection/v1/reflection.proto"
111+
local proto_path="$here/upstream"
112+
local output="$root/Tests/GRPCReflectionServiceTests/Generated/DescriptorSets/reflection.pb"
113+
114+
invoke_protoc --descriptor_set_out="$output" "$proto" -I "$proto_path" \
115+
--include_source_info \
116+
--include_imports
117+
}
118+
119+
function generate_health_service_descriptor_set {
120+
local proto="$here/upstream/grpc/health/v1/health.proto"
121+
local proto_path="$here/upstream"
122+
local output="$root/Tests/GRPCReflectionServiceTests/Generated/DescriptorSets/health.pb"
123+
124+
invoke_protoc --descriptor_set_out="$output" "$proto" -I "$proto_path" \
125+
--include_source_info \
126+
--include_imports
127+
}
128+
129+
function generate_extended_message_descriptor_set {
130+
local proto="$here/tests/reflection/base_message.proto"
131+
local proto_path="$here/tests/reflection"
132+
local output="$root/Tests/GRPCReflectionServiceTests/Generated/DescriptorSets/base_message.pb"
133+
134+
invoke_protoc --descriptor_set_out="$output" "$proto" -I "$proto_path" \
135+
--include_source_info \
136+
--include_imports
137+
}
138+
139+
function generate_message_with_dependency_descriptor_set {
140+
local proto="$here/tests/reflection/message_with_dependency.proto"
141+
local proto_path="$here/tests/reflection"
142+
local output="$root/Tests/GRPCReflectionServiceTests/Generated/DescriptorSets/message_with_dependency.pb"
143+
144+
invoke_protoc --descriptor_set_out="$output" "$proto" -I "$proto_path" \
145+
--include_source_info \
146+
--include_imports
147+
}
148+
97149
#------------------------------------------------------------------------------
98150

99-
# Interoperability tests
100151
generate_interop_test_service
101-
102-
# Health service
103152
generate_health_service
153+
generate_reflection_service
154+
155+
generate_reflection_service_descriptor_set
156+
generate_health_service_descriptor_set
157+
generate_extended_message_descriptor_set
158+
generate_message_with_dependency_descriptor_set
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
syntax = "proto2";
2+
3+
message BaseMessage {
4+
required string id = 1;
5+
6+
extensions 100 to 101;
7+
}
8+
9+
extend BaseMessage {
10+
optional int32 extended_field = 100;
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
syntax = "proto3";
2+
3+
import "google/protobuf/empty.proto";
4+
5+
message MessageWithDependency {
6+
google.protobuf.Empty empty = 1;
7+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// Copyright 2016 The gRPC Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Service exported by server reflection. A more complete description of how
16+
// server reflection works can be found at
17+
// https://github.com/grpc/grpc/blob/master/doc/server-reflection.md
18+
//
19+
// The canonical version of this proto can be found at
20+
// https://github.com/grpc/grpc-proto/blob/master/grpc/reflection/v1/reflection.proto
21+
22+
syntax = "proto3";
23+
24+
package grpc.reflection.v1;
25+
26+
option go_package = "google.golang.org/grpc/reflection/grpc_reflection_v1";
27+
option java_multiple_files = true;
28+
option java_package = "io.grpc.reflection.v1";
29+
option java_outer_classname = "ServerReflectionProto";
30+
31+
service ServerReflection {
32+
// The reflection service is structured as a bidirectional stream, ensuring
33+
// all related requests go to a single server.
34+
rpc ServerReflectionInfo(stream ServerReflectionRequest)
35+
returns (stream ServerReflectionResponse);
36+
}
37+
38+
// The message sent by the client when calling ServerReflectionInfo method.
39+
message ServerReflectionRequest {
40+
string host = 1;
41+
// To use reflection service, the client should set one of the following
42+
// fields in message_request. The server distinguishes requests by their
43+
// defined field and then handles them using corresponding methods.
44+
oneof message_request {
45+
// Find a proto file by the file name.
46+
string file_by_filename = 3;
47+
48+
// Find the proto file that declares the given fully-qualified symbol name.
49+
// This field should be a fully-qualified symbol name
50+
// (e.g. <package>.<service>[.<method>] or <package>.<type>).
51+
string file_containing_symbol = 4;
52+
53+
// Find the proto file which defines an extension extending the given
54+
// message type with the given field number.
55+
ExtensionRequest file_containing_extension = 5;
56+
57+
// Finds the tag numbers used by all known extensions of the given message
58+
// type, and appends them to ExtensionNumberResponse in an undefined order.
59+
// Its corresponding method is best-effort: it's not guaranteed that the
60+
// reflection service will implement this method, and it's not guaranteed
61+
// that this method will provide all extensions. Returns
62+
// StatusCode::UNIMPLEMENTED if it's not implemented.
63+
// This field should be a fully-qualified type name. The format is
64+
// <package>.<type>
65+
string all_extension_numbers_of_type = 6;
66+
67+
// List the full names of registered services. The content will not be
68+
// checked.
69+
string list_services = 7;
70+
}
71+
}
72+
73+
// The type name and extension number sent by the client when requesting
74+
// file_containing_extension.
75+
message ExtensionRequest {
76+
// Fully-qualified type name. The format should be <package>.<type>
77+
string containing_type = 1;
78+
int32 extension_number = 2;
79+
}
80+
81+
// The message sent by the server to answer ServerReflectionInfo method.
82+
message ServerReflectionResponse {
83+
string valid_host = 1;
84+
ServerReflectionRequest original_request = 2;
85+
// The server sets one of the following fields according to the message_request
86+
// in the request.
87+
oneof message_response {
88+
// This message is used to answer file_by_filename, file_containing_symbol,
89+
// file_containing_extension requests with transitive dependencies.
90+
// As the repeated label is not allowed in oneof fields, we use a
91+
// FileDescriptorResponse message to encapsulate the repeated fields.
92+
// The reflection service is allowed to avoid sending FileDescriptorProtos
93+
// that were previously sent in response to earlier requests in the stream.
94+
FileDescriptorResponse file_descriptor_response = 4;
95+
96+
// This message is used to answer all_extension_numbers_of_type requests.
97+
ExtensionNumberResponse all_extension_numbers_response = 5;
98+
99+
// This message is used to answer list_services requests.
100+
ListServiceResponse list_services_response = 6;
101+
102+
// This message is used when an error occurs.
103+
ErrorResponse error_response = 7;
104+
}
105+
}
106+
107+
// Serialized FileDescriptorProto messages sent by the server answering
108+
// a file_by_filename, file_containing_symbol, or file_containing_extension
109+
// request.
110+
message FileDescriptorResponse {
111+
// Serialized FileDescriptorProto messages. We avoid taking a dependency on
112+
// descriptor.proto, which uses proto2 only features, by making them opaque
113+
// bytes instead.
114+
repeated bytes file_descriptor_proto = 1;
115+
}
116+
117+
// A list of extension numbers sent by the server answering
118+
// all_extension_numbers_of_type request.
119+
message ExtensionNumberResponse {
120+
// Full name of the base type, including the package name. The format
121+
// is <package>.<type>
122+
string base_type_name = 1;
123+
repeated int32 extension_number = 2;
124+
}
125+
126+
// A list of ServiceResponse sent by the server answering list_services request.
127+
message ListServiceResponse {
128+
// The information of each service may be expanded in the future, so we use
129+
// ServiceResponse message to encapsulate it.
130+
repeated ServiceResponse service = 1;
131+
}
132+
133+
// The information of a single service used by ListServiceResponse to answer
134+
// list_services request.
135+
message ServiceResponse {
136+
// Full name of a registered service, including its package name. The format
137+
// is <package>.<service>
138+
string name = 1;
139+
}
140+
141+
// The error code and error message sent by the server when an error occurs.
142+
message ErrorResponse {
143+
// This field uses the error codes defined in grpc::StatusCode.
144+
int32 error_code = 1;
145+
string error_message = 2;
146+
}
147+

0 commit comments

Comments
 (0)