1
- use crate :: proto:: server_reflection_request:: MessageRequest ;
2
- use crate :: proto:: server_reflection_response:: MessageResponse ;
3
- use crate :: proto:: server_reflection_server:: { ServerReflection , ServerReflectionServer } ;
4
- use crate :: proto:: {
5
- FileDescriptorResponse , ListServiceResponse , ServerReflectionRequest , ServerReflectionResponse ,
6
- ServiceResponse ,
7
- } ;
1
+ use std:: collections:: HashMap ;
2
+ use std:: fmt:: { Display , Formatter } ;
3
+ use std:: pin:: Pin ;
4
+ use std:: sync:: Arc ;
5
+
8
6
use prost:: { DecodeError , Message } ;
9
7
use prost_types:: {
10
8
DescriptorProto , EnumDescriptorProto , FieldDescriptorProto , FileDescriptorProto ,
11
9
FileDescriptorSet ,
12
10
} ;
13
- use std:: collections:: HashMap ;
14
- use std:: fmt:: { Display , Formatter } ;
15
- use std:: sync:: Arc ;
16
- use tokio:: stream:: StreamExt ;
17
11
use tokio:: sync:: mpsc;
12
+ use tokio_stream:: wrappers:: ReceiverStream ;
13
+ use tokio_stream:: { Stream , StreamExt } ;
18
14
use tonic:: { Request , Response , Status , Streaming } ;
19
15
16
+ use crate :: proto:: server_reflection_request:: MessageRequest ;
17
+ use crate :: proto:: server_reflection_response:: MessageResponse ;
18
+ use crate :: proto:: server_reflection_server:: { ServerReflection , ServerReflectionServer } ;
19
+ use crate :: proto:: {
20
+ FileDescriptorResponse , ListServiceResponse , ServerReflectionRequest , ServerReflectionResponse ,
21
+ ServiceResponse ,
22
+ } ;
23
+
20
24
/// Represents an error in the construction of a gRPC Reflection Service.
21
25
#[ derive( Debug ) ]
22
26
pub enum Error {
@@ -78,6 +82,8 @@ impl<'b> Builder<'b> {
78
82
79
83
/// Registers a byte slice containing an encoded `prost_types::FileDescriptorSet` with
80
84
/// the gRPC Reflection Service builder.
85
+ ///
86
+ /// This can be called multiple times to append new descriptors to the serivce.
81
87
pub fn register_encoded_file_descriptor_set (
82
88
mut self ,
83
89
encoded_file_descriptor_set : & ' b [ u8 ] ,
@@ -97,7 +103,8 @@ impl<'b> Builder<'b> {
97
103
/// Build a gRPC Reflection Service to be served via Tonic.
98
104
pub fn build ( mut self ) -> Result < ServerReflectionServer < impl ServerReflection > , Error > {
99
105
if self . include_reflection_service {
100
- self = self . register_encoded_file_descriptor_set ( crate :: proto:: FILE_DESCRIPTOR_SET ) ;
106
+ self =
107
+ self . register_encoded_file_descriptor_set ( crate :: proto:: REFLECTION_DESCRIPTOR_SET ) ;
101
108
}
102
109
103
110
for encoded in & self . encoded_file_descriptor_sets {
@@ -304,14 +311,16 @@ struct ReflectionService {
304
311
305
312
#[ tonic:: async_trait]
306
313
impl ServerReflection for ReflectionService {
307
- type ServerReflectionInfoStream = mpsc:: Receiver < Result < ServerReflectionResponse , Status > > ;
314
+ type ServerReflectionInfoStream = Pin <
315
+ Box < dyn Stream < Item = Result < ServerReflectionResponse , Status > > + Send + Sync + ' static > ,
316
+ > ;
308
317
309
318
async fn server_reflection_info (
310
319
& self ,
311
320
req : Request < Streaming < ServerReflectionRequest > > ,
312
321
) -> Result < Response < Self :: ServerReflectionInfoStream > , Status > {
313
322
let mut req_rx = req. into_inner ( ) ;
314
- let ( mut resp_tx, resp_rx) = mpsc:: channel :: < Result < ServerReflectionResponse , Status > > ( 1 ) ;
323
+ let ( resp_tx, resp_rx) = mpsc:: channel :: < Result < ServerReflectionResponse , Status > > ( 1 ) ;
315
324
316
325
let state = self . state . clone ( ) ;
317
326
@@ -356,6 +365,6 @@ impl ServerReflection for ReflectionService {
356
365
}
357
366
} ) ;
358
367
359
- Ok ( Response :: new ( resp_rx) )
368
+ Ok ( Response :: new ( Box :: pin ( ReceiverStream :: new ( resp_rx) ) ) )
360
369
}
361
370
}
0 commit comments