parsers/hdrext: Parse the @id as u16 instead of String

The specification says it can only be in the 1-256, 4096-4351 ranges, so
use the closest type available.  This doesn’t validate that the value is
correct, but that will be done in a future commit.

Thanks gst-meet for making me notice this issue!
This commit is contained in:
Emmanuel Gil Peyrot 2021-10-23 12:24:32 +02:00
parent 3a6cd23166
commit 7bdf7656eb

View file

@ -22,8 +22,10 @@ generate_element!(
/// Header extensions to be used in a RTP description. /// Header extensions to be used in a RTP description.
RtpHdrext, "rtp-hdrext", JINGLE_RTP_HDREXT, RtpHdrext, "rtp-hdrext", JINGLE_RTP_HDREXT,
attributes: [ attributes: [
/// The ID of the extensions. /// The ID of the extensions. The allowed values are only in the 1-256, 4096-4351 ranges,
id: Required<String> = "id", /// this isnt enforced by xmpp-parsers yet!
// TODO: make it so.
id: Required<u16> = "id",
/// The URI that defines the extension. /// The URI that defines the extension.
uri: Required<String> = "uri", uri: Required<String> = "uri",
@ -35,7 +37,7 @@ generate_element!(
impl RtpHdrext { impl RtpHdrext {
/// Create a new RTP header extension element. /// Create a new RTP header extension element.
pub fn new(id: String, uri: String) -> RtpHdrext { pub fn new(id: u16, uri: String) -> RtpHdrext {
RtpHdrext { RtpHdrext {
id, id,
uri, uri,
@ -60,14 +62,14 @@ mod tests {
#[test] #[test]
fn test_size() { fn test_size() {
assert_size!(Senders, 1); assert_size!(Senders, 1);
assert_size!(RtpHdrext, 28); assert_size!(RtpHdrext, 16);
} }
#[cfg(target_pointer_width = "64")] #[cfg(target_pointer_width = "64")]
#[test] #[test]
fn test_size() { fn test_size() {
assert_size!(Senders, 1); assert_size!(Senders, 1);
assert_size!(RtpHdrext, 56); assert_size!(RtpHdrext, 32);
} }
#[test] #[test]
@ -79,7 +81,7 @@ mod tests {
.parse() .parse()
.unwrap(); .unwrap();
let rtp_hdrext = RtpHdrext::try_from(elem).unwrap(); let rtp_hdrext = RtpHdrext::try_from(elem).unwrap();
assert_eq!(rtp_hdrext.id, "1"); assert_eq!(rtp_hdrext.id, 1);
assert_eq!(rtp_hdrext.uri, "urn:ietf:params:rtp-hdrext:toffset"); assert_eq!(rtp_hdrext.uri, "urn:ietf:params:rtp-hdrext:toffset");
assert_eq!(rtp_hdrext.senders, Senders::Both); assert_eq!(rtp_hdrext.senders, Senders::Both);
} }