Skip to content

Commit b142c9c

Browse files
committed
packrat-api: Rename and document ereport delivery methods
@cbiffle noted (quite rightly!) yesterday that the name of `Packrat::encode_ereport` was somewhat unclear, as it both encodes the ereport *and* delivers it to Packrat. This commit renames the method and adds some slightly nicer documentation to it.
1 parent cf2e23b commit b142c9c

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

drv/cosmo-seq-server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ fn try_send_ereport(
10681068
class: EreportClass,
10691069
report: EreportKind,
10701070
) {
1071-
let eresult = packrat.encode_ereport(
1071+
let eresult = packrat.deliver_microcbor_ereport(
10721072
&task_packrat_api::Ereport {
10731073
class,
10741074
version: 0,

drv/gimlet-seq-server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ fn try_send_ereport(
16061606
class: EreportClass,
16071607
report: EreportKind,
16081608
) {
1609-
let eresult = packrat.encode_ereport(
1609+
let eresult = packrat.deliver_microcbor_ereport(
16101610
&packrat_api::Ereport {
16111611
class,
16121612
version: 0,

drv/psc-seq-server/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,9 @@ fn main() -> ! {
686686
}
687687
if let Some(ereport) = step.ereport {
688688
let psu = PSU_SLOTS[ereport.report.slot as usize];
689-
match packrat.encode_ereport(&ereport, &mut ereport_buf[..]) {
689+
match packrat
690+
.deliver_microcbor_ereport(&ereport, &mut ereport_buf[..])
691+
{
690692
Ok(len) => ringbuf_entry!(
691693
__TRACE,
692694
Trace::EreportSent {

drv/sidecar-seq-server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ fn try_send_ereport(
11161116
class: EreportClass,
11171117
report: EreportKind,
11181118
) {
1119-
let eresult = packrat.encode_ereport(
1119+
let eresult = packrat.deliver_microcbor_ereport(
11201120
&task_packrat_api::Ereport {
11211121
class,
11221122
version: 0,

task/packrat-api/src/lib.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ pub struct Ereport<C, D> {
114114
}
115115

116116
impl Packrat {
117-
/// Deliver an ereport for a value that implements [`serde::Serialize`]. The
118-
/// provided `buf` is used to serialize the value before sending it to
119-
/// Packrat.
117+
/// Deliver an ereport for a value that implements [`serde::Serialize`].
118+
///
119+
/// This method both encodes the ereport as CBOR into the provided `buf`
120+
/// (using `minicbor_serde`) and then delivers the encoded ereport to
121+
/// `packrat`.
120122
#[cfg(feature = "serde")]
121-
pub fn serialize_ereport(
123+
pub fn deliver_serde_ereport(
122124
&self,
123125
ereport: &impl serde::Serialize,
124126
buf: &mut [u8],
@@ -146,11 +148,22 @@ impl Packrat {
146148
Ok(len)
147149
}
148150

151+
/// Deliver an ereport for a value that implements [`microcbor::Encode`] and
152+
/// [`microcbor::StaticCborLen`].
153+
///
154+
/// This method both encodes the ereport as CBOR into the provided `buf` and
155+
/// then delivers the encoded ereport to `packrat`.
156+
///
157+
/// `buf` should generally be a buffer constructed using the
158+
/// [`microcbor::max_cbor_len_for!`] to determine the maximum length of the
159+
/// buffer needed to encode any of a set of ereport types. This ensures that
160+
/// it will never be too short to contain the encoded ereport.
161+
///
149162
// TODO(eliza): I really want this to be able to statically check that the
150163
// buffer is >= E::MAX_CBOR_LEN but unfortunately that isn't currently
151164
// possible due to https://github.com/rust-lang/rust/issues/132980...
152165
#[cfg(feature = "microcbor")]
153-
pub fn encode_ereport<E: StaticCborLen>(
166+
pub fn deliver_microcbor_ereport<E: StaticCborLen>(
154167
&self,
155168
ereport: &E,
156169
buf: &mut [u8],

0 commit comments

Comments
 (0)