Skip to content

Commit 7b04b17

Browse files
authored
axum-extra: Pre-allocate right sized buffer when encoding protobuf response (#3325)
1 parent 58f63bb commit 7b04b17

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

axum-extra/src/protobuf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ where
128128
T: Message + Default,
129129
{
130130
fn into_response(self) -> Response {
131-
let mut buf = BytesMut::with_capacity(128);
131+
let mut buf = BytesMut::with_capacity(self.0.encoded_len());
132132
match &self.0.encode(&mut buf) {
133133
Ok(()) => buf.into_response(),
134134
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),

0 commit comments

Comments
 (0)