Skip to content

Commit

Permalink
fix: doctest + generated rs
Browse files Browse the repository at this point in the history
  • Loading branch information
aoudiamoncef committed Feb 16, 2023
1 parent 94c4141 commit b5adfd5
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 15 deletions.
42 changes: 42 additions & 0 deletions tonic-health/src/generated/grpc.health.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ pub mod health_client {
self.inner = self.inner.accept_compressed(encoding);
self
}
/// Limits the maximum size of a decoded message.
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_decoding_message_size(limit);
self
}
/// Limits the maximum size of an encoded message.
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_encoding_message_size(limit);
self
}
/// If the requested service is unknown, the call will fail with status
/// NOT_FOUND.
pub async fn check(
Expand Down Expand Up @@ -224,6 +236,8 @@ pub mod health_server {
inner: _Inner<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
struct _Inner<T>(Arc<T>);
impl<T: Health> HealthServer<T> {
Expand All @@ -236,6 +250,8 @@ pub mod health_server {
inner,
accept_compression_encodings: Default::default(),
send_compression_encodings: Default::default(),
max_decoding_message_size: None,
max_encoding_message_size: None,
}
}
pub fn with_interceptor<F>(
Expand All @@ -259,6 +275,18 @@ pub mod health_server {
self.send_compression_encodings.enable(encoding);
self
}
/// Limits the maximum size of a decoded message.
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.max_decoding_message_size = Some(limit);
self
}
/// Limits the maximum size of an encoded message.
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.max_encoding_message_size = Some(limit);
self
}
}
impl<T, B> tonic::codegen::Service<http::Request<B>> for HealthServer<T>
where
Expand Down Expand Up @@ -301,6 +329,8 @@ pub mod health_server {
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
Expand All @@ -310,6 +340,10 @@ pub mod health_server {
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
Expand Down Expand Up @@ -340,6 +374,8 @@ pub mod health_server {
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
Expand All @@ -349,6 +385,10 @@ pub mod health_server {
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.server_streaming(method, req).await;
Ok(res)
Expand Down Expand Up @@ -377,6 +417,8 @@ pub mod health_server {
inner,
accept_compression_encodings: self.accept_compression_encodings,
send_compression_encodings: self.send_compression_encodings,
max_decoding_message_size: self.max_decoding_message_size,
max_encoding_message_size: self.max_encoding_message_size,
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions tonic-reflection/src/generated/grpc.reflection.v1alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ pub mod server_reflection_client {
self.inner = self.inner.accept_compressed(encoding);
self
}
/// Limits the maximum size of a decoded message.
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_decoding_message_size(limit);
self
}
/// Limits the maximum size of an encoded message.
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_encoding_message_size(limit);
self
}
/// The reflection service is structured as a bidirectional stream, ensuring
/// all related requests go to a single server.
pub async fn server_reflection_info(
Expand Down Expand Up @@ -270,6 +282,8 @@ pub mod server_reflection_server {
inner: _Inner<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
struct _Inner<T>(Arc<T>);
impl<T: ServerReflection> ServerReflectionServer<T> {
Expand All @@ -282,6 +296,8 @@ pub mod server_reflection_server {
inner,
accept_compression_encodings: Default::default(),
send_compression_encodings: Default::default(),
max_decoding_message_size: None,
max_encoding_message_size: None,
}
}
pub fn with_interceptor<F>(
Expand All @@ -305,6 +321,18 @@ pub mod server_reflection_server {
self.send_compression_encodings.enable(encoding);
self
}
/// Limits the maximum size of a decoded message.
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.max_decoding_message_size = Some(limit);
self
}
/// Limits the maximum size of an encoded message.
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.max_encoding_message_size = Some(limit);
self
}
}
impl<T, B> tonic::codegen::Service<http::Request<B>> for ServerReflectionServer<T>
where
Expand Down Expand Up @@ -352,6 +380,8 @@ pub mod server_reflection_server {
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
Expand All @@ -361,6 +391,10 @@ pub mod server_reflection_server {
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.streaming(method, req).await;
Ok(res)
Expand Down Expand Up @@ -389,6 +423,8 @@ pub mod server_reflection_server {
inner,
accept_compression_encodings: self.accept_compression_encodings,
send_compression_encodings: self.send_compression_encodings,
max_decoding_message_size: self.max_decoding_message_size,
max_encoding_message_size: self.max_encoding_message_size,
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions tonic/src/client/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ impl<T> Grpc<T> {

/// Limits the maximum size of a decoded message.
///
///
/// # Example
///
/// The most common way of using this is through a client generated by tonic-build:
Expand All @@ -151,8 +150,8 @@ impl<T> Grpc<T> {
/// .await
/// .unwrap();
///
/// // Set the limit to 2MB
/// let limit = 2 * 1024 * 1024
/// // Set the limit to 2MB, Defaults to 4MB.
/// let limit = 2 * 1024 * 1024;
/// let client = TestClient::new(channel).max_decoding_message_size(limit);
/// # };
/// ```
Expand All @@ -163,7 +162,6 @@ impl<T> Grpc<T> {

/// Limits the maximum size of an ecoded message.
///
///
/// # Example
///
/// The most common way of using this is through a client generated by tonic-build:
Expand All @@ -182,8 +180,8 @@ impl<T> Grpc<T> {
/// .await
/// .unwrap();
///
/// // Set the limit to 2MB
/// let limit = 2 * 1024 * 1024
/// // Set the limit to 2MB, Defaults to 4MB.
/// let limit = 2 * 1024 * 1024;
/// let client = TestClient::new(channel).max_encoding_message_size(limit);
/// # };
/// ```
Expand Down
13 changes: 4 additions & 9 deletions tonic/src/server/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ where

/// Limits the maximum size of a decoded message.
///
///
/// # Example
///
/// The most common way of using this is through a server generated by tonic-build:
Expand All @@ -142,11 +141,9 @@ where
/// // ...
/// }
///
/// // Set the limit to 2MB
/// let limit = 2 * 1024 * 1024
/// // Set the limit to 2MB, Defaults to 4MB.
/// let limit = 2 * 1024 * 1024;
/// let service = ExampleServer::new(Svc).max_decoding_message_size(limit);
/// # };
/// ```
/// ```
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.max_decoding_message_size = Some(limit);
Expand All @@ -155,7 +152,6 @@ where

/// Limits the maximum size of a encoded message.
///
///
/// # Example
///
/// The most common way of using this is through a server generated by tonic-build:
Expand All @@ -175,10 +171,9 @@ where
/// // ...
/// }
///
/// // Set the limit to 2MB
/// let limit = 2 * 1024 * 1024
/// // Set the limit to 2MB, Defaults to 4MB.
/// let limit = 2 * 1024 * 1024;
/// let service = ExampleServer::new(Svc).max_encoding_message_size(limit);
/// # };
/// ```
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.max_encoding_message_size = Some(limit);
Expand Down

0 comments on commit b5adfd5

Please sign in to comment.