|
6 | 6 | #![cfg_attr(not(test), deny(clippy::expect_used))]
|
7 | 7 | #![cfg_attr(not(test), deny(clippy::unimplemented))]
|
8 | 8 |
|
9 |
| -//! This crate implements Protobuf serializers for [`profiles`], including: |
| 9 | +//! This crate implements Protobuf serializers for [`profiles`], including |
| 10 | +//! serializers for: |
10 | 11 | //!
|
11 | 12 | //! - [Function]
|
12 | 13 | //! - [Label]
|
|
15 | 16 | //! - [Sample]
|
16 | 17 | //! - [ValueType]
|
17 | 18 | //!
|
| 19 | +//! Serialization typically begins with [Value], which is turned into a [Pair] |
| 20 | +//! by calling [Value::field], and then encoding it. For example, a Mapping is |
| 21 | +//! field `3` of a profile message: |
| 22 | +//! |
| 23 | +//! ``` |
| 24 | +//! # use datadog_profiling_protobuf::*; |
| 25 | +//! # fn main() -> std::io::Result<()> { |
| 26 | +//! let mut writer = Vec::new(); // could be any std::io::Write |
| 27 | +//! let mapping: Mapping = Mapping { |
| 28 | +//! id: 1, |
| 29 | +//! filename: StringOffset::new(2), |
| 30 | +//! ..Mapping::default() |
| 31 | +//! }; |
| 32 | +//! mapping.field(3).encode(&mut writer)?; |
| 33 | +//! # Ok(()) } |
| 34 | +//! ``` |
| 35 | +//! |
18 | 36 | //! There is no serializer for Profile. It would require borrowing a lot of
|
19 | 37 | //! data, which becomes unwieldy. It also isn't very compatible with writing
|
20 | 38 | //! a streaming serializer to lower peak memory usage.
|
@@ -80,10 +98,12 @@ pub trait Value {
|
80 | 98 | }
|
81 | 99 | }
|
82 | 100 |
|
83 |
| -/// A tag and value pair. |
| 101 | +/// A tag and value pair. Call [Pair::proto_len] to get the number of bytes |
| 102 | +/// it takes to encode the Pair if you need to embed it as a submessage, and |
| 103 | +/// use [Pair::encode] to serialize it. |
84 | 104 | ///
|
85 |
| -/// The wire type isn't stored; it's provided by the Value implementation, |
86 |
| -/// which allows us to specialize code. |
| 105 | +/// The wire type isn't stored; it's implicitly provided by the Value's |
| 106 | +/// implementation, which allows a form of code specialization. |
87 | 107 | pub struct Pair<V: Value> {
|
88 | 108 | field: u32,
|
89 | 109 | value: V,
|
|
0 commit comments