Skip to content

Commit eae5d66

Browse files
committed
Merge branch 'cmc/rrd_footers_1_framing' into cmc/rrd_footers_2_rrd_manifests
2 parents ad754fa + f11d7c3 commit eae5d66

File tree

6 files changed

+57
-51
lines changed

6 files changed

+57
-51
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9085,6 +9085,7 @@ dependencies = [
90859085
"re_protos",
90869086
"re_smart_channel",
90879087
"re_sorbet",
9088+
"re_span",
90889089
"re_tracing",
90899090
"re_types",
90909091
"re_types_core",

crates/store/re_log_encoding/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ re_log.workspace = true
5050
re_protos.workspace = true
5151
re_smart_channel.workspace = true
5252
re_sorbet.workspace = true
53+
re_span.workspace = true
5354
re_tracing.workspace = true
5455
re_types_core.workspace = true
5556

crates/store/re_log_encoding/src/rrd/decoder/state_machine.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,12 @@ impl<T: DecoderEntrypoint> Decoder<T> {
340340
let StreamFooter {
341341
fourcc: _,
342342
identifier: _,
343-
rrd_footer_byte_offset_from_start_excluding_header,
344-
rrd_footer_byte_size_excluding_header,
343+
rrd_footer_byte_span_from_start_excluding_header,
345344
crc_excluding_header: _,
346345
} = footer;
347346

348-
let rrd_footer_start =
349-
rrd_footer_byte_offset_from_start_excluding_header;
350347
let rrd_footer_end =
351-
rrd_footer_start + rrd_footer_byte_size_excluding_header;
348+
rrd_footer_byte_span_from_start_excluding_header.end();
352349

353350
if rrd_footer_end > position as u64 {
354351
// The RRD footer cannot possibly end after the stream footer starts, since it must

crates/store/re_log_encoding/src/rrd/encoder.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ impl FooterState {
109109
#[expect(clippy::unnecessary_wraps)] // won't stay for long
110110
fn append(
111111
&mut self,
112-
_byte_offset: u64,
113-
_byte_size: u64,
112+
_byte_span_excluding_header: re_span::Span<u64>,
114113
msg: &re_log_types::LogMsg,
115114
) -> Result<(), EncodeError> {
116115
match msg {
@@ -226,12 +225,13 @@ impl<W: std::io::Write> Encoder<W> {
226225

227226
let byte_size_excluding_header = n - crate::MessageHeader::ENCODED_SIZE_BYTES as u64;
228227

228+
let byte_span_excluding_header = re_span::Span {
229+
start: byte_offset_excluding_header,
230+
len: byte_size_excluding_header,
231+
};
232+
229233
if let Some(footer_state) = self.footer_state.as_mut() {
230-
footer_state.append(
231-
byte_offset_excluding_header,
232-
byte_size_excluding_header,
233-
message,
234-
)?;
234+
footer_state.append(byte_span_excluding_header, message)?;
235235
}
236236

237237
Ok(n)

crates/store/re_log_encoding/src/rrd/frames.rs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -229,41 +229,39 @@ pub struct StreamFooter {
229229
/// Always set to [`Self::RRD_IDENTIFIER`].
230230
pub identifier: [u8; 4], // FOOT
231231

232-
/// The position in bytes where the serialized [`RrdFooter`] payload starts, excluding the
233-
/// message header.
232+
/// The span in bytes where the serialized [`RrdFooter`] payload starts end ends, excluding
233+
/// the message header.
234234
///
235235
/// I.e. a transport-level [`RrdFooter`] can be decoded from the bytes at (pseudo-code):
236236
/// ```text
237-
/// let start = stream_footer.rrd_footer_byte_offset_from_start_excluding_header;
238-
/// let end = start + stream_footer.rrd_footer_byte_size_excluding_header;
237+
/// let start = stream_footer.rrd_footer_byte_span_from_start_excluding_header.start;
238+
/// let end = stream_footer.rrd_footer_byte_span_from_start_excluding_header.end();
239239
/// let bytes = &file[start..end];
240240
/// let rrd_footer = re_protos::RrdFooter::decode(bytes)?;
241241
/// let rrd_footer = rrd_footer.to_application()?;
242242
/// ```
243243
///
244244
/// [`RrdFooter`]: [crate::RrdFooter]
245-
pub rrd_footer_byte_offset_from_start_excluding_header: u64,
246-
247-
/// The size in bytes of the serialized [`RrdFooter`] payload, excluding the message header.
248-
///
249-
/// This is guaranteed to be the same value as the `len` found in the associated message
250-
/// header, but duplicating it here makes it possible for decoders to get everything they
251-
/// need using a single IO.
252-
///
253-
/// [`RrdFooter`]: [crate::RrdFooter]
254-
pub rrd_footer_byte_size_excluding_header: u64,
245+
pub rrd_footer_byte_span_from_start_excluding_header: re_span::Span<u64>,
255246

256247
/// Checksum for the [`RrdFooter`] payload.
257248
///
258249
/// The footer is most often accessed by jumping straight to it, so this is a nice extra safety
259250
/// to make sure that we didn't just get "lucky" (or unlucky, rather) when jumping around and
260251
/// parsing random bytes.
261252
///
253+
/// For now, the checksum algorithm is hardcoded to `xxh32`, the 32bit variant of the
254+
/// [`xxhash` family of hashing algorithms](https://xxhash.com/).
255+
/// This is fast, HW-accelerated, non-cryptographic hash that is perfect when needing to hash
256+
/// RRD footers, which can potentially get very, very large.
257+
///
262258
/// [`RrdFooter`]: [crate::RrdFooter]
263259
//
264260
// TODO(cmc): It shouldn't be the job of the StreamFooter to carry checksums for a specific
265261
// message's payload. All frames should have identifiers and CRCs for both themselves and their
266262
// payloads, in which case this CRC would belong in the MessageHeader.
263+
// TODO(cmc): In a potential future RRF3, we might make the choice of checksum algorithm
264+
// configurable via flag.
267265
pub crc_excluding_header: u32,
268266
}
269267

@@ -273,15 +271,13 @@ impl StreamFooter {
273271
pub const RRD_IDENTIFIER: [u8; 4] = *b"FOOT";
274272

275273
pub fn new(
276-
rrd_footer_byte_offset_from_start_excluding_header: u64,
277-
rrd_footer_byte_size_excluding_header: u64,
274+
rrd_footer_byte_span_from_start_excluding_header: re_span::Span<u64>,
278275
crc_excluding_header: u32,
279276
) -> Self {
280277
Self {
281278
fourcc: crate::RRD_FOURCC,
282279
identifier: Self::RRD_IDENTIFIER,
283-
rrd_footer_byte_offset_from_start_excluding_header,
284-
rrd_footer_byte_size_excluding_header,
280+
rrd_footer_byte_span_from_start_excluding_header,
285281
crc_excluding_header,
286282
}
287283
}
@@ -291,11 +287,14 @@ impl StreamFooter {
291287
rrd_footer_bytes: &[u8],
292288
) -> Self {
293289
let crc_excluding_header = xxhash_rust::xxh32::xxh32(rrd_footer_bytes, Self::CRC_SEED);
290+
let rrd_footer_byte_span_from_start_excluding_header = re_span::Span {
291+
start: rrd_footer_byte_offset_from_start_excluding_header,
292+
len: rrd_footer_bytes.len() as u64,
293+
};
294294
Self {
295295
fourcc: crate::RRD_FOURCC,
296296
identifier: Self::RRD_IDENTIFIER,
297-
rrd_footer_byte_offset_from_start_excluding_header,
298-
rrd_footer_byte_size_excluding_header: rrd_footer_bytes.len() as u64,
297+
rrd_footer_byte_span_from_start_excluding_header,
299298
crc_excluding_header,
300299
}
301300
}
@@ -306,18 +305,25 @@ impl Encodable for StreamFooter {
306305
let Self {
307306
fourcc,
308307
identifier,
309-
rrd_footer_byte_offset_from_start_excluding_header,
310-
rrd_footer_byte_size_excluding_header,
311-
crc_excluding_header: crc,
308+
rrd_footer_byte_span_from_start_excluding_header,
309+
crc_excluding_header,
312310
} = self;
313311

314312
let before = out.len() as u64;
315313

316314
out.extend_from_slice(fourcc);
317315
out.extend_from_slice(identifier);
318-
out.extend_from_slice(&rrd_footer_byte_offset_from_start_excluding_header.to_le_bytes());
319-
out.extend_from_slice(&rrd_footer_byte_size_excluding_header.to_le_bytes());
320-
out.extend_from_slice(&crc.to_le_bytes());
316+
out.extend_from_slice(
317+
&rrd_footer_byte_span_from_start_excluding_header
318+
.start
319+
.to_le_bytes(),
320+
);
321+
out.extend_from_slice(
322+
&rrd_footer_byte_span_from_start_excluding_header
323+
.len
324+
.to_le_bytes(),
325+
);
326+
out.extend_from_slice(&crc_excluding_header.to_le_bytes());
321327

322328
let n = out.len() as u64 - before;
323329
assert_eq!(Self::ENCODED_SIZE_BYTES as u64, n);
@@ -356,17 +362,16 @@ impl Decodable for StreamFooter {
356362
)));
357363
}
358364

359-
let rrd_footer_byte_offset_from_start_excluding_header =
360-
u64::from_le_bytes(data[8..16].try_into().expect("cannot fail, checked above"));
361-
let rrd_footer_byte_size_excluding_header =
362-
u64::from_le_bytes(data[16..24].try_into().expect("cannot fail, checked above"));
365+
let rrd_footer_byte_span_from_start_excluding_header = re_span::Span {
366+
start: u64::from_le_bytes(data[8..16].try_into().expect("cannot fail, checked above")),
367+
len: u64::from_le_bytes(data[16..24].try_into().expect("cannot fail, checked above")),
368+
};
363369
let crc = u32::from_le_bytes(data[24..28].try_into().expect("cannot fail, checked above"));
364370

365371
Ok(Self {
366372
fourcc,
367373
identifier,
368-
rrd_footer_byte_offset_from_start_excluding_header,
369-
rrd_footer_byte_size_excluding_header,
374+
rrd_footer_byte_span_from_start_excluding_header,
370375
crc_excluding_header: crc,
371376
})
372377
}

crates/store/re_log_encoding/tests/footers_and_manifests.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,18 @@ fn footer_empty() {
6464
re_log_encoding::StreamFooter::from_rrd_bytes(&msgs_encoded[stream_footer_start..])
6565
.unwrap();
6666

67-
let rrd_footer_start =
68-
stream_footer.rrd_footer_byte_offset_from_start_excluding_header as usize;
69-
let rrd_footer_end = rrd_footer_start
70-
.checked_add(stream_footer.rrd_footer_byte_size_excluding_header as usize)
71-
.unwrap();
72-
let rrd_footer_bytes = &msgs_encoded[rrd_footer_start..rrd_footer_end];
67+
let rrd_footer_range = stream_footer
68+
.rrd_footer_byte_span_from_start_excluding_header
69+
.try_cast::<usize>()
70+
.unwrap()
71+
.range();
72+
let rrd_footer_bytes = &msgs_encoded[rrd_footer_range];
7373

7474
{
7575
let crc = re_log_encoding::StreamFooter::from_rrd_footer_bytes(
76-
rrd_footer_start as u64,
76+
stream_footer
77+
.rrd_footer_byte_span_from_start_excluding_header
78+
.start,
7779
rrd_footer_bytes,
7880
)
7981
.crc_excluding_header;

0 commit comments

Comments
 (0)