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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
use pnet_macros_support::types::*;
use std::num::Wrapping;











#[derive(PartialEq)]
/// A structure enabling manipulation of on the wire packets
pub struct RtpPacket<'p> {
    packet: ::pnet_macros_support::packet::PacketData<'p>,
}
#[derive(PartialEq)]
/// A structure enabling manipulation of on the wire packets
pub struct MutableRtpPacket<'p> {
    packet: ::pnet_macros_support::packet::MutPacketData<'p>,
}
impl <'a> RtpPacket<'a> {
    /// Constructs a new RtpPacket. 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<RtpPacket<'p>> {
        if packet.len() >= RtpPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::PacketData;
            Some(RtpPacket{packet: PacketData::Borrowed(packet),})
        } else { None }
    }
    /// Constructs a new RtpPacket. If the provided buffer is less than the minimum required
    /// packet size, this will return None. With this constructor the RtpPacket will
    /// own its own data and the underlying buffer will be dropped when the RtpPacket is.
    pub fn owned(packet: Vec<u8>) -> Option<RtpPacket<'static>> {
        if packet.len() >= RtpPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::PacketData;
            Some(RtpPacket{packet: PacketData::Owned(packet),})
        } else { None }
    }
    /// Maps from a RtpPacket to a RtpPacket
    #[inline]
    pub fn to_immutable<'p>(&'p self) -> RtpPacket<'p> {
        use ::pnet_macros_support::packet::PacketData;
        RtpPacket{packet: PacketData::Borrowed(self.packet.as_slice()),}
    }
    /// Maps from a RtpPacket to a RtpPacket while consuming the source
    #[inline]
    pub fn consume_to_immutable(self) -> RtpPacket<'a> {
        RtpPacket{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 { 12 }
    /// The size (in bytes) of a Rtp instance when converted into
    /// a byte-array
    #[inline]
    pub fn packet_size(_packet: &Rtp) -> usize {
        12 + _packet.csrc_list.len() + _packet.payload.len()
    }
    /// Get the version field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_version(&self) -> u2 {
        let _self = self;
        let co = 0;
        ((_self.packet[co] as u2) & 192) >> 6
    }
    /// Get the padding field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_padding(&self) -> u1 {
        let _self = self;
        let co = 0;
        ((_self.packet[co] as u1) & 32) >> 5
    }
    /// Get the extension field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_extension(&self) -> u1 {
        let _self = self;
        let co = 0;
        ((_self.packet[co] as u1) & 16) >> 4
    }
    /// Get the csrc_count field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_csrc_count(&self) -> u4 {
        let _self = self;
        let co = 0;
        ((_self.packet[co] as u4) & 15)
    }
    /// Get the marker field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_marker(&self) -> u1 {
        let _self = self;
        let co = 1;
        ((_self.packet[co] as u1) & 128) >> 7
    }
    /// Get the value of the payload_type field
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_payload_type(&self) -> RtpType {
        #[inline(always)]
        #[allow(trivial_numeric_casts, unused_parens)]
        #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
        fn get_arg0(_self: &RtpPacket) -> u7 {
            let co = 1;
            ((_self.packet[co] as u7) & 127)
        }
        RtpType::new(get_arg0(&self))
    }
    /// Get the sequence 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_sequence(&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 timestamp 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_timestamp(&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 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 = 8;
        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 csrc_list field, without copying
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_csrc_list_raw(&self) -> &[u8] {
        use std::cmp::min;
        let _self = self;
        let current_offset = 12;
        let end =
            min(current_offset + (_self.get_csrc_count() as usize),
                _self.packet.len());
        &_self.packet[current_offset..end]
    }
    /// Get the value of the csrc_list field (copies contents)
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_csrc_list(&self) -> Vec<u32be> {
        use std::cmp::min;
        let _self = self;
        let current_offset = 12;
        let pkt_len = self.packet.len();
        let end =
            min(current_offset + (_self.get_csrc_count() as usize), pkt_len);
        let packet = &_self.packet[current_offset..end];
        let mut vec: Vec<u32be> = Vec::with_capacity(packet.len());
        let mut co = 0;
        for _ in 0..vec.capacity() {
            vec.push({
                         let b0 = ((packet[co + 0] as u32be) << 24) as u32be;
                         let b1 = ((packet[co + 1] as u32be) << 16) as u32be;
                         let b2 = ((packet[co + 2] as u32be) << 8) as u32be;
                         let b3 = ((packet[co + 3] as u32be)) as u32be;
                         b0 | b1 | b2 | b3
                     });
            co += 4;
        }
        vec
    }
}
impl <'a> MutableRtpPacket<'a> {
    /// Constructs a new MutableRtpPacket. 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<MutableRtpPacket<'p>> {
        if packet.len() >= MutableRtpPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::MutPacketData;
            Some(MutableRtpPacket{packet: MutPacketData::Borrowed(packet),})
        } else { None }
    }
    /// Constructs a new MutableRtpPacket. If the provided buffer is less than the minimum required
    /// packet size, this will return None. With this constructor the MutableRtpPacket will
    /// own its own data and the underlying buffer will be dropped when the MutableRtpPacket is.
    pub fn owned(packet: Vec<u8>) -> Option<MutableRtpPacket<'static>> {
        if packet.len() >= MutableRtpPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::MutPacketData;
            Some(MutableRtpPacket{packet: MutPacketData::Owned(packet),})
        } else { None }
    }
    /// Maps from a MutableRtpPacket to a RtpPacket
    #[inline]
    pub fn to_immutable<'p>(&'p self) -> RtpPacket<'p> {
        use ::pnet_macros_support::packet::PacketData;
        RtpPacket{packet: PacketData::Borrowed(self.packet.as_slice()),}
    }
    /// Maps from a MutableRtpPacket to a RtpPacket while consuming the source
    #[inline]
    pub fn consume_to_immutable(self) -> RtpPacket<'a> {
        RtpPacket{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 { 12 }
    /// The size (in bytes) of a Rtp instance when converted into
    /// a byte-array
    #[inline]
    pub fn packet_size(_packet: &Rtp) -> usize {
        12 + _packet.csrc_list.len() + _packet.payload.len()
    }
    /// Populates a RtpPacket using a Rtp structure
    #[inline]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn populate(&mut self, packet: &Rtp) {
        let _self = self;
        _self.set_version(packet.version);
        _self.set_padding(packet.padding);
        _self.set_extension(packet.extension);
        _self.set_csrc_count(packet.csrc_count);
        _self.set_marker(packet.marker);
        _self.set_payload_type(packet.payload_type);
        _self.set_sequence(packet.sequence);
        _self.set_timestamp(packet.timestamp);
        _self.set_ssrc(packet.ssrc);
        _self.set_csrc_list(&packet.csrc_list);
        _self.set_payload(&packet.payload);
    }
    /// Get the version field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_version(&self) -> u2 {
        let _self = self;
        let co = 0;
        ((_self.packet[co] as u2) & 192) >> 6
    }
    /// Get the padding field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_padding(&self) -> u1 {
        let _self = self;
        let co = 0;
        ((_self.packet[co] as u1) & 32) >> 5
    }
    /// Get the extension field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_extension(&self) -> u1 {
        let _self = self;
        let co = 0;
        ((_self.packet[co] as u1) & 16) >> 4
    }
    /// Get the csrc_count field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_csrc_count(&self) -> u4 {
        let _self = self;
        let co = 0;
        ((_self.packet[co] as u4) & 15)
    }
    /// Get the marker field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_marker(&self) -> u1 {
        let _self = self;
        let co = 1;
        ((_self.packet[co] as u1) & 128) >> 7
    }
    /// Get the value of the payload_type field
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_payload_type(&self) -> RtpType {
        #[inline(always)]
        #[allow(trivial_numeric_casts, unused_parens)]
        #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
        fn get_arg0(_self: &MutableRtpPacket) -> u7 {
            let co = 1;
            ((_self.packet[co] as u7) & 127)
        }
        RtpType::new(get_arg0(&self))
    }
    /// Get the sequence 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_sequence(&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 timestamp 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_timestamp(&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 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 = 8;
        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 csrc_list field, without copying
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_csrc_list_raw(&self) -> &[u8] {
        use std::cmp::min;
        let _self = self;
        let current_offset = 12;
        let end =
            min(current_offset + (_self.get_csrc_count() as usize),
                _self.packet.len());
        &_self.packet[current_offset..end]
    }
    /// Get the value of the csrc_list field (copies contents)
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_csrc_list(&self) -> Vec<u32be> {
        use std::cmp::min;
        let _self = self;
        let current_offset = 12;
        let pkt_len = self.packet.len();
        let end =
            min(current_offset + (_self.get_csrc_count() as usize), pkt_len);
        let packet = &_self.packet[current_offset..end];
        let mut vec: Vec<u32be> = Vec::with_capacity(packet.len());
        let mut co = 0;
        for _ in 0..vec.capacity() {
            vec.push({
                         let b0 = ((packet[co + 0] as u32be) << 24) as u32be;
                         let b1 = ((packet[co + 1] as u32be) << 16) as u32be;
                         let b2 = ((packet[co + 2] as u32be) << 8) as u32be;
                         let b3 = ((packet[co + 3] as u32be)) as u32be;
                         b0 | b1 | b2 | b3
                     });
            co += 4;
        }
        vec
    }
    /// Set the version field.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_version(&mut self, val: u2) {
        let _self = self;
        let co = 0;
        _self.packet[co + 0] =
            ((_self.packet[co + 0] & 63) | (((val & 3) << 6) as u8)) as u8;
    }
    /// Set the padding field.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_padding(&mut self, val: u1) {
        let _self = self;
        let co = 0;
        _self.packet[co + 0] =
            ((_self.packet[co + 0] & 223) | (((val & 1) << 5) as u8)) as u8;
    }
    /// Set the extension field.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_extension(&mut self, val: u1) {
        let _self = self;
        let co = 0;
        _self.packet[co + 0] =
            ((_self.packet[co + 0] & 239) | (((val & 1) << 4) as u8)) as u8;
    }
    /// Set the csrc_count field.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_csrc_count(&mut self, val: u4) {
        let _self = self;
        let co = 0;
        _self.packet[co + 0] =
            ((_self.packet[co + 0] & 240) | (((val & 15)) as u8)) as u8;
    }
    /// Set the marker field.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_marker(&mut self, val: u1) {
        let _self = self;
        let co = 1;
        _self.packet[co + 0] =
            ((_self.packet[co + 0] & 127) | (((val & 1) << 7) as u8)) as u8;
    }
    /// Set the value of the payload_type field.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_payload_type(&mut self, val: RtpType) {
        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 MutableRtpPacket, val: u7) {
            let co = 1;
            _self.packet[co + 0] =
                ((_self.packet[co + 0] & 128) | (((val & 127)) as u8)) as u8;
        }
        let vals = val.to_primitive_values();
        set_arg0(_self, vals.0);
    }
    /// Set the sequence 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_sequence(&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 timestamp 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_timestamp(&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;
    }
    /// 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 = 8;
        _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 csrc_list field, without copying
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_csrc_list_raw_mut(&mut self) -> &mut [u8] {
        use std::cmp::min;
        let _self = self;
        let current_offset = 12;
        let end =
            min(current_offset + (_self.get_csrc_count() as usize),
                _self.packet.len());
        &mut _self.packet[current_offset..end]
    }
    /// Set the value of the csrc_list field (copies contents)
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_csrc_list(&mut self, vals: &[u32be]) {
        use std::ptr::copy_nonoverlapping;
        let mut _self = self;
        let current_offset = 12;
        let len = _self.get_csrc_count() as usize;
        assert!(vals . len (  ) <= len);
        let mut co = current_offset;
        for i in 0..vals.len() {
            let val = vals[i];
            _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;
            co += 4;
        }
    }
    /// 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 = 12 + (_self.get_csrc_count() as usize);
        unsafe {
            copy_nonoverlapping(vals[..].as_ptr(),
                                _self.packet[current_offset..].as_mut_ptr(),
                                vals.len())
        }
    }
}
impl <'a> ::pnet_macros_support::packet::PacketSize for RtpPacket<'a> {
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    fn packet_size(&self) -> usize {
        let _self = self;
        12 + (_self.get_csrc_count() as usize)
    }
}
impl <'a> ::pnet_macros_support::packet::PacketSize for MutableRtpPacket<'a> {
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    fn packet_size(&self) -> usize {
        let _self = self;
        12 + (_self.get_csrc_count() as usize)
    }
}
impl <'a> ::pnet_macros_support::packet::MutablePacket for
 MutableRtpPacket<'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 = 12 + (_self.get_csrc_count() as usize);
        if _self.packet.len() <= start { return &mut []; }
        &mut _self.packet[start..]
    }
}
impl <'a> ::pnet_macros_support::packet::Packet for MutableRtpPacket<'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 = 12 + (_self.get_csrc_count() as usize);
        if _self.packet.len() <= start { return &[]; }
        &_self.packet[start..]
    }
}
impl <'a> ::pnet_macros_support::packet::Packet for RtpPacket<'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 = 12 + (_self.get_csrc_count() as usize);
        if _self.packet.len() <= start { return &[]; }
        &_self.packet[start..]
    }
}
/// Used to iterate over a slice of `RtpPacket`s
pub struct RtpIterable<'a> {
    buf: &'a [u8],
}
impl <'a> Iterator for RtpIterable<'a> {
    type
    Item
    =
    RtpPacket<'a>;
    fn next(&mut self) -> Option<RtpPacket<'a>> {
        use pnet_macros_support::packet::PacketSize;
        use std::cmp::min;
        if self.buf.len() > 0 {
            if let Some(ret) = RtpPacket::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 RtpPacket<'p> {
    type
    T
    =
    Rtp;
    #[inline]
    fn from_packet(&self) -> Rtp {
        use pnet_macros_support::packet::Packet;
        let _self = self;
        Rtp{version: _self.get_version(),
            padding: _self.get_padding(),
            extension: _self.get_extension(),
            csrc_count: _self.get_csrc_count(),
            marker: _self.get_marker(),
            payload_type: _self.get_payload_type(),
            sequence: _self.get_sequence(),
            timestamp: _self.get_timestamp(),
            ssrc: _self.get_ssrc(),
            csrc_list: _self.get_csrc_list(),
            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 MutableRtpPacket<'p> {
    type
    T
    =
    Rtp;
    #[inline]
    fn from_packet(&self) -> Rtp {
        use pnet_macros_support::packet::Packet;
        let _self = self;
        Rtp{version: _self.get_version(),
            padding: _self.get_padding(),
            extension: _self.get_extension(),
            csrc_count: _self.get_csrc_count(),
            marker: _self.get_marker(),
            payload_type: _self.get_payload_type(),
            sequence: _self.get_sequence(),
            timestamp: _self.get_timestamp(),
            ssrc: _self.get_ssrc(),
            csrc_list: _self.get_csrc_list(),
            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 RtpPacket<'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 ,
               "RtpPacket {{ version : {:?}, padding : {:?}, extension : {:?}, csrc_count : {:?}, marker : {:?}, payload_type : {:?}, sequence : {:?}, timestamp : {:?}, ssrc : {:?}, csrc_list : {:?},  }}"
               , _self . get_version (  ) , _self . get_padding (  ) , _self .
               get_extension (  ) , _self . get_csrc_count (  ) , _self .
               get_marker (  ) , _self . get_payload_type (  ) , _self .
               get_sequence (  ) , _self . get_timestamp (  ) , _self .
               get_ssrc (  ) , _self . get_csrc_list (  ))
    }
}
impl <'p> ::std::fmt::Debug for MutableRtpPacket<'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 ,
               "MutableRtpPacket {{ version : {:?}, padding : {:?}, extension : {:?}, csrc_count : {:?}, marker : {:?}, payload_type : {:?}, sequence : {:?}, timestamp : {:?}, ssrc : {:?}, csrc_list : {:?},  }}"
               , _self . get_version (  ) , _self . get_padding (  ) , _self .
               get_extension (  ) , _self . get_csrc_count (  ) , _self .
               get_marker (  ) , _self . get_payload_type (  ) , _self .
               get_sequence (  ) , _self . get_timestamp (  ) , _self .
               get_ssrc (  ) , _self . get_csrc_list (  ))
    }
}
/// Packet header for the [Real-time Transport Protocol](https://tools.ietf.org/html/rfc3550).
///
/// This is a test description.
#[derive(Clone, Debug)]
#[allow(unused_attributes)]
pub struct Rtp {
    pub version: u2,
    pub padding: u1,
    pub extension: u1,
    pub csrc_count: u4,
    pub marker: u1,
    pub payload_type: RtpType,
    pub sequence: u16be,
    pub timestamp: u32be,
    pub ssrc: u32be,
    pub csrc_list: Vec<u32be>,
    payload: Vec<u8>,
}