Skip to content

Commit

Permalink
Add from_bytes method.
Browse files Browse the repository at this point in the history
Closes #2327
  • Loading branch information
tbro committed Nov 25, 2024
1 parent 60283a5 commit 7f1c813
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions types/src/v0/impls/block/full_payload/ns_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ impl NsTable {
self.len().in_bounds(index)
}

/// Instantiate an `NsTable` from a byte slice.
pub fn from_bytes(bytes: &[u8]) -> NsTable {
NsTable {
bytes: bytes.to_vec(),
}
}

/// Are the bytes of this [`NsTable`] uncorrupted?
///
/// # Checks
Expand Down
7 changes: 7 additions & 0 deletions types/src/v0/impls/block/full_payload/ns_table/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ fn random_valid() {
}
}

#[test]
fn ns_table_from_bytes() {
let bytes = Vec::from([0; NUM_NSS_BYTE_LEN]);
let ns_table = NsTable::from_bytes(&bytes);
expect_valid(&ns_table);
}

#[test]
fn ns_table_byte_len() {
setup_test();
Expand Down

0 comments on commit 7f1c813

Please sign in to comment.