1 /*
2 *
3 * Copyright 2023 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18 19 package reflection
20 21 import (
22 "google.golang.org/grpc/reflection/internal"
23 24 v1reflectiongrpc "google.golang.org/grpc/reflection/grpc_reflection_v1"
25 v1reflectionpb "google.golang.org/grpc/reflection/grpc_reflection_v1"
26 v1alphareflectiongrpc "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
27 )
28 29 // asV1Alpha returns an implementation of the v1alpha version of the reflection
30 // interface that delegates all calls to the given v1 version.
31 func asV1Alpha(svr v1reflectiongrpc.ServerReflectionServer) v1alphareflectiongrpc.ServerReflectionServer {
32 return v1AlphaServerImpl{svr: svr}
33 }
34 35 type v1AlphaServerImpl struct {
36 svr v1reflectiongrpc.ServerReflectionServer
37 }
38 39 func (s v1AlphaServerImpl) ServerReflectionInfo(stream v1alphareflectiongrpc.ServerReflection_ServerReflectionInfoServer) error {
40 return s.svr.ServerReflectionInfo(v1AlphaServerStreamAdapter{stream})
41 }
42 43 type v1AlphaServerStreamAdapter struct {
44 v1alphareflectiongrpc.ServerReflection_ServerReflectionInfoServer
45 }
46 47 func (s v1AlphaServerStreamAdapter) Send(response *v1reflectionpb.ServerReflectionResponse) error {
48 return s.ServerReflection_ServerReflectionInfoServer.Send(internal.V1ToV1AlphaResponse(response))
49 }
50 51 func (s v1AlphaServerStreamAdapter) Recv() (*v1reflectionpb.ServerReflectionRequest, error) {
52 resp, err := s.ServerReflection_ServerReflectionInfoServer.Recv()
53 if err != nil {
54 return nil, err
55 }
56 return internal.V1AlphaToV1Request(resp), nil
57 }
58