Skip to content

Commit a53ba2c

Browse files
committed
fix: codec v7 version field
1 parent 8c1f7d1 commit a53ba2c

File tree

1 file changed

+21
-3
lines changed
  • crates/codec/src/decoding/v7

1 file changed

+21
-3
lines changed

crates/codec/src/decoding/v7/mod.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ pub fn decode_v7(blob: &[u8]) -> Result<Batch, DecodingError> {
5656
};
5757

5858
// decode the payload.
59-
decode_v7_payload(buf)
59+
decode_v7_payload(version, buf)
6060
}
6161

6262
/// Decode the blob data into a [`Batch`].
63-
pub(crate) fn decode_v7_payload(blob: &[u8]) -> Result<Batch, DecodingError> {
63+
pub(crate) fn decode_v7_payload(version: u8, blob: &[u8]) -> Result<Batch, DecodingError> {
6464
let buf = &mut (&*blob);
6565

6666
// check buf len.
@@ -103,7 +103,7 @@ pub(crate) fn decode_v7_payload(blob: &[u8]) -> Result<Batch, DecodingError> {
103103
skipped_l1_message_bitmap: None,
104104
};
105105

106-
Ok(Batch::new(7, None, payload))
106+
Ok(Batch::new(version, None, payload))
107107
}
108108

109109
#[cfg(test)]
@@ -294,4 +294,22 @@ mod tests {
294294

295295
Ok(())
296296
}
297+
298+
#[test]
299+
fn test_should_decode_v8_mock() -> eyre::Result<()> {
300+
let blob = read_to_bytes("./testdata/blob_v7_uncompressed.bin")?;
301+
let mut blob = blob.to_vec();
302+
// Manually patch the version byte to 8 to simulate a v8 blob.
303+
// BlobSliceIter skips the first byte (index 0) of every 32-byte chunk.
304+
// So the first data byte (version) is at index 1.
305+
blob[1] = 8;
306+
307+
let batch = decode_v7(&blob)?;
308+
assert_eq!(batch.version, 8);
309+
310+
let blocks = batch.data.l2_blocks();
311+
assert_eq!(blocks.len(), 4);
312+
313+
Ok(())
314+
}
297315
}

0 commit comments

Comments
 (0)