neoeinstein / protoc-gen-prost

Apache License 2.0
150 stars 40 forks source link

add max message size configuration to generated service #67

Closed Lev1ty closed 1 year ago

Lev1ty commented 1 year ago

max request message size is 4MB by default in tonic's 0.9.0 release https://github.com/hyperium/tonic/pull/1337 currently, this size is not configurable from protoc-gen-tonic since it depends on tonic-build 0.8.x a version bump should catch the codegen up

neoeinstein commented 1 year ago

I think I can do this, with a caveat that it will be a breaking change because the generated code will now rely on a tonic 0.9.0 feature. That's not a problem, just something that I'll need to call out when cutting a new release with this update included.

In the build-with-buf example, the generated code has the following diff:

diff src/gen/example.tonic.rs src/gen-new/example.tonic.rs
16c16
<             D: std::convert::TryInto<tonic::transport::Endpoint>,
---
>             D: TryInto<tonic::transport::Endpoint>,
71a72
>         /// Limits the maximum size of a decoded message.
72a74,88
>         /// Default: `4MB`
>         #[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.
>         ///
>         /// Default: `usize::MAX`
>         #[must_use]
>         pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
>             self.inner = self.inner.max_encoding_message_size(limit);
>             self
>         }
>         ///
76c92,95
<         ) -> Result<tonic::Response<super::ExampleResponse>, tonic::Status> {
---
>         ) -> std::result::Result<
>             tonic::Response<super::ExampleResponse>,
>             tonic::Status,
>         > {
90c109,112
<             self.inner.unary(request.into_request(), path, codec).await
---
>             let mut req = request.into_request();
>             req.extensions_mut()
>                 .insert(GrpcMethod::new("example.Example", "DoTheThing"));
>             self.inner.unary(req, path, codec).await
105c127
<         ) -> Result<tonic::Response<super::ExampleResponse>, tonic::Status>;
---
>         ) -> std::result::Result<tonic::Response<super::ExampleResponse>, tonic::Status>;
112a135,136
>         max_decoding_message_size: Option<usize>,
>         max_encoding_message_size: Option<usize>,
124a149,150
>                 max_decoding_message_size: None,
>                 max_encoding_message_size: None,
147a174,189
>         /// Limits the maximum size of a decoded message.
>         ///
>         /// Default: `4MB`
>         #[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.
>         ///
>         /// Default: `usize::MAX`
>         #[must_use]
>         pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
>             self.max_encoding_message_size = Some(limit);
>             self
>         }
161c203
<         ) -> Poll<Result<(), Self::Error>> {
---
>         ) -> Poll<std::result::Result<(), Self::Error>> {
181c223
<                             let inner = self.0.clone();
---
>                             let inner = Arc::clone(&self.0);
189a232,233
>                     let max_decoding_message_size = self.max_decoding_message_size;
>                     let max_encoding_message_size = self.max_encoding_message_size;
198a243,246
>                             )
>                             .apply_max_message_size_config(
>                                 max_decoding_message_size,
>                                 max_encoding_message_size,
226a275,276
>                 max_decoding_message_size: self.max_decoding_message_size,
>                 max_encoding_message_size: self.max_encoding_message_size,
232c282
<             Self(self.0.clone())
---
>             Self(Arc::clone(&self.0))