Interpret the provided bytes as an [`Lsn`].
(bytes: &[u8])
| 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] { |