Skip to main content

nurtex_codec/types/basic/
int.rs

1use crate::Buffer;
2
3use byteorder::{BE, ReadBytesExt, WriteBytesExt};
4
5impl Buffer for i8 {
6  fn read_buf(buffer: &mut std::io::Cursor<&[u8]>) -> Option<Self> {
7    buffer.read_i8().ok()
8  }
9
10  fn write_buf(&self, buffer: &mut impl std::io::Write) -> std::io::Result<()> {
11    buffer.write_i8(*self)
12  }
13}
14
15impl Buffer for i16 {
16  fn read_buf(buffer: &mut std::io::Cursor<&[u8]>) -> Option<Self> {
17    buffer.read_i16::<BE>().ok()
18  }
19
20  fn write_buf(&self, buffer: &mut impl std::io::Write) -> std::io::Result<()> {
21    buffer.write_i16::<BE>(*self)
22  }
23}
24
25impl Buffer for i32 {
26  fn read_buf(buffer: &mut std::io::Cursor<&[u8]>) -> Option<Self> {
27    buffer.read_i32::<BE>().ok()
28  }
29
30  fn write_buf(&self, buffer: &mut impl std::io::Write) -> std::io::Result<()> {
31    buffer.write_i32::<BE>(*self)
32  }
33}
34
35impl Buffer for i64 {
36  fn read_buf(buffer: &mut std::io::Cursor<&[u8]>) -> Option<Self> {
37    buffer.read_i64::<BE>().ok()
38  }
39
40  fn write_buf(&self, buffer: &mut impl std::io::Write) -> std::io::Result<()> {
41    buffer.write_i64::<BE>(*self)
42  }
43}