MCPcopy Create free account
hub / github.com/pion/rtcp / Marshal

Method Marshal

source_description.go:85–128  ·  view source on GitHub ↗

Marshal encodes the SourceDescription in binary.

()

Source from the content-addressed store, hash-verified

83
84// Marshal encodes the SourceDescription in binary.
85func (s SourceDescription) Marshal() ([]byte, error) {
86 /*
87 * 0 1 2 3
88 * 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
89 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
90 * header |V=2|P| SC | PT=SDES=202 | length |
91 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
92 * chunk | SSRC/CSRC_1 |
93 * 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
94 * | SDES items |
95 * | ... |
96 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
97 * chunk | SSRC/CSRC_2 |
98 * 2 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
99 * | SDES items |
100 * | ... |
101 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
102 */
103
104 rawPacket := make([]byte, s.MarshalSize())
105 packetBody := rawPacket[headerLength:]
106
107 chunkOffset := 0
108 for _, c := range s.Chunks {
109 data, err := c.Marshal()
110 if err != nil {
111 return nil, err
112 }
113 copy(packetBody[chunkOffset:], data)
114 chunkOffset += len(data)
115 }
116
117 if len(s.Chunks) > countMax {
118 return nil, errTooManyChunks
119 }
120
121 hData, err := s.Header().Marshal()
122 if err != nil {
123 return nil, err
124 }
125 copy(rawPacket, hData)
126
127 return rawPacket, nil
128}
129
130// Unmarshal decodes the SourceDescription from binary.
131func (s *SourceDescription) Unmarshal(rawPacket []byte) error {

Calls 3

MarshalSizeMethod · 0.95
HeaderMethod · 0.95
MarshalMethod · 0.65

Tested by 1