toe-beans 0.10.0

DHCP library, client, and server
Documentation
use serde::{Deserialize, Serialize};

/// Variants of option 52 in [MessageOptions](crate::v4::MessageOptions).
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[repr(u8)]
pub enum OverloadOptions {
    /// The 128 bytes of `Message.file` are used to store additional options.
    File,
    /// The 64 bytes of `Message.sname` are used to store additional options.
    Sname,
    /// The 192 bytes of `Message.file` and `Message.sname` are used to store additional options.
    Both,
}

impl From<&OverloadOptions> for u8 {
    fn from(mtype: &OverloadOptions) -> Self {
        match mtype {
            OverloadOptions::File => 1,
            OverloadOptions::Sname => 2,
            OverloadOptions::Both => 3,
        }
    }
}

impl From<&[u8]> for OverloadOptions {
    fn from(value: &[u8]) -> Self {
        match value[0] {
            1 => OverloadOptions::File,
            2 => OverloadOptions::Sname,
            3 => OverloadOptions::Both,
            _ => OverloadOptions::Both,
        }
    }
}

impl OverloadOptions {
    /// Used, when serializing, to add to the byte buffer.
    #[inline]
    pub fn extend_into(&self, bytes: &mut Vec<u8>, tag: u8) {
        bytes.push(tag); // tag
        bytes.push(1); // length
        bytes.push(self.into()); // value
    }
}