Skip to content

Commit e37e1ab

Browse files
committed
tonic: fold encode_client() into EncodeBody::new_client()
1 parent 168ba46 commit e37e1ab

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

tonic/src/client/grpc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::codec::compression::{CompressionEncoding, EnabledCompressionEncodings};
2+
use crate::codec::EncodeBody;
23
use crate::metadata::GRPC_CONTENT_TYPE;
34
use crate::{
45
body::BoxBody,
56
client::GrpcService,
6-
codec::{encode_client, Codec, Decoder, Streaming},
7+
codec::{Codec, Decoder, Streaming},
78
request::SanitizeHeaders,
89
Code, Request, Response, Status,
910
};
@@ -295,7 +296,7 @@ impl<T> Grpc<T> {
295296
{
296297
let request = request
297298
.map(|s| {
298-
encode_client(
299+
EncodeBody::new_client(
299300
codec.encoder(),
300301
s.map(Ok),
301302
self.config.send_compression_encodings,

tonic/src/codec/encode.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,6 @@ use std::{
1313
};
1414
use tokio_stream::{adapters::Fuse, Stream, StreamExt};
1515

16-
/// Turns a stream of grpc messages into [EncodeBody] which is used by grpc clients for
17-
/// turning the messages into http frames for sending over the network.
18-
pub fn encode_client<T, U>(
19-
encoder: T,
20-
source: U,
21-
compression_encoding: Option<CompressionEncoding>,
22-
max_message_size: Option<usize>,
23-
) -> EncodeBody<T, U>
24-
where
25-
T: Encoder<Error = Status>,
26-
U: Stream,
27-
{
28-
let stream = EncodedBytes::new(
29-
encoder,
30-
source,
31-
compression_encoding,
32-
SingleMessageCompressionOverride::default(),
33-
max_message_size,
34-
);
35-
EncodeBody::new_client(stream)
36-
}
37-
3816
/// Combinator for efficient encoding of messages into reasonably sized buffers.
3917
/// EncodedBytes encodes ready messages from its delegate stream into a BytesMut,
4018
/// splitting off and yielding a buffer when either:
@@ -251,9 +229,22 @@ struct EncodeState {
251229
}
252230

253231
impl<T: Encoder, U: Stream> EncodeBody<T, U> {
254-
fn new_client(inner: EncodedBytes<T, U>) -> Self {
232+
/// Turns a stream of grpc messages into [EncodeBody] which is used by grpc clients for
233+
/// turning the messages into http frames for sending over the network.
234+
pub fn new_client(
235+
encoder: T,
236+
source: U,
237+
compression_encoding: Option<CompressionEncoding>,
238+
max_message_size: Option<usize>,
239+
) -> Self {
255240
Self {
256-
inner,
241+
inner: EncodedBytes::new(
242+
encoder,
243+
source,
244+
compression_encoding,
245+
SingleMessageCompressionOverride::default(),
246+
max_message_size,
247+
),
257248
state: EncodeState {
258249
error: None,
259250
role: Role::Client,

tonic/src/codec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::io;
1616
pub use self::buffer::{DecodeBuf, EncodeBuf};
1717
pub use self::compression::{CompressionEncoding, EnabledCompressionEncodings};
1818
pub use self::decode::Streaming;
19-
pub use self::encode::{encode_client, EncodeBody};
19+
pub use self::encode::EncodeBody;
2020
#[cfg(feature = "prost")]
2121
pub use self::prost::ProstCodec;
2222

0 commit comments

Comments
 (0)