MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / try_from_bytes

Method try_from_bytes

src/sql-server-util/src/cdc.rs:527–541  ·  view source on GitHub ↗

Interpret the provided bytes as an [`Lsn`].

(bytes: &[u8])

Source from the content-addressed store, hash-verified

525
526 /// Interpret the provided bytes as an [`Lsn`].
527 pub fn try_from_bytes(bytes: &[u8]) -> Result<Self, String> {
528 if bytes.len() != Self::SIZE {
529 return Err(format!("incorrect length, expected 10 got {}", bytes.len()));
530 }
531
532 let vlf_id: [u8; 4] = bytes[0..4].try_into().expect("known good length");
533 let block_id: [u8; 4] = bytes[4..8].try_into().expect("known good length");
534 let record_id: [u8; 2] = bytes[8..].try_into().expect("known good length");
535
536 Ok(Lsn {
537 vlf_id: u32::from_be_bytes(vlf_id),
538 block_id: u32::from_be_bytes(block_id),
539 record_id: u16::from_be_bytes(record_id),
540 })
541 }
542
543 /// Return the underlying byte slice for this [`Lsn`].
544 pub fn as_bytes(&self) -> [u8; 10] {

Callers

nothing calls this directly

Calls 3

expectMethod · 0.80
lenMethod · 0.45
try_intoMethod · 0.45

Tested by

no test coverage detected