1 #[cfg(any(test, feature = "quickcheck"))] 2 use quickcheck::{Arbitrary, Gen}; 3 4 use crate::packet; 5 use crate::Packet; 6 7 /// Holds a Marker packet. 8 /// 9 /// See [Section 5.8 of RFC 4880] for details. 10 /// 11 /// [Section 5.8 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.8 12 // IMPORTANT: If you add fields to this struct, you need to explicitly 13 // IMPORTANT: implement PartialEq, Eq, and Hash. 14 #[derive(Clone, Debug, PartialEq, Eq, Hash)] 15 pub struct Marker { 16 /// CTB packet header fields. 17 pub(crate) common: packet::Common, 18 } 19 20 impl Marker { 21 pub(crate) const BODY: &'static [u8] = &[0x50, 0x47, 0x50]; 22 } 23 24 impl Default for Marker { default() -> Self25 fn default() -> Self { 26 Self { 27 common: Default::default(), 28 } 29 } 30 } 31 32 impl From<Marker> for Packet { from(p: Marker) -> Self33 fn from(p: Marker) -> Self { 34 Packet::Marker(p) 35 } 36 } 37 38 #[cfg(any(test, feature = "quickcheck"))] 39 impl Arbitrary for Marker { arbitrary<G: Gen>(_: &mut G) -> Self40 fn arbitrary<G: Gen>(_: &mut G) -> Self { 41 Self::default() 42 } 43 } 44 45 #[cfg(test)] 46 mod tests { 47 use super::*; 48 use crate::parse::Parse; 49 use crate::serialize::MarshalInto; 50 51 #[test] roundtrip()52 fn roundtrip() { 53 let p = Marker::default(); 54 let q = Marker::from_bytes(&p.to_vec().unwrap()).unwrap(); 55 assert_eq!(p, q); 56 } 57 } 58