Skip to content

Commit 7f2835b

Browse files
committed
fix: pair length delimiter size
1 parent 4e328bc commit 7f2835b

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

datadog-profiling-protobuf/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ impl<V: Value> Pair<V> {
7474

7575
pub fn proto_len(&self) -> u64 {
7676
let tag = Tag::new(self.field, V::WIRE_TYPE).proto_len();
77+
let value = self.value.proto_len();
7778
let len_prefix = if V::WIRE_TYPE == WireType::LengthDelimited {
78-
self.value.proto_len()
79+
Varint(value).proto_len()
7980
} else {
8081
0
8182
};
82-
let value = self.value.proto_len();
8383
tag + len_prefix + value
8484
}
8585

@@ -228,11 +228,11 @@ impl Tag {
228228
}
229229
}
230230

231-
pub struct PackedVarint<'a, T: Into<Varint>> {
231+
pub struct Packed<'a, T: Into<Varint>> {
232232
values: &'a [T],
233233
}
234234

235-
impl<'a, T: Into<Varint>> PackedVarint<'a, T>
235+
impl<'a, T: Into<Varint>> Packed<'a, T>
236236
where
237237
Varint: From<&'a T>,
238238
{
@@ -241,7 +241,7 @@ where
241241
}
242242
}
243243

244-
impl<'a, T: Into<Varint>> Value for PackedVarint<'a, T>
244+
impl<'a, T: Into<Varint>> Value for Packed<'a, T>
245245
where
246246
Varint: From<&'a T>,
247247
{

datadog-profiling-protobuf/src/sample.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2025-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::{prost_impls, Label, PackedVarint, Value, WireType};
4+
use crate::{prost_impls, Label, Packed, Value, WireType};
55
use std::io::{self, Write};
66

77
#[derive(Copy, Clone, Debug)]
@@ -15,8 +15,8 @@ impl Value for Sample<'_> {
1515
const WIRE_TYPE: WireType = WireType::LengthDelimited;
1616

1717
fn proto_len(&self) -> u64 {
18-
let locations = PackedVarint::new(self.location_ids).field(1).proto_len();
19-
let values = PackedVarint::new(self.values).field(2).proto_len();
18+
let locations = Packed::new(self.location_ids).field(1).proto_len();
19+
let values = Packed::new(self.values).field(2).proto_len();
2020
let labels = self
2121
.labels
2222
.iter()
@@ -26,10 +26,8 @@ impl Value for Sample<'_> {
2626
}
2727

2828
fn encode<W: Write>(&self, writer: &mut W) -> io::Result<()> {
29-
PackedVarint::new(self.location_ids)
30-
.field(1)
31-
.encode(writer)?;
32-
PackedVarint::new(self.values).field(2).encode(writer)?;
29+
Packed::new(self.location_ids).field(1).encode(writer)?;
30+
Packed::new(self.values).field(2).encode(writer)?;
3331

3432
for label in self.labels {
3533
label.field(3).encode(writer)?;

datadog-profiling-protobuf/src/value_type.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ mod tests {
5757
assert_eq!(i64::from(value_type.r#type), prost_value_type.r#type);
5858
assert_eq!(i64::from(value_type.unit), prost_value_type.unit);
5959

60-
let value = value_type.unit.to_u64();
61-
let value1 = value_type.r#type.to_u64();
62-
let len = (Varint(value1).field(1).proto_len_small()
63-
+ Varint(value).field(2).proto_len_small()) as usize;
64-
let mut buffer = Vec::with_capacity(len);
60+
let mut buffer = Vec::with_capacity(value_type.proto_len() as usize);
61+
prost_value_type.encode(&mut buffer).unwrap();
6562
value_type.encode(&mut buffer).unwrap();
6663
let roundtrip = prost_impls::ValueType::decode(buffer.as_slice()).unwrap();
6764
assert_eq!(prost_value_type, roundtrip);

0 commit comments

Comments
 (0)