Skip to main content

nurtex_codec/types/basic/
float.rs

1use crate::Buffer;
2
3use byteorder::{BE, ReadBytesExt, WriteBytesExt};
4
5impl Buffer for f32 {
6  fn read_buf(buffer: &mut std::io::Cursor<&[u8]>) -> Option<Self> {
7    buffer.read_f32::<BE>().ok()
8  }
9
10  fn write_buf(&self, buffer: &mut impl std::io::Write) -> std::io::Result<()> {
11    buffer.write_f32::<BE>(*self)
12  }
13}
14
15impl Buffer for f64 {
16  fn read_buf(buffer: &mut std::io::Cursor<&[u8]>) -> Option<Self> {
17    buffer.read_f64::<BE>().ok()
18  }
19
20  fn write_buf(&self, buffer: &mut impl std::io::Write) -> std::io::Result<()> {
21    buffer.write_f64::<BE>(*self)
22  }
23}