pgcopy/types/implementation/
macaddr.rs

1use std::io;
2
3use byteorder::{WriteBytesExt, NetworkEndian};
4
5use crate::types::MacAddr;
6
7impl MacAddr for [u8; 6] {
8    fn to_writer<W: io::Write>(&self, writer: &mut W) -> io::Result<()> {
9        writer.write_i32::<NetworkEndian>(6)?;
10        for byte in self {
11            writer.write_u8(*byte)?;
12        }
13
14        Ok(())
15    }
16}
17
18#[cfg(feature = "with-eui48")]
19mod with_eui48 {
20    use std::io;
21
22    use byteorder::{WriteBytesExt, NetworkEndian};
23    use eui48::MacAddress;
24    use crate::types::MacAddr;
25
26    impl MacAddr for MacAddress {
27        fn to_writer<W: io::Write>(&self, writer: &mut W) -> io::Result<()> {
28            writer.write_i32::<NetworkEndian>(6)?;
29            for byte in self.as_bytes() {
30                writer.write_u8(*byte)?;
31            }
32
33            Ok(())
34        }
35    }
36}