@@ -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 }
0 commit comments