toe-beans 0.10.0

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

/// An option that contains ambiguous bytes. For example, it might be an id, with no special meaning, sent by the client.
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct OpaqueOption(Vec<u8>);

impl OpaqueOption {
    /// 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(self.0.len() as u8); // length
        bytes.extend_from_slice(&self.0); // value
    }
}

impl From<&[u8]> for OpaqueOption {
    fn from(value: &[u8]) -> Self {
        Self(value.into())
    }
}