Skip to content

Commit 27addec

Browse files
authored
Update to protocompile v0.6 and grpc-go v1.57.0 to address compatibility issues (#567)
1 parent 00716cd commit 27addec

File tree

14 files changed

+185
-1563
lines changed

14 files changed

+185
-1563
lines changed

desc/protoparse/ast.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func convertASTMessageElement(f *ast.FileNode, el ast.MessageElement) ast2.Messa
148148
return convertASTField(f, el)
149149
case *ast.MapFieldNode:
150150
return convertASTMapField(f, el)
151-
case *ast.OneOfNode:
151+
case *ast.OneofNode:
152152
return convertASTOneOf(f, el)
153153
case *ast.GroupNode:
154154
return convertASTGroup(f, el)
@@ -241,7 +241,7 @@ func convertASTGroup(f *ast.FileNode, g *ast.GroupNode) *ast2.GroupNode {
241241
)
242242
}
243243

244-
func convertASTOneOf(f *ast.FileNode, oo *ast.OneOfNode) *ast2.OneOfNode {
244+
func convertASTOneOf(f *ast.FileNode, oo *ast.OneofNode) *ast2.OneOfNode {
245245
decls := make([]ast2.OneOfElement, len(oo.Decls))
246246
for i := range oo.Decls {
247247
decls[i] = convertASTOneOfElement(f, oo.Decls[i])
@@ -255,7 +255,7 @@ func convertASTOneOf(f *ast.FileNode, oo *ast.OneOfNode) *ast2.OneOfNode {
255255
)
256256
}
257257

258-
func convertASTOneOfElement(f *ast.FileNode, el ast.OneOfElement) ast2.OneOfElement {
258+
func convertASTOneOfElement(f *ast.FileNode, el ast.OneofElement) ast2.OneOfElement {
259259
switch el := el.(type) {
260260
case *ast.OptionNode:
261261
return convertASTOption(f, el)

desc/protoparse/linker_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func TestLinkerValidation(t *testing.T) {
285285
map[string]string{
286286
"foo.proto": "package fu.baz; message foobar{ optional string a = 1 [default = { a: \"abc\" }]; }",
287287
},
288-
"foo.proto:1:66: field fu.baz.foobar.a: default value cannot be a message",
288+
"foo.proto:1:66: field fu.baz.foobar.a: option default: default value cannot be a message",
289289
},
290290
{
291291
map[string]string{

desc/protoparse/parser.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (p Parser) ParseFilesButDoNotLink(filenames ...string) ([]*descriptorpb.Fil
253253
protos := make([]*descriptorpb.FileDescriptorProto, len(results))
254254
for i, res := range results {
255255
protos[i] = res.FileDescriptorProto()
256-
var optsIndex options.Index
256+
var optsIndex sourceinfo.OptionIndex
257257
if p.InterpretOptionsInUnlinkedFiles {
258258
var err error
259259
optsIndex, err = options.InterpretUnlinkedOptions(res)
@@ -263,7 +263,7 @@ func (p Parser) ParseFilesButDoNotLink(filenames ...string) ([]*descriptorpb.Fil
263263
removeDynamicExtensionsFromProto(protos[i])
264264
}
265265
if p.IncludeSourceCodeInfo {
266-
protos[i].SourceCodeInfo = sourceinfo.GenerateSourceInfo(res.AST(), optsIndex)
266+
protos[i].SourceCodeInfo = sourceinfo.GenerateSourceInfo(res.AST(), optsIndex, sourceinfo.WithExtraComments())
267267
}
268268
}
269269

desc/protoparse/reporting_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestErrorReporting(t *testing.T) {
5757
`,
5858
},
5959
expectedErrs: []string{
60-
"test.proto:5:41: syntax error: unexpected \"enum\", expecting ';'",
60+
"test.proto:5:41: syntax error: unexpected \"enum\", expecting ';' or '.'",
6161
"test.proto:5:69: syntax error: unexpected ';', expecting '='",
6262
"test.proto:7:53: syntax error: unexpected '='",
6363
},

go.mod

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ module github.com/jhump/protoreflect
33
go 1.18
44

55
require (
6-
github.com/bufbuild/protocompile v0.4.0
7-
github.com/golang/protobuf v1.5.2
6+
github.com/bufbuild/protocompile v0.6.0
7+
github.com/golang/protobuf v1.5.3
88
github.com/jhump/gopoet v0.1.0
99
github.com/jhump/goprotoc v0.5.0
10-
google.golang.org/grpc v1.53.0
11-
google.golang.org/protobuf v1.28.2-0.20230222093303-bc1253ad3743
10+
google.golang.org/grpc v1.57.0
11+
google.golang.org/protobuf v1.31.0
1212
)
1313

1414
require (
15-
golang.org/x/net v0.7.0 // indirect
16-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
17-
golang.org/x/sys v0.5.0 // indirect
18-
golang.org/x/text v0.7.0 // indirect
19-
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
15+
golang.org/x/net v0.9.0 // indirect
16+
golang.org/x/sync v0.3.0 // indirect
17+
golang.org/x/sys v0.7.0 // indirect
18+
golang.org/x/text v0.9.0 // indirect
19+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
2020
)

go.sum

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3-
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
4-
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
3+
github.com/bufbuild/protocompile v0.6.0 h1:Uu7WiSQ6Yj9DbkdnOe7U4mNKp58y9WDMKDn28/ZlunY=
4+
github.com/bufbuild/protocompile v0.6.0/go.mod h1:YNP35qEYoYGme7QMtz5SBCoN4kL4g12jTtjuzRNdjpE=
55
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
66
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
77
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
@@ -23,8 +23,8 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
2323
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
2424
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
2525
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
26-
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
27-
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
26+
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
27+
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
2828
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
2929
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
3030
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
@@ -47,7 +47,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
4747
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
4848
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4949
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
50-
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
50+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
5151
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
5252
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
5353
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -60,25 +60,25 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
6060
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
6161
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
6262
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
63-
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
64-
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
63+
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
64+
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
6565
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
6666
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6767
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6868
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6969
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
70-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
71-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
70+
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
71+
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
7272
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
7373
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
7474
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
7575
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
76-
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
77-
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
76+
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
77+
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7878
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
7979
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
80-
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
81-
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
80+
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
81+
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
8282
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
8383
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
8484
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
@@ -90,15 +90,15 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
9090
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
9191
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
9292
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
93-
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w=
94-
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
93+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 h1:0nDDozoAU19Qb2HwhXadU8OcsiO/09cnTqhUtq2MEOM=
94+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
9595
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
9696
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
9797
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
9898
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
9999
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
100-
google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc=
101-
google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw=
100+
google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
101+
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
102102
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
103103
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
104104
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -110,8 +110,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
110110
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
111111
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
112112
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
113-
google.golang.org/protobuf v1.28.2-0.20230222093303-bc1253ad3743 h1:yqElulDvOF26oZ2O+2/aoX7mQ8DY/6+p39neytrycd8=
114-
google.golang.org/protobuf v1.28.2-0.20230222093303-bc1253ad3743/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
113+
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
114+
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
115115
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
116116
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
117117
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

grpcreflect/adapt.go

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package grpcreflect
2+
3+
import (
4+
refv1 "google.golang.org/grpc/reflection/grpc_reflection_v1"
5+
refv1alpha "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
6+
)
7+
8+
func toV1Request(v1alpha *refv1alpha.ServerReflectionRequest) *refv1.ServerReflectionRequest {
9+
var v1 refv1.ServerReflectionRequest
10+
v1.Host = v1alpha.Host
11+
switch mr := v1alpha.MessageRequest.(type) {
12+
case *refv1alpha.ServerReflectionRequest_FileByFilename:
13+
v1.MessageRequest = &refv1.ServerReflectionRequest_FileByFilename{
14+
FileByFilename: mr.FileByFilename,
15+
}
16+
case *refv1alpha.ServerReflectionRequest_FileContainingSymbol:
17+
v1.MessageRequest = &refv1.ServerReflectionRequest_FileContainingSymbol{
18+
FileContainingSymbol: mr.FileContainingSymbol,
19+
}
20+
case *refv1alpha.ServerReflectionRequest_FileContainingExtension:
21+
if mr.FileContainingExtension != nil {
22+
v1.MessageRequest = &refv1.ServerReflectionRequest_FileContainingExtension{
23+
FileContainingExtension: &refv1.ExtensionRequest{
24+
ContainingType: mr.FileContainingExtension.GetContainingType(),
25+
ExtensionNumber: mr.FileContainingExtension.GetExtensionNumber(),
26+
},
27+
}
28+
}
29+
case *refv1alpha.ServerReflectionRequest_AllExtensionNumbersOfType:
30+
v1.MessageRequest = &refv1.ServerReflectionRequest_AllExtensionNumbersOfType{
31+
AllExtensionNumbersOfType: mr.AllExtensionNumbersOfType,
32+
}
33+
case *refv1alpha.ServerReflectionRequest_ListServices:
34+
v1.MessageRequest = &refv1.ServerReflectionRequest_ListServices{
35+
ListServices: mr.ListServices,
36+
}
37+
default:
38+
// no value set
39+
}
40+
return &v1
41+
}
42+
43+
func toV1AlphaRequest(v1 *refv1.ServerReflectionRequest) *refv1alpha.ServerReflectionRequest {
44+
var v1alpha refv1alpha.ServerReflectionRequest
45+
v1alpha.Host = v1.Host
46+
switch mr := v1.MessageRequest.(type) {
47+
case *refv1.ServerReflectionRequest_FileByFilename:
48+
if mr != nil {
49+
v1alpha.MessageRequest = &refv1alpha.ServerReflectionRequest_FileByFilename{
50+
FileByFilename: mr.FileByFilename,
51+
}
52+
}
53+
case *refv1.ServerReflectionRequest_FileContainingSymbol:
54+
if mr != nil {
55+
v1alpha.MessageRequest = &refv1alpha.ServerReflectionRequest_FileContainingSymbol{
56+
FileContainingSymbol: mr.FileContainingSymbol,
57+
}
58+
}
59+
case *refv1.ServerReflectionRequest_FileContainingExtension:
60+
if mr != nil {
61+
v1alpha.MessageRequest = &refv1alpha.ServerReflectionRequest_FileContainingExtension{
62+
FileContainingExtension: &refv1alpha.ExtensionRequest{
63+
ContainingType: mr.FileContainingExtension.GetContainingType(),
64+
ExtensionNumber: mr.FileContainingExtension.GetExtensionNumber(),
65+
},
66+
}
67+
}
68+
case *refv1.ServerReflectionRequest_AllExtensionNumbersOfType:
69+
if mr != nil {
70+
v1alpha.MessageRequest = &refv1alpha.ServerReflectionRequest_AllExtensionNumbersOfType{
71+
AllExtensionNumbersOfType: mr.AllExtensionNumbersOfType,
72+
}
73+
}
74+
case *refv1.ServerReflectionRequest_ListServices:
75+
if mr != nil {
76+
v1alpha.MessageRequest = &refv1alpha.ServerReflectionRequest_ListServices{
77+
ListServices: mr.ListServices,
78+
}
79+
}
80+
default:
81+
// no value set
82+
}
83+
return &v1alpha
84+
}
85+
86+
func toV1AlphaResponse(v1 *refv1.ServerReflectionResponse) *refv1alpha.ServerReflectionResponse {
87+
var v1alpha refv1alpha.ServerReflectionResponse
88+
v1alpha.ValidHost = v1.ValidHost
89+
if v1.OriginalRequest != nil {
90+
v1alpha.OriginalRequest = toV1AlphaRequest(v1.OriginalRequest)
91+
}
92+
switch mr := v1.MessageResponse.(type) {
93+
case *refv1.ServerReflectionResponse_FileDescriptorResponse:
94+
if mr != nil {
95+
v1alpha.MessageResponse = &refv1alpha.ServerReflectionResponse_FileDescriptorResponse{
96+
FileDescriptorResponse: &refv1alpha.FileDescriptorResponse{
97+
FileDescriptorProto: mr.FileDescriptorResponse.GetFileDescriptorProto(),
98+
},
99+
}
100+
}
101+
case *refv1.ServerReflectionResponse_AllExtensionNumbersResponse:
102+
if mr != nil {
103+
v1alpha.MessageResponse = &refv1alpha.ServerReflectionResponse_AllExtensionNumbersResponse{
104+
AllExtensionNumbersResponse: &refv1alpha.ExtensionNumberResponse{
105+
BaseTypeName: mr.AllExtensionNumbersResponse.GetBaseTypeName(),
106+
ExtensionNumber: mr.AllExtensionNumbersResponse.GetExtensionNumber(),
107+
},
108+
}
109+
}
110+
case *refv1.ServerReflectionResponse_ListServicesResponse:
111+
if mr != nil {
112+
svcs := make([]*refv1alpha.ServiceResponse, len(mr.ListServicesResponse.GetService()))
113+
for i, svc := range mr.ListServicesResponse.GetService() {
114+
svcs[i] = &refv1alpha.ServiceResponse{
115+
Name: svc.GetName(),
116+
}
117+
}
118+
v1alpha.MessageResponse = &refv1alpha.ServerReflectionResponse_ListServicesResponse{
119+
ListServicesResponse: &refv1alpha.ListServiceResponse{
120+
Service: svcs,
121+
},
122+
}
123+
}
124+
case *refv1.ServerReflectionResponse_ErrorResponse:
125+
if mr != nil {
126+
v1alpha.MessageResponse = &refv1alpha.ServerReflectionResponse_ErrorResponse{
127+
ErrorResponse: &refv1alpha.ErrorResponse{
128+
ErrorCode: mr.ErrorResponse.GetErrorCode(),
129+
ErrorMessage: mr.ErrorResponse.GetErrorMessage(),
130+
},
131+
}
132+
}
133+
default:
134+
// no value set
135+
}
136+
return &v1alpha
137+
}

grpcreflect/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
"github.com/golang/protobuf/proto"
1414
"google.golang.org/grpc"
1515
"google.golang.org/grpc/codes"
16+
refv1 "google.golang.org/grpc/reflection/grpc_reflection_v1"
1617
refv1alpha "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
1718
"google.golang.org/grpc/status"
1819
"google.golang.org/protobuf/types/descriptorpb"
1920

2021
"github.com/jhump/protoreflect/desc"
21-
refv1 "github.com/jhump/protoreflect/grpcreflect/internal/grpc_reflection_v1"
2222
"github.com/jhump/protoreflect/internal"
2323
)
2424

@@ -758,7 +758,7 @@ type adaptStreamFromV1 struct {
758758
}
759759

760760
func (a adaptStreamFromV1) Send(request *refv1alpha.ServerReflectionRequest) error {
761-
v1req := refv1.ToV1Request(request)
761+
v1req := toV1Request(request)
762762
return a.ServerReflection_ServerReflectionInfoClient.Send(v1req)
763763
}
764764

@@ -767,5 +767,5 @@ func (a adaptStreamFromV1) Recv() (*refv1alpha.ServerReflectionResponse, error)
767767
if err != nil {
768768
return nil, err
769769
}
770-
return refv1.ToV1AlphaResponse(v1resp), nil
770+
return toV1AlphaResponse(v1resp), nil
771771
}

0 commit comments

Comments
 (0)