diff -r 2470a15711b1 -r 1567e8a5a0cb src/vrrpv2.rs --- a/src/vrrpv2.rs Sat Jan 06 22:50:47 2024 +0530 +++ b/src/vrrpv2.rs Wed Jan 10 16:29:32 2024 +0530 @@ -133,7 +133,31 @@ } !(sum as u16) } - +/// Parse and validate a byte array to construct a VRRPv2 struct. +/// +/// # Examples +/// +/// ``` +/// use vrrpd::vrrpv2::VRRPv2; +/// use vrrpd::vrrpv2::VRRPv2AuthType; +/// use vrrpd::vrrpv2::from_bytes; +/// use std::net::Ipv4Addr; +/// +/// let bytes = [ +/// 0x21, 0x01, 0x64, 0x01, 0x00, 0x01, 0xba, 0x52, 0xc0, 0xa8, 0x00, 0x01, 0x00, 0x00, 0x00, +/// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +/// ]; +/// let expected = VRRPv2 { +/// virtual_router_id: 1, +/// priority: 100, +/// count_ip_addrs: 1, +/// auth_type: VRRPv2AuthType::VRRPv2AuthNoAuth, +/// checksum: 47698, +/// advertisement_interval: 1, +/// ip_addrs: vec![Ipv4Addr::from([192, 168, 0, 1])], +/// }; +/// assert_eq!(from_bytes(&bytes), Ok(expected)); +/// ``` pub fn from_bytes(bytes: &[u8]) -> Result { let vrrpv2 = parse(bytes)?; if checksum(bytes) != 0 {