parsenic/be/
write.rs

1use traitful::extend;
2
3use crate::result::FullResult;
4
5/// Big endian writer extension trait
6#[extend]
7pub trait Write: crate::Write {
8    /// Write out a big endian encoded 2-byte unsigned integer.
9    fn u16(&mut self, int: u16) -> FullResult {
10        self.bytes(int.to_be_bytes())
11    }
12
13    /// Write out a big endian encoded 4-byte unsigned integer.
14    fn u32(&mut self, int: u32) -> FullResult {
15        self.bytes(int.to_be_bytes())
16    }
17
18    /// Write out a big endian encoded 8-byte unsigned integer.
19    fn u64(&mut self, int: u64) -> FullResult {
20        self.bytes(int.to_be_bytes())
21    }
22
23    /// Write out a big endian encoded 16-byte unsigned integer.
24    fn u128(&mut self, int: u128) -> FullResult {
25        self.bytes(int.to_be_bytes())
26    }
27
28    /// Write out a big endian encoded 2-byte signed integer.
29    fn i16(&mut self, int: i16) -> FullResult {
30        self.bytes(int.to_be_bytes())
31    }
32
33    /// Write out a big endian encoded 4-byte signed integer.
34    fn i32(&mut self, int: i32) -> FullResult {
35        self.bytes(int.to_be_bytes())
36    }
37
38    /// Write out a big endian encoded 8-byte signed integer.
39    fn i64(&mut self, int: i64) -> FullResult {
40        self.bytes(int.to_be_bytes())
41    }
42
43    /// Write out a big endian encoded 16-byte signed integer.
44    fn i128(&mut self, int: i128) -> FullResult {
45        self.bytes(int.to_be_bytes())
46    }
47
48    /// Write out a big endian encoded 32-bit float.
49    fn f32(&mut self, float: f32) -> FullResult {
50        self.bytes(float.to_be_bytes())
51    }
52
53    /// Write out a big endian encoded 64-bit float.
54    fn f64(&mut self, float: f64) -> FullResult {
55        self.bytes(float.to_be_bytes())
56    }
57}