diff options
Diffstat (limited to 'shared/src/helper.rs')
-rw-r--r-- | shared/src/helper.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/shared/src/helper.rs b/shared/src/helper.rs index d46a830..723f91e 100644 --- a/shared/src/helper.rs +++ b/shared/src/helper.rs @@ -161,6 +161,48 @@ impl ReadWrite for Vec<[u32; 3]> { .collect()) } } +impl ReadWrite for Vec<[u16; 4]> { + fn write(&self, w: &mut dyn Write) -> Result<()> { + for e in self { + w.write_all(&e[0].to_be_bytes())?; + w.write_all(&e[1].to_be_bytes())?; + w.write_all(&e[2].to_be_bytes())?; + w.write_all(&e[3].to_be_bytes())?; + } + Ok(()) + } + fn read(r: &mut dyn Read) -> Result<Self> { + let mut buf = Vec::new(); + r.read_to_end(&mut buf)?; + Ok(buf + .into_iter() + .array_chunks::<{ size_of::<u16>() }>() + .map(u16::from_be_bytes) + .array_chunks::<4>() + .collect()) + } +} +impl ReadWrite for Vec<[f32; 4]> { + fn write(&self, w: &mut dyn Write) -> Result<()> { + for e in self { + w.write_all(&e[0].to_be_bytes())?; + w.write_all(&e[1].to_be_bytes())?; + w.write_all(&e[2].to_be_bytes())?; + w.write_all(&e[3].to_be_bytes())?; + } + Ok(()) + } + fn read(r: &mut dyn Read) -> Result<Self> { + let mut buf = Vec::new(); + r.read_to_end(&mut buf)?; + Ok(buf + .into_iter() + .array_chunks::<{ size_of::<f32>() }>() + .map(f32::from_be_bytes) + .array_chunks::<4>() + .collect()) + } +} impl ReadWrite for Vec<f32> { fn write(&self, w: &mut dyn Write) -> Result<()> { for e in self { |