特殊格式報文的實現

來源:互聯網
上載者:User

    The RTP header has the following format:

    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             |
   |                             ....                              |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

 

從上面的顯示中我們可以看到rtp包在網路上傳送時的位元組序。那在程式中怎麼寫呢?

來看一下人家寫好的代碼就知道了。

 

        struct RTPFixedHeader
        {
#if     __BYTE_ORDER == __BIG_ENDIAN
                /// For big endian boxes
                unsigned char version:2;       ///< Version, currently 2
                unsigned char padding:1;       ///< Padding bit
                unsigned char extension:1;     ///< Extension bit
                unsigned char cc:4;            ///< CSRC count
                unsigned char marker:1;        ///< Marker bit
                unsigned char payload:7;       ///< Payload type
#else
                /// For little endian boxes
                unsigned char cc:4;            ///< CSRC count
                unsigned char extension:1;     ///< Extension bit
                unsigned char padding:1;       ///< Padding bit
                unsigned char version:2;       ///< Version, currently 2
                unsigned char payload:7;       ///< Payload type
                unsigned char marker:1;        ///< Marker bit
#endif
                uint16 sequence;        ///< sequence number
                uint32 timestamp;       ///< timestamp
                uint32 sources[1];      ///< contributing sources
        };

 

怎麼樣,明白了吧。

以後要發格式特殊的報文的時候就這樣寫,就ok了。

 

而且重要的一點,這個順序是以位元組為單位的。 也就是以位元組為單位的話,順序是不變的,都是由低到高。但是在一個位元組內,要進行區分的話,根據大小位元組序來調整。

 

貌似這個和我們平時見的整型數值,表達有點不一樣。 整型的話,是以位元組為單位。

在小子節序時, 低位元組在低位。

在大位元組序時, 高位元組在低位。

 

 

類似的表達方式,還有種更牛的。。。。 我服了

typedef struct {
    uint8
    Wlan_WpaAKm_None:1,
    Wlan_WpaAKm_Unspecified:1,
    Wlan_WpaAKm_Psk:1,
    reserved:3,
    Wlan_Wpa2AKm_Unspecified:1,
    Wlan_Wpa2AKm_Psk:1;
} Wlan_WpaAKmBit;

 

用逗號分隔,牛的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.