Skip to content

Commit

Permalink
refactor a tiny bit
Browse files Browse the repository at this point in the history
  • Loading branch information
morrisonlevi committed Feb 9, 2024
1 parent cde6b04 commit dc20736
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions profiling/src/serializer/compressed_streaming_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ pub struct CompressedProtobufSerializer {
zipper: FrameEncoder<Vec<u8>>,
}

// I've opened a PR for this upstream:
// I've opened a PR for a generic version of this upstream:
// https://github.com/tokio-rs/prost/pull/978
fn encode_str(tag: u32, value: impl AsRef<str>, buf: &mut impl BufMut) {
let str = value.as_ref();
fn encode_str(tag: u32, value: &str, buf: &mut Vec<u8>) {
encode_key(tag, WireType::LengthDelimited, buf);
encode_varint(str.len() as u64, buf);
buf.put_slice(str.as_bytes());
encode_varint(value.len() as u64, buf);
buf.put_slice(value.as_bytes());
}

impl CompressedProtobufSerializer {
Expand All @@ -42,7 +41,7 @@ impl CompressedProtobufSerializer {
.context("failed to encode Protobuf str; insufficient buffer capacity"));
}

encode_str(tag, item, &mut self.buffer);
encode_str(tag, str, &mut self.buffer);
self.zipper.write_all(&self.buffer)?;
self.buffer.clear();
Ok(())
Expand Down

0 comments on commit dc20736

Please sign in to comment.