fn marshal_to(&self, mut buf: &mut [u8]) -> Result<usize, util::Error> {
        /*
         *  0                   1                   2                   3
         *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * |V=2|P|X|  CC   |M|     PT      |       sequence number         |
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * |                           timestamp                           |
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * |           synchronization source (SSRC) identifier            |
         * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
         * |            contributing source (CSRC) identifiers             |
         * |                             ....                              |
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         */
        let remaining_before = buf.remaining_mut();
        if remaining_before < self.marshal_size() {
            return Err(Error::ErrBufferTooSmall.into());
        }

        // The first byte contains the version, padding bit, extension bit, and csrc size
        let mut b0 = (self.version << VERSION_SHIFT) | self.csrc.len() as u8;
        if self.padding {
            b0 |= 1 << PADDING_SHIFT;
        }

        if self.extension {
            b0 |= 1 << EXTENSION_SHIFT;
        }
        buf.put_u8(b0);

        // The second byte contains the marker bit and payload type.
        let mut b1 = self.payload_type;
        if self.marker {
            b1 |= 1 << MARKER_SHIFT;
        }
        buf.put_u8(b1);

        buf.put_u16(self.sequence_number);
        buf.put_u32(self.timestamp);
        buf.put_u32(self.ssrc);

        for csrc in &self.csrc {
            buf.put_u32(*csrc);
        }

        if self.extension {
            buf.put_u16(self.extension_profile);

            // calculate extensions size and round to 4 bytes boundaries
            let extension_payload_len = self.get_extension_payload_len();
            if self.extension_profile != EXTENSION_PROFILE_ONE_BYTE
                && self.extension_profile != EXTENSION_PROFILE_TWO_BYTE
                && extension_payload_len % 4 != 0
            {
                //the payload must be in 32-bit words.
                return Err(Error::HeaderExtensionPayloadNot32BitWords.into());
            }
            let extension_payload_size = (extension_payload_len as u16 + 3) / 4;
            buf.put_u16(extension_payload_size);

            match self.extension_profile {
                // RFC 8285 RTP One Byte Header Extension
                EXTENSION_PROFILE_ONE_BYTE => {
                    for extension in &self.extensions {
                        buf.put_u8((extension.id << 4) | (extension.payload.len() as u8 - 1));
                        buf.put(&*extension.payload);
                    }
                }
                // RFC 8285 RTP Two Byte Header Extension
                EXTENSION_PROFILE_TWO_BYTE => {
                    for extension in &self.extensions {
                        buf.put_u8(extension.id);
                        buf.put_u8(extension.payload.len() as u8);
                        buf.put(&*extension.payload);
                    }
                }
                // RFC3550 Extension
                _ => {
                    if self.extensions.len() != 1 {
                        return Err(Error::ErrRfc3550headerIdrange.into());
                    }

                    if let Some(extension) = self.extensions.first() {
                        let ext_len = extension.payload.len();
                        if ext_len % 4 != 0 {
                            return Err(Error::HeaderExtensionPayloadNot32BitWords.into());
                        }
                        buf.put(&*extension.payload);
                    }
                }
            };

            // add padding to reach 4 bytes boundaries
            for _ in extension_payload_len..extension_payload_size as usize * 4 {
                buf.put_u8(0);
            }
        }

        let remaining_after = buf.remaining_mut();
        Ok(remaining_before - remaining_after)
    }
/// Marshal serializes the header and writes to the buffer.
Marshal serializes the header and writes to the buffer.
Marshal serializes the header and writes to the buffer .
fn marshal_to(&self, mut buf: &mut [u8]) -> Result<usize, util::Error> {
        /*
         *  0                   1                   2                   3
         *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * |V=2|P|X|  CC   |M|     PT      |       sequence number         |
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * |                           timestamp                           |
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * |           synchronization source (SSRC) identifier            |
         * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
         * |            contributing source (CSRC) identifiers             |
         * |                             ....                              |
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         */
        let remaining_before = buf.remaining_mut();
        if remaining_before < self.marshal_size() {
            return Err(Error::ErrBufferTooSmall.into());
        }
        // The first byte contains the version, padding bit, extension bit, and csrc size
        let mut b0 = (self.version << VERSION_SHIFT) | self.csrc.len() as u8;
        if self.padding {
            b0 |= 1 << PADDING_SHIFT;
        }
        if self.extension {
            b0 |= 1 << EXTENSION_SHIFT;
        }
        buf.put_u8(b0);
        // The second byte contains the marker bit and payload type.
        let mut b1 = self.payload_type;
        if self.marker {
            b1 |= 1 << MARKER_SHIFT;
        }
        buf.put_u8(b1);
        buf.put_u16(self.sequence_number);
        buf.put_u32(self.timestamp);
        buf.put_u32(self.ssrc);
        for csrc in &self.csrc {
            buf.put_u32(*csrc);
        }
        if self.extension {
            buf.put_u16(self.extension_profile);
            // calculate extensions size and round to 4 bytes boundaries
            let extension_payload_len = self.get_extension_payload_len();
            if self.extension_profile != EXTENSION_PROFILE_ONE_BYTE
                && self.extension_profile != EXTENSION_PROFILE_TWO_BYTE
                && extension_payload_len % 4 != 0
            {
                //the payload must be in 32-bit words.
                return Err(Error::HeaderExtensionPayloadNot32BitWords.into());
            }
            let extension_payload_size = (extension_payload_len as u16 + 3) / 4;
            buf.put_u16(extension_payload_size);
            match self.extension_profile {
                // RFC 8285 RTP One Byte Header Extension
                EXTENSION_PROFILE_ONE_BYTE => {
                    for extension in &self.extensions {
                        buf.put_u8((extension.id << 4) | (extension.payload.len() as u8 - 1));
                        buf.put(&*extension.payload);
                    }
                }
                // RFC 8285 RTP Two Byte Header Extension
                EXTENSION_PROFILE_TWO_BYTE => {
                    for extension in &self.extensions {
                        buf.put_u8(extension.id);
                        buf.put_u8(extension.payload.len() as u8);
                        buf.put(&*extension.payload);
                    }
                }
                // RFC3550 Extension
                _ => {
                    if self.extensions.len() != 1 {
                        return Err(Error::ErrRfc3550headerIdrange.into());
                    }
                    if let Some(extension) = self.extensions.first() {
                        let ext_len = extension.payload.len();
                        if ext_len % 4 != 0 {
                            return Err(Error::HeaderExtensionPayloadNot32BitWords.into());
                        }
                        buf.put(&*extension.payload);
                    }
                }
            };
            // add padding to reach 4 bytes boundaries
            for _ in extension_payload_len..extension_payload_size as usize * 4 {
                buf.put_u8(0);
            }
        }
        let remaining_after = buf.remaining_mut();
        Ok(remaining_before - remaining_after)
    }
