1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
use pnet_macros_support::types::*;
use std::mem;

const FIXED_SIZE_COMPONENT: usize =
    std::mem::size_of::<u16>() + std::mem::size_of::<u32>();

// NOTE: pnet macro limitations disallow doc comments for now...





#[derive(PartialEq)]
/// A structure enabling manipulation of on the wire packets
pub struct IpDiscoveryPacket<'p> {
    packet: ::pnet_macros_support::packet::PacketData<'p>,
}
#[derive(PartialEq)]
/// A structure enabling manipulation of on the wire packets
pub struct MutableIpDiscoveryPacket<'p> {
    packet: ::pnet_macros_support::packet::MutPacketData<'p>,
}
impl <'a> IpDiscoveryPacket<'a> {
    /// Constructs a new IpDiscoveryPacket. If the provided buffer is less than the minimum required
    /// packet size, this will return None.
    #[inline]
    pub fn new<'p>(packet: &'p [u8]) -> Option<IpDiscoveryPacket<'p>> {
        if packet.len() >= IpDiscoveryPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::PacketData;
            Some(IpDiscoveryPacket{packet: PacketData::Borrowed(packet),})
        } else { None }
    }
    /// Constructs a new IpDiscoveryPacket. If the provided buffer is less than the minimum required
    /// packet size, this will return None. With this constructor the IpDiscoveryPacket will
    /// own its own data and the underlying buffer will be dropped when the IpDiscoveryPacket is.
    pub fn owned(packet: Vec<u8>) -> Option<IpDiscoveryPacket<'static>> {
        if packet.len() >= IpDiscoveryPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::PacketData;
            Some(IpDiscoveryPacket{packet: PacketData::Owned(packet),})
        } else { None }
    }
    /// Maps from a IpDiscoveryPacket to a IpDiscoveryPacket
    #[inline]
    pub fn to_immutable<'p>(&'p self) -> IpDiscoveryPacket<'p> {
        use ::pnet_macros_support::packet::PacketData;
        IpDiscoveryPacket{packet:
                              PacketData::Borrowed(self.packet.as_slice()),}
    }
    /// Maps from a IpDiscoveryPacket to a IpDiscoveryPacket while consuming the source
    #[inline]
    pub fn consume_to_immutable(self) -> IpDiscoveryPacket<'a> {
        IpDiscoveryPacket{packet: self.packet.to_immutable(),}
    }
    /// The minimum size (in bytes) a packet of this type can be. It's based on the total size
    /// of the fixed-size fields.
    #[inline]
    pub const fn minimum_packet_size() -> usize { 10 }
    /// The size (in bytes) of a IpDiscovery instance when converted into
    /// a byte-array
    #[inline]
    pub fn packet_size(_packet: &IpDiscovery) -> usize {
        10 + _packet.address.len() + _packet.payload.len()
    }
    /// Get the value of the pkt_type field
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_pkt_type(&self) -> IpDiscoveryType {
        #[inline(always)]
        #[allow(trivial_numeric_casts, unused_parens)]
        #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
        fn get_arg0(_self: &IpDiscoveryPacket) -> u16be {
            let co = 0;
            let b0 = ((_self.packet[co + 0] as u16be) << 8) as u16be;
            let b1 = ((_self.packet[co + 1] as u16be)) as u16be;
            b0 | b1
        }
        IpDiscoveryType::new(get_arg0(&self))
    }
    /// Get the length field. This field is always stored big-endian
    /// within the struct, but this accessor returns host order.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_length(&self) -> u16be {
        let _self = self;
        let co = 2;
        let b0 = ((_self.packet[co + 0] as u16be) << 8) as u16be;
        let b1 = ((_self.packet[co + 1] as u16be)) as u16be;
        b0 | b1
    }
    /// Get the ssrc field. This field is always stored big-endian
    /// within the struct, but this accessor returns host order.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_ssrc(&self) -> u32be {
        let _self = self;
        let co = 4;
        let b0 = ((_self.packet[co + 0] as u32be) << 24) as u32be;
        let b1 = ((_self.packet[co + 1] as u32be) << 16) as u32be;
        let b2 = ((_self.packet[co + 2] as u32be) << 8) as u32be;
        let b3 = ((_self.packet[co + 3] as u32be)) as u32be;
        b0 | b1 | b2 | b3
    }
    /// Get the raw &[u8] value of the address field, without copying
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_address_raw(&self) -> &[u8] {
        use std::cmp::min;
        let _self = self;
        let current_offset = 8;
        let end =
            min(current_offset + (_self.get_length() as usize) -
                    (FIXED_SIZE_COMPONENT as usize), _self.packet.len());
        &_self.packet[current_offset..end]
    }
    /// Get the value of the address field (copies contents)
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_address(&self) -> Vec<u8> {
        use std::cmp::min;
        let _self = self;
        let current_offset = 8;
        let pkt_len = self.packet.len();
        let end =
            min(current_offset + (_self.get_length() as usize) -
                    (FIXED_SIZE_COMPONENT as usize), pkt_len);
        let packet = &_self.packet[current_offset..end];
        let mut vec: Vec<u8> = Vec::with_capacity(packet.len());
        let mut co = 0;
        for _ in 0..vec.capacity() {
            vec.push({ (packet[co] as u8) });
            co += 1;
        }
        vec
    }
    /// Get the port field. This field is always stored big-endian
    /// within the struct, but this accessor returns host order.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_port(&self) -> u16be {
        let _self = self;
        let co =
            8 + (_self.get_length() as usize) -
                (FIXED_SIZE_COMPONENT as usize);
        let b0 = ((_self.packet[co + 0] as u16be) << 8) as u16be;
        let b1 = ((_self.packet[co + 1] as u16be)) as u16be;
        b0 | b1
    }
}
impl <'a> MutableIpDiscoveryPacket<'a> {
    /// Constructs a new MutableIpDiscoveryPacket. If the provided buffer is less than the minimum required
    /// packet size, this will return None.
    #[inline]
    pub fn new<'p>(packet: &'p mut [u8])
     -> Option<MutableIpDiscoveryPacket<'p>> {
        if packet.len() >= MutableIpDiscoveryPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::MutPacketData;
            Some(MutableIpDiscoveryPacket{packet:
                                              MutPacketData::Borrowed(packet),})
        } else { None }
    }
    /// Constructs a new MutableIpDiscoveryPacket. If the provided buffer is less than the minimum required
    /// packet size, this will return None. With this constructor the MutableIpDiscoveryPacket will
    /// own its own data and the underlying buffer will be dropped when the MutableIpDiscoveryPacket is.
    pub fn owned(packet: Vec<u8>)
     -> Option<MutableIpDiscoveryPacket<'static>> {
        if packet.len() >= MutableIpDiscoveryPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::MutPacketData;
            Some(MutableIpDiscoveryPacket{packet:
                                              MutPacketData::Owned(packet),})
        } else { None }
    }
    /// Maps from a MutableIpDiscoveryPacket to a IpDiscoveryPacket
    #[inline]
    pub fn to_immutable<'p>(&'p self) -> IpDiscoveryPacket<'p> {
        use ::pnet_macros_support::packet::PacketData;
        IpDiscoveryPacket{packet:
                              PacketData::Borrowed(self.packet.as_slice()),}
    }
    /// Maps from a MutableIpDiscoveryPacket to a IpDiscoveryPacket while consuming the source
    #[inline]
    pub fn consume_to_immutable(self) -> IpDiscoveryPacket<'a> {
        IpDiscoveryPacket{packet: self.packet.to_immutable(),}
    }
    /// The minimum size (in bytes) a packet of this type can be. It's based on the total size
    /// of the fixed-size fields.
    #[inline]
    pub const fn minimum_packet_size() -> usize { 10 }
    /// The size (in bytes) of a IpDiscovery instance when converted into
    /// a byte-array
    #[inline]
    pub fn packet_size(_packet: &IpDiscovery) -> usize {
        10 + _packet.address.len() + _packet.payload.len()
    }
    /// Populates a IpDiscoveryPacket using a IpDiscovery structure
    #[inline]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn populate(&mut self, packet: &IpDiscovery) {
        let _self = self;
        _self.set_pkt_type(packet.pkt_type);
        _self.set_length(packet.length);
        _self.set_ssrc(packet.ssrc);
        _self.set_address(&packet.address);
        _self.set_port(packet.port);
        _self.set_payload(&packet.payload);
    }
    /// Get the value of the pkt_type field
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_pkt_type(&self) -> IpDiscoveryType {
        #[inline(always)]
        #[allow(trivial_numeric_casts, unused_parens)]
        #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
        fn get_arg0(_self: &MutableIpDiscoveryPacket) -> u16be {
            let co = 0;
            let b0 = ((_self.packet[co + 0] as u16be) << 8) as u16be;
            let b1 = ((_self.packet[co + 1] as u16be)) as u16be;
            b0 | b1
        }
        IpDiscoveryType::new(get_arg0(&self))
    }
    /// Get the length field. This field is always stored big-endian
    /// within the struct, but this accessor returns host order.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_length(&self) -> u16be {
        let _self = self;
        let co = 2;
        let b0 = ((_self.packet[co + 0] as u16be) << 8) as u16be;
        let b1 = ((_self.packet[co + 1] as u16be)) as u16be;
        b0 | b1
    }
    /// Get the ssrc field. This field is always stored big-endian
    /// within the struct, but this accessor returns host order.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_ssrc(&self) -> u32be {
        let _self = self;
        let co = 4;
        let b0 = ((_self.packet[co + 0] as u32be) << 24) as u32be;
        let b1 = ((_self.packet[co + 1] as u32be) << 16) as u32be;
        let b2 = ((_self.packet[co + 2] as u32be) << 8) as u32be;
        let b3 = ((_self.packet[co + 3] as u32be)) as u32be;
        b0 | b1 | b2 | b3
    }
    /// Get the raw &[u8] value of the address field, without copying
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_address_raw(&self) -> &[u8] {
        use std::cmp::min;
        let _self = self;
        let current_offset = 8;
        let end =
            min(current_offset + (_self.get_length() as usize) -
                    (FIXED_SIZE_COMPONENT as usize), _self.packet.len());
        &_self.packet[current_offset..end]
    }
    /// Get the value of the address field (copies contents)
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_address(&self) -> Vec<u8> {
        use std::cmp::min;
        let _self = self;
        let current_offset = 8;
        let pkt_len = self.packet.len();
        let end =
            min(current_offset + (_self.get_length() as usize) -
                    (FIXED_SIZE_COMPONENT as usize), pkt_len);
        let packet = &_self.packet[current_offset..end];
        let mut vec: Vec<u8> = Vec::with_capacity(packet.len());
        let mut co = 0;
        for _ in 0..vec.capacity() {
            vec.push({ (packet[co] as u8) });
            co += 1;
        }
        vec
    }
    /// Get the port field. This field is always stored big-endian
    /// within the struct, but this accessor returns host order.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_port(&self) -> u16be {
        let _self = self;
        let co =
            8 + (_self.get_length() as usize) -
                (FIXED_SIZE_COMPONENT as usize);
        let b0 = ((_self.packet[co + 0] as u16be) << 8) as u16be;
        let b1 = ((_self.packet[co + 1] as u16be)) as u16be;
        b0 | b1
    }
    /// Set the value of the pkt_type field.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_pkt_type(&mut self, val: IpDiscoveryType) {
        use pnet_macros_support::packet::PrimitiveValues;
        let _self = self;
        #[inline]
        #[allow(trivial_numeric_casts)]
        #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
        fn set_arg0(_self: &mut MutableIpDiscoveryPacket, val: u16be) {
            let co = 0;
            _self.packet[co + 0] = ((val & 65280) >> 8) as u8;
            _self.packet[co + 1] = (val) as u8;
        }
        let vals = val.to_primitive_values();
        set_arg0(_self, vals.0);
    }
    /// Set the length field. This field is always stored big-endian
    /// within the struct, but this mutator wants host order.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_length(&mut self, val: u16be) {
        let _self = self;
        let co = 2;
        _self.packet[co + 0] = ((val & 65280) >> 8) as u8;
        _self.packet[co + 1] = (val) as u8;
    }
    /// Set the ssrc field. This field is always stored big-endian
    /// within the struct, but this mutator wants host order.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_ssrc(&mut self, val: u32be) {
        let _self = self;
        let co = 4;
        _self.packet[co + 0] = ((val & 4278190080) >> 24) as u8;
        _self.packet[co + 1] = ((val & 16711680) >> 16) as u8;
        _self.packet[co + 2] = ((val & 65280) >> 8) as u8;
        _self.packet[co + 3] = (val) as u8;
    }
    /// Get the raw &mut [u8] value of the address field, without copying
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_address_raw_mut(&mut self) -> &mut [u8] {
        use std::cmp::min;
        let _self = self;
        let current_offset = 8;
        let end =
            min(current_offset + (_self.get_length() as usize) -
                    (FIXED_SIZE_COMPONENT as usize), _self.packet.len());
        &mut _self.packet[current_offset..end]
    }
    /// Set the value of the address field (copies contents)
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_address(&mut self, vals: &[u8]) {
        use std::ptr::copy_nonoverlapping;
        let mut _self = self;
        let current_offset = 8;
        let len =
            (_self.get_length() as usize) - (FIXED_SIZE_COMPONENT as usize);
        assert!(vals . len (  ) <= len);
        unsafe {
            copy_nonoverlapping(vals[..].as_ptr(),
                                _self.packet[current_offset..].as_mut_ptr(),
                                vals.len())
        }
    }
    /// Set the port field. This field is always stored big-endian
    /// within the struct, but this mutator wants host order.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_port(&mut self, val: u16be) {
        let _self = self;
        let co =
            8 + (_self.get_length() as usize) -
                (FIXED_SIZE_COMPONENT as usize);
        _self.packet[co + 0] = ((val & 65280) >> 8) as u8;
        _self.packet[co + 1] = (val) as u8;
    }
    /// Set the value of the payload field (copies contents)
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_payload(&mut self, vals: &[u8]) {
        use std::ptr::copy_nonoverlapping;
        let mut _self = self;
        let current_offset =
            10 + (_self.get_length() as usize) -
                (FIXED_SIZE_COMPONENT as usize);
        let len = 0;
        assert!(vals . len (  ) <= len);
        unsafe {
            copy_nonoverlapping(vals[..].as_ptr(),
                                _self.packet[current_offset..].as_mut_ptr(),
                                vals.len())
        }
    }
}
impl <'a> ::pnet_macros_support::packet::PacketSize for IpDiscoveryPacket<'a>
 {
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    fn packet_size(&self) -> usize {
        let _self = self;
        10 + (_self.get_length() as usize) - (FIXED_SIZE_COMPONENT as usize) +
            0
    }
}
impl <'a> ::pnet_macros_support::packet::PacketSize for
 MutableIpDiscoveryPacket<'a> {
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    fn packet_size(&self) -> usize {
        let _self = self;
        10 + (_self.get_length() as usize) - (FIXED_SIZE_COMPONENT as usize) +
            0
    }
}
impl <'a> ::pnet_macros_support::packet::MutablePacket for
 MutableIpDiscoveryPacket<'a> {
    #[inline]
    fn packet_mut<'p>(&'p mut self) -> &'p mut [u8] { &mut self.packet[..] }
    #[inline]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    fn payload_mut<'p>(&'p mut self) -> &'p mut [u8] {
        let _self = self;
        let start =
            10 + (_self.get_length() as usize) -
                (FIXED_SIZE_COMPONENT as usize);
        let end =
            ::std::cmp::min(10 + (_self.get_length() as usize) -
                                (FIXED_SIZE_COMPONENT as usize) + 0,
                            _self.packet.len());
        if _self.packet.len() <= start { return &mut []; }
        &mut _self.packet[start..end]
    }
}
impl <'a> ::pnet_macros_support::packet::Packet for
 MutableIpDiscoveryPacket<'a> {
    #[inline]
    fn packet<'p>(&'p self) -> &'p [u8] { &self.packet[..] }
    #[inline]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    fn payload<'p>(&'p self) -> &'p [u8] {
        let _self = self;
        let start =
            10 + (_self.get_length() as usize) -
                (FIXED_SIZE_COMPONENT as usize);
        let end =
            ::std::cmp::min(10 + (_self.get_length() as usize) -
                                (FIXED_SIZE_COMPONENT as usize) + 0,
                            _self.packet.len());
        if _self.packet.len() <= start { return &[]; }
        &_self.packet[start..end]
    }
}
impl <'a> ::pnet_macros_support::packet::Packet for IpDiscoveryPacket<'a> {
    #[inline]
    fn packet<'p>(&'p self) -> &'p [u8] { &self.packet[..] }
    #[inline]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    fn payload<'p>(&'p self) -> &'p [u8] {
        let _self = self;
        let start =
            10 + (_self.get_length() as usize) -
                (FIXED_SIZE_COMPONENT as usize);
        let end =
            ::std::cmp::min(10 + (_self.get_length() as usize) -
                                (FIXED_SIZE_COMPONENT as usize) + 0,
                            _self.packet.len());
        if _self.packet.len() <= start { return &[]; }
        &_self.packet[start..end]
    }
}
/// Used to iterate over a slice of `IpDiscoveryPacket`s
pub struct IpDiscoveryIterable<'a> {
    buf: &'a [u8],
}
impl <'a> Iterator for IpDiscoveryIterable<'a> {
    type
    Item
    =
    IpDiscoveryPacket<'a>;
    fn next(&mut self) -> Option<IpDiscoveryPacket<'a>> {
        use pnet_macros_support::packet::PacketSize;
        use std::cmp::min;
        if self.buf.len() > 0 {
            if let Some(ret) = IpDiscoveryPacket::new(self.buf) {
                let start = min(ret.packet_size(), self.buf.len());
                self.buf = &self.buf[start..];
                return Some(ret);
            }
        }
        None
    }
    fn size_hint(&self) -> (usize, Option<usize>) { (0, None) }
}
impl <'p> ::pnet_macros_support::packet::FromPacket for IpDiscoveryPacket<'p>
 {
    type
    T
    =
    IpDiscovery;
    #[inline]
    fn from_packet(&self) -> IpDiscovery {
        use pnet_macros_support::packet::Packet;
        let _self = self;
        IpDiscovery{pkt_type: _self.get_pkt_type(),
                    length: _self.get_length(),
                    ssrc: _self.get_ssrc(),
                    address: _self.get_address(),
                    port: _self.get_port(),
                    payload:
                        {
                            let payload = self.payload();
                            let mut vec = Vec::with_capacity(payload.len());
                            vec.extend_from_slice(payload);
                            vec
                        },}
    }
}
impl <'p> ::pnet_macros_support::packet::FromPacket for
 MutableIpDiscoveryPacket<'p> {
    type
    T
    =
    IpDiscovery;
    #[inline]
    fn from_packet(&self) -> IpDiscovery {
        use pnet_macros_support::packet::Packet;
        let _self = self;
        IpDiscovery{pkt_type: _self.get_pkt_type(),
                    length: _self.get_length(),
                    ssrc: _self.get_ssrc(),
                    address: _self.get_address(),
                    port: _self.get_port(),
                    payload:
                        {
                            let payload = self.payload();
                            let mut vec = Vec::with_capacity(payload.len());
                            vec.extend_from_slice(payload);
                            vec
                        },}
    }
}
impl <'p> ::std::fmt::Debug for IpDiscoveryPacket<'p> {
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
        let _self = self;
        write!(fmt ,
               "IpDiscoveryPacket {{ pkt_type : {:?}, length : {:?}, ssrc : {:?}, address : {:?}, port : {:?},  }}"
               , _self . get_pkt_type (  ) , _self . get_length (  ) , _self .
               get_ssrc (  ) , _self . get_address (  ) , _self . get_port (
               ))
    }
}
impl <'p> ::std::fmt::Debug for MutableIpDiscoveryPacket<'p> {
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
        let _self = self;
        write!(fmt ,
               "MutableIpDiscoveryPacket {{ pkt_type : {:?}, length : {:?}, ssrc : {:?}, address : {:?}, port : {:?},  }}"
               , _self . get_pkt_type (  ) , _self . get_length (  ) , _self .
               get_ssrc (  ) , _self . get_address (  ) , _self . get_port (
               ))
    }
}
/// Packet format for Discord's
/// [IP Discovery](https://discordapp.com/developers/docs/topics/voice-connections#ip-discovery),
/// used in NAT tunnelling.
///
/// A description of fields:
///
/// ## [`pkt_type`]
/// Denotes whether this packet is a request or response.
///
/// ## [`length`]
/// Length (in bytes) of all successive fields.
/// This controls the string length of [`address`].
///
/// In ordinary use, this should be set to 70.
///
/// ## [`ssrc`]
/// SSRC that the requesting client has been assigned to use over RTP.
///
/// ## [`address`]
/// Null-terminated C-string containing the address of the
/// requester as seen by the server.
///
/// Requests should leave this empty.
///
/// ## [`port`]
/// Client's source port, as seen by the server.
///
/// Requests may include their destination port.
///
/// ## [`payload`]
/// No payload exists for this packet type: 0-length.
///
/// [`pkt_type`]: #structfield.pkt_type
/// [`length`]: #structfield.length
/// [`ssrc`]: #structfield.ssrc
/// [`address`]: #structfield.address
/// [`port`]: #structfield.port
/// [`payload`]: #structfield.payload
#[derive(Clone, Debug)]
#[allow(unused_attributes)]
pub struct IpDiscovery {
    pub pkt_type: IpDiscoveryType,
    pub length: u16be,
    pub ssrc: u32be,
    pub address: Vec<u8>,
    pub port: u16be,
    pub payload: Vec<u8>,
}