Skip to content

Commit 52bc9ad

Browse files
committed
improve docs and remove dead code
1 parent 7f2835b commit 52bc9ad

File tree

1 file changed

+9
-10
lines changed
  • datadog-profiling-protobuf/src

1 file changed

+9
-10
lines changed

datadog-profiling-protobuf/src/lib.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub trait Value {
5151
where
5252
Self: Sized,
5353
{
54-
Pair::new(field, self)
54+
Pair { field, value: self }
5555
}
5656
}
5757

@@ -61,17 +61,17 @@ pub trait Value {
6161
#[derive(Copy, Clone)]
6262
pub struct Varint(pub u64);
6363

64+
/// A tag and value pair.
65+
///
66+
/// The wire type isn't stored; it's provided by the Value implementation,
67+
/// which allows us to specialize code.
6468
pub struct Pair<V: Value> {
6569
field: u32,
6670
value: V,
6771
}
6872

6973
impl<V: Value> Pair<V> {
70-
#[inline]
71-
pub const fn new(field: u32, value: V) -> Self {
72-
Pair { field, value }
73-
}
74-
74+
/// Calculate the size of pair, without using the zero-size optimization.
7575
pub fn proto_len(&self) -> u64 {
7676
let tag = Tag::new(self.field, V::WIRE_TYPE).proto_len();
7777
let value = self.value.proto_len();
@@ -83,6 +83,7 @@ impl<V: Value> Pair<V> {
8383
tag + len_prefix + value
8484
}
8585

86+
/// Calculate the size of pair, using the zero-size optimization.
8687
#[inline]
8788
pub fn proto_len_small(&self) -> u64 {
8889
if self.value.proto_len() != 0 {
@@ -92,6 +93,7 @@ impl<V: Value> Pair<V> {
9293
}
9394
}
9495

96+
/// Encodes into protobuf, without using the zero-size optimization.
9597
pub fn encode(&self, writer: &mut impl Write) -> io::Result<()> {
9698
Tag::new(self.field, V::WIRE_TYPE).encode(writer)?;
9799
if V::WIRE_TYPE == WireType::LengthDelimited {
@@ -101,6 +103,7 @@ impl<V: Value> Pair<V> {
101103
self.value.encode(writer)
102104
}
103105

106+
/// Encodes into protobuf, using the zero-size optimization.
104107
#[inline]
105108
pub fn encode_small(&self, writer: &mut impl Write) -> io::Result<()> {
106109
let len = self.value.proto_len();
@@ -116,10 +119,6 @@ impl<V: Value> Pair<V> {
116119
}
117120
}
118121

119-
pub trait TagEncodable {
120-
fn encode_with_tag<W: Write>(&self, w: &mut W, field: u32) -> io::Result<()>;
121-
}
122-
123122
/// The smallest possible protobuf field number.
124123
const MIN_FIELD: u32 = 1;
125124

0 commit comments

Comments
 (0)