diff options
Diffstat (limited to 'shared/src/helper.rs')
-rw-r--r-- | shared/src/helper.rs | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/shared/src/helper.rs b/shared/src/helper.rs index be7d929..873c9d8 100644 --- a/shared/src/helper.rs +++ b/shared/src/helper.rs @@ -36,24 +36,24 @@ pub trait ReadWrite: Sized { impl ReadWrite for f32 { fn write(&self, w: &mut dyn Write) -> Result<()> { - w.write_all(&self.to_be_bytes())?; + w.write_all(&self.to_le_bytes())?; Ok(()) } fn read(r: &mut dyn Read) -> Result<Self> { let mut buf = [0; { size_of::<f32>() }]; r.read_exact(&mut buf)?; - Ok(f32::from_be_bytes(buf)) + Ok(f32::from_le_bytes(buf)) } } impl ReadWrite for u32 { fn write(&self, w: &mut dyn Write) -> Result<()> { - w.write_all(&self.to_be_bytes())?; + w.write_all(&self.to_le_bytes())?; Ok(()) } fn read(r: &mut dyn Read) -> Result<Self> { let mut buf = [0; { size_of::<u32>() }]; r.read_exact(&mut buf)?; - Ok(u32::from_be_bytes(buf)) + Ok(u32::from_le_bytes(buf)) } } impl ReadWrite for Vec<u8> { @@ -97,7 +97,7 @@ impl ReadWrite for Vec<Vec3A> { Ok(buf .into_iter() .array_chunks::<{ size_of::<f32>() }>() - .map(f32::from_be_bytes) + .map(f32::from_le_bytes) .array_chunks::<3>() .map(Vec3A::from_array) .collect()) @@ -116,7 +116,7 @@ impl ReadWrite for Vec<Vec3> { Ok(buf .into_iter() .array_chunks::<{ size_of::<f32>() }>() - .map(f32::from_be_bytes) + .map(f32::from_le_bytes) .array_chunks::<3>() .map(Vec3::from_array) .collect()) @@ -135,7 +135,7 @@ impl ReadWrite for Vec<Vec4> { Ok(buf .into_iter() .array_chunks::<{ size_of::<f32>() }>() - .map(f32::from_be_bytes) + .map(f32::from_le_bytes) .array_chunks::<4>() .map(Vec4::from_array) .collect()) @@ -154,7 +154,7 @@ impl ReadWrite for Vec<Vec2> { Ok(buf .into_iter() .array_chunks::<{ size_of::<f32>() }>() - .map(f32::from_be_bytes) + .map(f32::from_le_bytes) .array_chunks::<2>() .map(Vec2::from_array) .collect()) @@ -163,9 +163,9 @@ impl ReadWrite for Vec<Vec2> { impl ReadWrite for Vec<[u32; 3]> { 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[0].to_le_bytes())?; + w.write_all(&e[1].to_le_bytes())?; + w.write_all(&e[2].to_le_bytes())?; } Ok(()) } @@ -175,7 +175,7 @@ impl ReadWrite for Vec<[u32; 3]> { Ok(buf .into_iter() .array_chunks::<{ size_of::<u32>() }>() - .map(u32::from_be_bytes) + .map(u32::from_le_bytes) .array_chunks::<3>() .collect()) } @@ -183,10 +183,10 @@ impl ReadWrite for Vec<[u32; 3]> { 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())?; + w.write_all(&e[0].to_le_bytes())?; + w.write_all(&e[1].to_le_bytes())?; + w.write_all(&e[2].to_le_bytes())?; + w.write_all(&e[3].to_le_bytes())?; } Ok(()) } @@ -196,7 +196,7 @@ impl ReadWrite for Vec<[u16; 4]> { Ok(buf .into_iter() .array_chunks::<{ size_of::<u16>() }>() - .map(u16::from_be_bytes) + .map(u16::from_le_bytes) .array_chunks::<4>() .collect()) } @@ -204,10 +204,10 @@ impl ReadWrite for Vec<[u16; 4]> { 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())?; + w.write_all(&e[0].to_le_bytes())?; + w.write_all(&e[1].to_le_bytes())?; + w.write_all(&e[2].to_le_bytes())?; + w.write_all(&e[3].to_le_bytes())?; } Ok(()) } @@ -217,7 +217,7 @@ impl ReadWrite for Vec<[f32; 4]> { Ok(buf .into_iter() .array_chunks::<{ size_of::<f32>() }>() - .map(f32::from_be_bytes) + .map(f32::from_le_bytes) .array_chunks::<4>() .collect()) } @@ -235,7 +235,7 @@ impl ReadWrite for Vec<f32> { Ok(buf .into_iter() .array_chunks::<{ size_of::<f32>() }>() - .map(f32::from_be_bytes) + .map(f32::from_le_bytes) .collect()) } } @@ -252,7 +252,7 @@ impl ReadWrite for Vec<u16> { Ok(buf .into_iter() .array_chunks::<{ size_of::<u16>() }>() - .map(u16::from_be_bytes) + .map(u16::from_le_bytes) .collect()) } } @@ -269,7 +269,7 @@ impl ReadWrite for Vec<Affine3A> { Ok(buf .into_iter() .array_chunks::<{ size_of::<f32>() }>() - .map(f32::from_be_bytes) + .map(f32::from_le_bytes) .array_chunks::<12>() .map(|m| Affine3A::from_cols_array(&m)) .collect()) @@ -310,14 +310,14 @@ impl ReadWrite for String { impl ReadWrite for Data { fn write(&self, w: &mut dyn Write) -> Result<()> { - w.write_all(&(self.0.len() as u32).to_be_bytes())?; + w.write_all(&(self.0.len() as u32).to_le_bytes())?; w.write_all(&self.0)?; Ok(()) } fn read(r: &mut dyn Read) -> Result<Self> { let mut size = [0; { size_of::<u32>() }]; r.read_exact(&mut size)?; - let size = u32::from_be_bytes(size); + let size = u32::from_le_bytes(size); let mut buf = vec![0; size as usize]; r.read_exact(&mut buf)?; Ok(Self(buf)) @@ -325,14 +325,14 @@ impl ReadWrite for Data { } impl ReadWrite for Message { fn write(&self, w: &mut dyn Write) -> Result<()> { - w.write_all(&(self.0.len() as u32).to_be_bytes())?; + w.write_all(&(self.0.len() as u32).to_le_bytes())?; w.write_all(self.0.as_bytes())?; Ok(()) } fn read(r: &mut dyn Read) -> Result<Self> { let mut size = [0; { size_of::<u32>() }]; r.read_exact(&mut size)?; - let size = u32::from_be_bytes(size); + let size = u32::from_le_bytes(size); let mut buf = vec![0; size as usize]; r.read_exact(&mut buf)?; Ok(Self(String::from_utf8_lossy_owned(buf))) @@ -351,13 +351,13 @@ impl<T> ReadWrite for Resource<T> { } impl ReadWrite for Object { fn write(&self, w: &mut dyn Write) -> Result<()> { - w.write_all(&self.0.to_be_bytes())?; + w.write_all(&self.0.to_le_bytes())?; Ok(()) } fn read(r: &mut dyn Read) -> Result<Self> { let mut s = [0; 16]; r.read_exact(&mut s)?; - Ok(Object(u128::from_be_bytes(s))) + Ok(Object(u128::from_le_bytes(s))) } } impl<T: ReadWrite, const N: usize> ReadWrite for [T; N] { @@ -474,12 +474,12 @@ impl ReadWrite for u8 { } impl ReadWrite for u16 { fn write(&self, w: &mut dyn Write) -> Result<()> { - w.write_all(&self.to_be_bytes())?; + w.write_all(&self.to_le_bytes())?; Ok(()) } fn read(r: &mut dyn Read) -> Result<Self> { let mut buf = [0u8; 2]; r.read_exact(&mut buf)?; - Ok(u16::from_be_bytes(buf)) + Ok(u16::from_le_bytes(buf)) } } |