fn marshal_to ( & self , mut buf : & mut [ u8 ] ) -> Result < usize , util :: Error > { /*
         *  0                   1                   2                   3
         *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * |V=2|P|X|  CC   |M|     PT      |       sequence number         |
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * |                           timestamp                           |
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * |           synchronization source (SSRC) identifier            |
         * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
         * |            contributing source (CSRC) identifiers             |
         * |                             ....                              |
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         */ let remaining_before = buf . remaining_mut ( ) ; if remaining_before < self . marshal_size ( ) { return Err ( Error :: ErrBufferTooSmall . into ( ) ) ; } // The first byte contains the version, padding bit, extension bit, and csrc size let mut b0 = ( self . version << VERSION_SHIFT ) | self . csrc . len ( ) as u8 ; if self . padding { b0 |= 1 << PADDING_SHIFT ; } if self . extension { b0 |= 1 << EXTENSION_SHIFT ; } buf . put_u8 ( b0 ) ; // The second byte contains the marker bit and payload type. let mut b1 = self . payload_type ; if self . marker { b1 |= 1 << MARKER_SHIFT ; } buf . put_u8 ( b1 ) ; buf . put_u16 ( self . sequence_number ) ; buf . put_u32 ( self . timestamp ) ; buf . put_u32 ( self . ssrc ) ; for csrc in & self . csrc { buf . put_u32 ( * csrc ) ; } if self . extension { buf . put_u16 ( self . extension_profile ) ; // calculate extensions size and round to 4 bytes boundaries let extension_payload_len = self . get_extension_payload_len ( ) ; if self . extension_profile != EXTENSION_PROFILE_ONE_BYTE && self . extension_profile != EXTENSION_PROFILE_TWO_BYTE && extension_payload_len % 4 != 0 { //the payload must be in 32-bit words. return Err ( Error :: HeaderExtensionPayloadNot32BitWords . into ( ) ) ; } let extension_payload_size = ( extension_payload_len as u16 + 3 ) / 4 ; buf . put_u16 ( extension_payload_size ) ; match self . extension_profile { // RFC 8285 RTP One Byte Header Extension EXTENSION_PROFILE_ONE_BYTE => { for extension in & self . extensions { buf . put_u8 ( ( extension . id << 4 ) | ( extension . payload . len ( ) as u8 - 1 ) ) ; buf . put ( & * extension . payload ) ; } } // RFC 8285 RTP Two Byte Header Extension EXTENSION_PROFILE_TWO_BYTE => { for extension in & self . extensions { buf . put_u8 ( extension . id ) ; buf . put_u8 ( extension . payload . len ( ) as u8 ) ; buf . put ( & * extension . payload ) ; } } // RFC3550 Extension _ => { if self . extensions . len ( ) != 1 { return Err ( Error :: ErrRfc3550headerIdrange . into ( ) ) ; } if let Some ( extension ) = self . extensions . first ( ) { let ext_len = extension . payload . len ( ) ; if ext_len % 4 != 0 { return Err ( Error :: HeaderExtensionPayloadNot32BitWords . into ( ) ) ; } buf . put ( & * extension . payload ) ; } } } ; // add padding to reach 4 bytes boundaries for _ in extension_payload_len .. extension_payload_size as usize * 4 { buf . put_u8 ( 0 ) ; } } let remaining_after = buf . remaining_mut ( ) ; Ok ( remaining_before - remaining_after ) }
Marshal serializes the header and writes to the buffer.
Marshal serializes the header and writes to the buffer .
&self
buf
&mut [u8]