toe_beans/v4/message/
flags.rs

1/// Wraps a [bit field](https://en.wikipedia.org/wiki/Bit_field) used in [Message](crate::v4::Message).
2///
3/// The two bytes that this field occupies were unused in [RFC-951](https://datatracker.ietf.org/doc/html/rfc951#section-3), and later [defined](https://datatracker.ietf.org/doc/html/rfc1542#section-2.2) then [clarified](https://datatracker.ietf.org/doc/html/rfc1542#section-3.1) in RFC-1542.
4///
5/// The leftmost bit is defined as the Broadcast flag. The remaining bits are reserved for future use, and must be set to zero by clients and ignored by servers and relay agents.
6#[derive(Debug, PartialEq)]
7pub struct Flags {
8    /// Used to work around some clients that cannot accept IP unicast datagrams before the TCP/IP software is configured.
9    pub broadcast: bool,
10}
11
12impl From<&Flags> for [u8; 2] {
13    fn from(flags: &Flags) -> Self {
14        let mut bytes: u16 = 0b00000000_00000000;
15
16        if flags.broadcast {
17            bytes |= 0b10000000_00000000
18        }
19
20        bytes.to_be_bytes()
21    }
22}