toe_beans/v4/message/options/
address.rs1use serde::{Deserialize, Serialize};
2use std::net::Ipv4Addr;
3
4#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
6pub struct AddressOption(Ipv4Addr);
7
8impl AddressOption {
9 pub fn new(ip: Ipv4Addr) -> Self {
11 Self(ip)
12 }
13
14 #[inline]
16 pub fn extend_into(&self, bytes: &mut Vec<u8>, tag: u8) {
17 bytes.push(tag); bytes.push(4); bytes.extend_from_slice(&self.0.octets()); }
21
22 pub fn inner(&self) -> Ipv4Addr {
24 self.0
25 }
26}
27
28impl From<&[u8]> for AddressOption {
29 fn from(value: &[u8]) -> Self {
30 Self(Ipv4Addr::new(value[0], value[1], value[2], value[3]))
31 }
32}