Skip to content

Commit

Permalink
Add from_bytes method. (#2329)
Browse files Browse the repository at this point in the history
* Add `from_bytes_unchecked` method.

Closes #2327

---------

Co-authored-by: tbro <[email protected]>
  • Loading branch information
tbro and tbro authored Nov 25, 2024
1 parent 60283a5 commit c9f9583
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_unchecked(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_unchecked(&bytes);
expect_valid(&ns_table);
}

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

0 comments on commit c9f9583

Please sign in to comment.