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
use pnet_macros_support::types::*;
use std::num::Wrapping;







#[derive(PartialEq)]
/// A structure enabling manipulation of on the wire packets
pub struct RtcpPacket<'p> {
    packet: ::pnet_macros_support::packet::PacketData<'p>,
}
#[derive(PartialEq)]
/// A structure enabling manipulation of on the wire packets
pub struct MutableRtcpPacket<'p> {
    packet: ::pnet_macros_support::packet::MutPacketData<'p>,
}
impl <'a> RtcpPacket<'a> {
    /// Constructs a new RtcpPacket. 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<RtcpPacket<'p>> {
        if packet.len() >= RtcpPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::PacketData;
            Some(RtcpPacket{packet: PacketData::Borrowed(packet),})
        } else { None }
    }
    /// Constructs a new RtcpPacket. If the provided buffer is less than the minimum required
    /// packet size, this will return None. With this constructor the RtcpPacket will
    /// own its own data and the underlying buffer will be dropped when the RtcpPacket is.
    pub fn owned(packet: Vec<u8>) -> Option<RtcpPacket<'static>> {
        if packet.len() >= RtcpPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::PacketData;
            Some(RtcpPacket{packet: PacketData::Owned(packet),})
        } else { None }
    }
    /// Maps from a RtcpPacket to a RtcpPacket
    #[inline]
    pub fn to_immutable<'p>(&'p self) -> RtcpPacket<'p> {
        use ::pnet_macros_support::packet::PacketData;
        RtcpPacket{packet: PacketData::Borrowed(self.packet.as_slice()),}
    }
    /// Maps from a RtcpPacket to a RtcpPacket while consuming the source
    #[inline]
    pub fn consume_to_immutable(self) -> RtcpPacket<'a> {
        RtcpPacket{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 { 8 }
    /// The size (in bytes) of a Rtcp instance when converted into
    /// a byte-array
    #[inline]
    pub fn packet_size(_packet: &Rtcp) -> usize { 8 + _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 rx_report_count field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_rx_report_count(&self) -> u5 {
        let _self = self;
        let co = 0;
        ((_self.packet[co] as u5) & 31)
    }
    /// Get the value of the packet_type field
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_packet_type(&self) -> RtcpType {
        #[inline(always)]
        #[allow(trivial_numeric_casts, unused_parens)]
        #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
        fn get_arg0(_self: &RtcpPacket) -> u8 {
            let co = 1;
            (_self.packet[co] as u8)
        }
        RtcpType::new(get_arg0(&self))
    }
    /// Get the pkt_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_pkt_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
    }
}
impl <'a> MutableRtcpPacket<'a> {
    /// Constructs a new MutableRtcpPacket. 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<MutableRtcpPacket<'p>> {
        if packet.len() >= MutableRtcpPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::MutPacketData;
            Some(MutableRtcpPacket{packet: MutPacketData::Borrowed(packet),})
        } else { None }
    }
    /// Constructs a new MutableRtcpPacket. If the provided buffer is less than the minimum required
    /// packet size, this will return None. With this constructor the MutableRtcpPacket will
    /// own its own data and the underlying buffer will be dropped when the MutableRtcpPacket is.
    pub fn owned(packet: Vec<u8>) -> Option<MutableRtcpPacket<'static>> {
        if packet.len() >= MutableRtcpPacket::minimum_packet_size() {
            use ::pnet_macros_support::packet::MutPacketData;
            Some(MutableRtcpPacket{packet: MutPacketData::Owned(packet),})
        } else { None }
    }
    /// Maps from a MutableRtcpPacket to a RtcpPacket
    #[inline]
    pub fn to_immutable<'p>(&'p self) -> RtcpPacket<'p> {
        use ::pnet_macros_support::packet::PacketData;
        RtcpPacket{packet: PacketData::Borrowed(self.packet.as_slice()),}
    }
    /// Maps from a MutableRtcpPacket to a RtcpPacket while consuming the source
    #[inline]
    pub fn consume_to_immutable(self) -> RtcpPacket<'a> {
        RtcpPacket{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 { 8 }
    /// The size (in bytes) of a Rtcp instance when converted into
    /// a byte-array
    #[inline]
    pub fn packet_size(_packet: &Rtcp) -> usize { 8 + _packet.payload.len() }
    /// Populates a RtcpPacket using a Rtcp structure
    #[inline]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn populate(&mut self, packet: &Rtcp) {
        let _self = self;
        _self.set_version(packet.version);
        _self.set_padding(packet.padding);
        _self.set_rx_report_count(packet.rx_report_count);
        _self.set_packet_type(packet.packet_type);
        _self.set_pkt_length(packet.pkt_length);
        _self.set_ssrc(packet.ssrc);
        _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 rx_report_count field.
    #[inline]
    #[allow(trivial_numeric_casts, unused_parens)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_rx_report_count(&self) -> u5 {
        let _self = self;
        let co = 0;
        ((_self.packet[co] as u5) & 31)
    }
    /// Get the value of the packet_type field
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn get_packet_type(&self) -> RtcpType {
        #[inline(always)]
        #[allow(trivial_numeric_casts, unused_parens)]
        #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
        fn get_arg0(_self: &MutableRtcpPacket) -> u8 {
            let co = 1;
            (_self.packet[co] as u8)
        }
        RtcpType::new(get_arg0(&self))
    }
    /// Get the pkt_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_pkt_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
    }
    /// 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 rx_report_count field.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_rx_report_count(&mut self, val: u5) {
        let _self = self;
        let co = 0;
        _self.packet[co + 0] =
            ((_self.packet[co + 0] & 224) | (((val & 31)) as u8)) as u8;
    }
    /// Set the value of the packet_type field.
    #[inline]
    #[allow(trivial_numeric_casts)]
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    pub fn set_packet_type(&mut self, val: RtcpType) {
        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 MutableRtcpPacket, val: u8) {
            let co = 1;
            _self.packet[co + 0] = (val) as u8;
        }
        let vals = val.to_primitive_values();
        set_arg0(_self, vals.0);
    }
    /// Set the pkt_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_pkt_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;
    }
    /// 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 = 8;
        unsafe {
            copy_nonoverlapping(vals[..].as_ptr(),
                                _self.packet[current_offset..].as_mut_ptr(),
                                vals.len())
        }
    }
}
impl <'a> ::pnet_macros_support::packet::PacketSize for RtcpPacket<'a> {
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    fn packet_size(&self) -> usize { let _self = self; 8 }
}
impl <'a> ::pnet_macros_support::packet::PacketSize for MutableRtcpPacket<'a>
 {
    #[cfg_attr(feature = "clippy", allow(used_underscore_binding))]
    fn packet_size(&self) -> usize { let _self = self; 8 }
}
impl <'a> ::pnet_macros_support::packet::MutablePacket for
 MutableRtcpPacket<'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 = 8;
        if _self.packet.len() <= start { return &mut []; }
        &mut _self.packet[start..]
    }
}
impl <'a> ::pnet_macros_support::packet::Packet for MutableRtcpPacket<'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 = 8;
        if _self.packet.len() <= start { return &[]; }
        &_self.packet[start..]
    }
}
impl <'a> ::pnet_macros_support::packet::Packet for RtcpPacket<'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 = 8;
        if _self.packet.len() <= start { return &[]; }
        &_self.packet[start..]
    }
}
/// Used to iterate over a slice of `RtcpPacket`s
pub struct RtcpIterable<'a> {
    buf: &'a [u8],
}
impl <'a> Iterator for RtcpIterable<'a> {
    type
    Item
    =
    RtcpPacket<'a>;
    fn next(&mut self) -> Option<RtcpPacket<'a>> {
        use pnet_macros_support::packet::PacketSize;
        use std::cmp::min;
        if self.buf.len() > 0 {
            if let Some(ret) = RtcpPacket::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 RtcpPacket<'p> {
    type
    T
    =
    Rtcp;
    #[inline]
    fn from_packet(&self) -> Rtcp {
        use pnet_macros_support::packet::Packet;
        let _self = self;
        Rtcp{version: _self.get_version(),
             padding: _self.get_padding(),
             rx_report_count: _self.get_rx_report_count(),
             packet_type: _self.get_packet_type(),
             pkt_length: _self.get_pkt_length(),
             ssrc: _self.get_ssrc(),
             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 MutableRtcpPacket<'p>
 {
    type
    T
    =
    Rtcp;
    #[inline]
    fn from_packet(&self) -> Rtcp {
        use pnet_macros_support::packet::Packet;
        let _self = self;
        Rtcp{version: _self.get_version(),
             padding: _self.get_padding(),
             rx_report_count: _self.get_rx_report_count(),
             packet_type: _self.get_packet_type(),
             pkt_length: _self.get_pkt_length(),
             ssrc: _self.get_ssrc(),
             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 RtcpPacket<'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 ,
               "RtcpPacket {{ version : {:?}, padding : {:?}, rx_report_count : {:?}, packet_type : {:?}, pkt_length : {:?}, ssrc : {:?},  }}"
               , _self . get_version (  ) , _self . get_padding (  ) , _self .
               get_rx_report_count (  ) , _self . get_packet_type (  ) , _self
               . get_pkt_length (  ) , _self . get_ssrc (  ))
    }
}
impl <'p> ::std::fmt::Debug for MutableRtcpPacket<'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 ,
               "MutableRtcpPacket {{ version : {:?}, padding : {:?}, rx_report_count : {:?}, packet_type : {:?}, pkt_length : {:?}, ssrc : {:?},  }}"
               , _self . get_version (  ) , _self . get_padding (  ) , _self .
               get_rx_report_count (  ) , _self . get_packet_type (  ) , _self
               . get_pkt_length (  ) , _self . get_ssrc (  ))
    }
}
/// Packet header for the [RTP Control Protocol](https://tools.ietf.org/html/rfc3550#section-6).
///
/// This is a test description. [RFC](https://tools.ietf.org/html/rfc3550#section-6)
#[derive(Clone, Debug)]
#[allow(unused_attributes)]
pub struct Rtcp {
    pub version: u2,
    pub padding: u1,
    pub rx_report_count: u5,
    pub packet_type: RtcpType,
    pub pkt_length: u16be,
    pub ssrc: u32be,
    pub payload: Vec<u8>,
}