Skip to content

Commit 72a5c99

Browse files
committed
pass
1 parent d1b40a9 commit 72a5c99

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

examples/manual_metadata_encoding.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,22 @@ impl MetadataRoundtrip for IndividualMetadata {
6060
str::from_utf8(&md[std::mem::size_of::<usize>()..size + std::mem::size_of::<usize>()])
6161
.unwrap()
6262
.to_string();
63-
assert_eq!(name, "Jerome");
64-
todo!()
63+
let offset = size + std::mem::size_of::<usize>();
64+
let size: [u8; std::mem::size_of::<usize>()] = md
65+
[offset..offset + std::mem::size_of::<usize>()]
66+
.try_into()
67+
.unwrap();
68+
let size = usize::from_be_bytes(size);
69+
let mut offset = offset + std::mem::size_of::<usize>();
70+
let mut phenotypes = vec![];
71+
for _ in 0..size {
72+
let p: [u8; 4] = md[offset..offset + std::mem::size_of::<i32>()]
73+
.try_into()
74+
.unwrap();
75+
phenotypes.push(i32::from_be_bytes(p));
76+
offset += std::mem::size_of::<i32>();
77+
}
78+
Ok(Self { name, phenotypes })
6579
}
6680
}
6781

0 commit comments

Comments
 (0)