Skip to content

Commit 9b8e8b3

Browse files
committed
refactor: simplify Tag
1 parent 348195f commit 9b8e8b3

File tree

1 file changed

+4
-12
lines changed
  • datadog-profiling-protobuf/src

1 file changed

+4
-12
lines changed

datadog-profiling-protobuf/src/lib.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ use std::io::{self, Write};
3232
/// A tag is a combination of a wire_type, stored in the least significant
3333
/// three bits, and the field number that is defined in the .proto file.
3434
#[derive(Copy, Clone)]
35-
pub struct Tag {
36-
field: u32,
37-
wire_type: WireType,
38-
}
35+
pub struct Tag(u32);
3936

4037
/// A value is stored differently depending on the wire_type.
4138
pub trait Value {
@@ -132,22 +129,17 @@ impl Tag {
132129
#[inline]
133130
pub const fn new(field: u32, wire_type: WireType) -> Self {
134131
debug_assert!(field >= MIN_FIELD && field <= MAX_FIELD);
135-
Self { field, wire_type }
132+
Self((field << 3) | wire_type as u32)
136133
}
137134

138135
#[inline]
139136
pub fn proto_len(self) -> u64 {
140-
self.into_varint().proto_len()
137+
Varint(self.0 as u64).proto_len()
141138
}
142139

143140
#[inline]
144141
pub fn encode<W: Write>(self, writer: &mut W) -> io::Result<()> {
145-
self.into_varint().encode(writer)
146-
}
147-
148-
#[inline]
149-
pub const fn into_varint(self) -> Varint {
150-
Varint(((self.field << 3) | self.wire_type as u32) as u64)
142+
Varint(self.0 as u64).encode(writer)
151143
}
152144
}
153145

0 commit comments

Comments
 (0)