File tree Expand file tree Collapse file tree 2 files changed +7
-13
lines changed Expand file tree Collapse file tree 2 files changed +7
-13
lines changed Original file line number Diff line number Diff line change @@ -95,19 +95,13 @@ fn create_error_response(status: Status) -> GrpcResponse {
9595 TonicResponse :: new ( Box :: pin ( stream) )
9696}
9797
98- fn convert_request ( req : GrpcRequest ) -> TonicRequest < Pin < Box < dyn Stream < Item = Bytes > + Send > > > {
98+ fn convert_request ( req : GrpcRequest ) -> TonicRequest < BoxStream < Bytes > > {
9999 let ( metadata, extensions, stream) = req. into_parts ( ) ;
100100
101- let bytes_stream = Box :: pin ( stream. filter_map ( |msg| {
101+ let bytes_stream = Box :: pin ( stream. map ( |msg| {
102102 let mut buf = BytesMut :: with_capacity ( msg. encoded_message_size_hint ( ) . unwrap_or ( 0 ) ) ;
103- if let Ok ( ( ) ) = msg. encode ( & mut buf) {
104- Some ( buf. freeze ( ) )
105- } else {
106- // TODO: Handle encoding failures.
107- // If it fails, log the error and return None to filter it out.
108- eprintln ! ( "A message could not be downcast to Bytes and was skipped." ) ;
109- None
110- }
103+ msg. encode ( & mut buf) . map_err ( Status :: internal) ?;
104+ Ok ( buf. freeze ( ) )
111105 } ) ) ;
112106
113107 TonicRequest :: from_parts ( metadata, extensions, bytes_stream as _ )
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ use tonic::{
1111pub ( crate ) struct BytesCodec { }
1212
1313impl Codec for BytesCodec {
14- type Encode = Bytes ;
14+ type Encode = Result < Bytes , Status > ;
1515 type Decode = Bytes ;
1616 type Encoder = BytesEncoder ;
1717 type Decoder = BytesDecoder ;
@@ -28,11 +28,11 @@ impl Codec for BytesCodec {
2828pub struct BytesEncoder { }
2929
3030impl Encoder for BytesEncoder {
31- type Item = Bytes ;
31+ type Item = Result < Bytes , Status > ;
3232 type Error = Status ;
3333
3434 fn encode ( & mut self , item : Self :: Item , dst : & mut EncodeBuf < ' _ > ) -> Result < ( ) , Self :: Error > {
35- dst. put_slice ( & item) ;
35+ dst. put_slice ( & item? ) ;
3636 Ok ( ( ) )
3737 }
3838}
You can’t perform that action at this time.
0 commit comments