Skip to content

Commit

Permalink
Renamed Len to MarshalSize for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
asnyatkov committed Dec 8, 2023
1 parent f25e8b9 commit 4bef349
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 52 deletions.
6 changes: 3 additions & 3 deletions compound_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ func (c CompoundPacket) Marshal() ([]byte, error) {
return Marshal(p)
}

// Len returns the length of the CompoundPacket when encoded as binary.
func (c CompoundPacket) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (c CompoundPacket) MarshalSize() int {
l := 0
for _, p := range c {
l += p.Len()
l += p.MarshalSize()
}
return l
}
Expand Down
4 changes: 2 additions & 2 deletions extended_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ func (b *UnknownReportBlock) setupBlockHeader() {
func (b *UnknownReportBlock) unpackBlockHeader() {
}

// Len returns the length of the ExtendedReport when encoded as binary.
func (x ExtendedReport) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (x ExtendedReport) MarshalSize() int {
return wireSize(x)
}

Expand Down
6 changes: 3 additions & 3 deletions full_intra_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ func (p *FullIntraRequest) Header() Header {
return Header{
Count: FormatFIR,
Type: TypePayloadSpecificFeedback,
Length: uint16((p.Len() / 4) - 1),
Length: uint16((p.MarshalSize() / 4) - 1),
}
}

// Len returns the length of the FullIntraRequest when encoded as binary.
func (p *FullIntraRequest) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (p *FullIntraRequest) MarshalSize() int {
return headerLength + firOffset + len(p.FIR)*8
}

Expand Down
8 changes: 4 additions & 4 deletions goodbye.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (g Goodbye) Marshal() ([]byte, error) {
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/

rawPacket := make([]byte, g.Len())
rawPacket := make([]byte, g.MarshalSize())
packetBody := rawPacket[headerLength:]

if len(g.Sources) > countMax {
Expand Down Expand Up @@ -126,12 +126,12 @@ func (g *Goodbye) Header() Header {
Padding: false,
Count: uint8(len(g.Sources)),
Type: TypeGoodbye,
Length: uint16((g.Len() / 4) - 1),
Length: uint16((g.MarshalSize() / 4) - 1),
}
}

// Len returns the length of the Goodbye when encoded as binary.
func (g *Goodbye) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (g *Goodbye) MarshalSize() int {
srcsLength := len(g.Sources) * ssrcLength
reasonLength := len(g.Reason) + 1

Expand Down
2 changes: 1 addition & 1 deletion packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Packet interface {

Marshal() ([]byte, error)
Unmarshal(rawPacket []byte) error
Len() int
MarshalSize() int
}

// Unmarshal takes an entire udp datagram (which may consist of multiple RTCP packets) and
Expand Down
6 changes: 3 additions & 3 deletions picture_loss_indication.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (p PictureLossIndication) Marshal() ([]byte, error) {
*
* The semantics of this FB message is independent of the payload type.
*/
rawPacket := make([]byte, p.Len())
rawPacket := make([]byte, p.MarshalSize())
packetBody := rawPacket[headerLength:]

binary.BigEndian.PutUint32(packetBody, p.SenderSSRC)
Expand Down Expand Up @@ -78,8 +78,8 @@ func (p *PictureLossIndication) Header() Header {
}
}

// Len returns the length of the PictureLossIndication when encoded as binary.
func (p *PictureLossIndication) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (p *PictureLossIndication) MarshalSize() int {
return headerLength + ssrcLength*2
}

Expand Down
6 changes: 3 additions & 3 deletions rapid_resynchronization_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (p RapidResynchronizationRequest) Marshal() ([]byte, error) {
*
* The semantics of this FB message is independent of the payload type.
*/
rawPacket := make([]byte, p.Len())
rawPacket := make([]byte, p.MarshalSize())
packetBody := rawPacket[headerLength:]

binary.BigEndian.PutUint32(packetBody, p.SenderSSRC)
Expand Down Expand Up @@ -70,8 +70,8 @@ func (p *RapidResynchronizationRequest) Unmarshal(rawPacket []byte) error {
return nil
}

// Len returns the length of the RapidResynchronizationRequest when encoded as binary.
func (p *RapidResynchronizationRequest) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (p *RapidResynchronizationRequest) MarshalSize() int {
return headerLength + rrrHeaderLength
}

Expand Down
4 changes: 2 additions & 2 deletions raw_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r RawPacket) String() string {
return out
}

// Len returns the length of the RawPacket when encoded as binary.
func (r RawPacket) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (r RawPacket) MarshalSize() int {
return len(r)
}
12 changes: 6 additions & 6 deletions receiver_estimated_maximum_bitrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type ReceiverEstimatedMaximumBitrate struct {
// Marshal serializes the packet and returns a byte slice.
func (p ReceiverEstimatedMaximumBitrate) Marshal() (buf []byte, err error) {
// Allocate a buffer of the exact output size.
buf = make([]byte, p.Len())
buf = make([]byte, p.MarshalSize())

// Write to our buffer.
n, err := p.MarshalTo(buf)
Expand All @@ -42,8 +42,8 @@ func (p ReceiverEstimatedMaximumBitrate) Marshal() (buf []byte, err error) {
return buf, nil
}

// Len returns the length of the ReceiverEstimatedMaximumBitrate when encoded as binary.
func (p ReceiverEstimatedMaximumBitrate) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (p ReceiverEstimatedMaximumBitrate) MarshalSize() int {
return 20 + 4*len(p.SSRCs)
}

Expand All @@ -69,7 +69,7 @@ func (p ReceiverEstimatedMaximumBitrate) MarshalTo(buf []byte) (n int, err error
| ... |
*/

size := p.Len()
size := p.MarshalSize()
if len(buf) < size {
return 0, errPacketTooShort
}
Expand All @@ -78,7 +78,7 @@ func (p ReceiverEstimatedMaximumBitrate) MarshalTo(buf []byte) (n int, err error
buf[1] = 206

// Length of this packet in 32-bit words minus one.
length := uint16((p.Len() / 4) - 1)
length := uint16((p.MarshalSize() / 4) - 1)
binary.BigEndian.PutUint16(buf[2:4], length)

binary.BigEndian.PutUint32(buf[4:8], p.SenderSSRC)
Expand Down Expand Up @@ -255,7 +255,7 @@ func (p *ReceiverEstimatedMaximumBitrate) Header() Header {
return Header{
Count: FormatREMB,
Type: TypePayloadSpecificFeedback,
Length: uint16((p.Len() / 4) - 1),
Length: uint16((p.MarshalSize() / 4) - 1),
}
}

Expand Down
8 changes: 4 additions & 4 deletions receiver_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (r ReceiverReport) Marshal() ([]byte, error) {
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/

rawPacket := make([]byte, r.Len())
rawPacket := make([]byte, r.MarshalSize())
packetBody := rawPacket[headerLength:]

binary.BigEndian.PutUint32(packetBody, r.SSRC)
Expand Down Expand Up @@ -157,8 +157,8 @@ func (r *ReceiverReport) Unmarshal(rawPacket []byte) error {
return nil
}

// Len returns the length of the ReceiverReport when encoded as binary.
func (r *ReceiverReport) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (r *ReceiverReport) MarshalSize() int {
repsLength := 0
for _, rep := range r.Reports {
repsLength += rep.len()
Expand All @@ -171,7 +171,7 @@ func (r *ReceiverReport) Header() Header {
return Header{
Count: uint8(len(r.Reports)),
Type: TypeReceiverReport,
Length: uint16((r.Len()/4)-1) + uint16(getPadding(len(r.ProfileExtensions))),
Length: uint16((r.MarshalSize()/4)-1) + uint16(getPadding(len(r.ProfileExtensions))),
}
}

Expand Down
6 changes: 3 additions & 3 deletions rfc8888.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (b CCFeedbackReport) DestinationSSRC() []uint32 {
return ssrcs
}

// Len returns the length of the report in bytes
func (b *CCFeedbackReport) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (b *CCFeedbackReport) MarshalSize() int {
n := 0
for _, block := range b.ReportBlocks {
n += block.len()
Expand All @@ -107,7 +107,7 @@ func (b *CCFeedbackReport) Header() Header {
Padding: false,
Count: FormatCCFB,
Type: TypeTransportSpecificFeedback,
Length: uint16(b.Len()/4 - 1),
Length: uint16(b.MarshalSize()/4 - 1),
}
}

Expand Down
8 changes: 4 additions & 4 deletions sender_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (r SenderReport) Marshal() ([]byte, error) {
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/

rawPacket := make([]byte, r.Len())
rawPacket := make([]byte, r.MarshalSize())
packetBody := rawPacket[headerLength:]

binary.BigEndian.PutUint32(packetBody[srSSRCOffset:], r.SSRC)
Expand Down Expand Up @@ -228,8 +228,8 @@ func (r *SenderReport) DestinationSSRC() []uint32 {
return out
}

// Len returns the length of the SenderReport when encoded as binary.
func (r *SenderReport) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (r *SenderReport) MarshalSize() int {
repsLength := 0
for _, rep := range r.Reports {
repsLength += rep.len()
Expand All @@ -242,7 +242,7 @@ func (r *SenderReport) Header() Header {
return Header{
Count: uint8(len(r.Reports)),
Type: TypeSenderReport,
Length: uint16((r.Len() / 4) - 1),
Length: uint16((r.MarshalSize() / 4) - 1),
}
}

Expand Down
6 changes: 3 additions & 3 deletions slice_loss_indication.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (p *SliceLossIndication) Unmarshal(rawPacket []byte) error {
return nil
}

// Len returns the length of the SliceLossIndication when encoded as binary.
func (p *SliceLossIndication) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (p *SliceLossIndication) MarshalSize() int {
return headerLength + sliOffset + (len(p.SLI) * 4)
}

Expand All @@ -103,7 +103,7 @@ func (p *SliceLossIndication) Header() Header {
return Header{
Count: FormatSLI,
Type: TypeTransportSpecificFeedback,
Length: uint16((p.Len() / 4) - 1),
Length: uint16((p.MarshalSize() / 4) - 1),
}
}

Expand Down
8 changes: 4 additions & 4 deletions source_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s SourceDescription) Marshal() ([]byte, error) {
* +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
*/

rawPacket := make([]byte, s.Len())
rawPacket := make([]byte, s.MarshalSize())
packetBody := rawPacket[headerLength:]

chunkOffset := 0
Expand Down Expand Up @@ -169,8 +169,8 @@ func (s *SourceDescription) Unmarshal(rawPacket []byte) error {
return nil
}

// Len returns the length of the SourceDescription when encoded as binary.
func (s *SourceDescription) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (s *SourceDescription) MarshalSize() int {
chunksLength := 0
for _, c := range s.Chunks {
chunksLength += c.len()
Expand All @@ -183,7 +183,7 @@ func (s *SourceDescription) Header() Header {
return Header{
Count: uint8(len(s.Chunks)),
Type: TypeSourceDescription,
Length: uint16((s.Len() / 4) - 1),
Length: uint16((s.MarshalSize() / 4) - 1),
}
}

Expand Down
8 changes: 4 additions & 4 deletions transport_layer_cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ func (t *TransportLayerCC) packetLen() uint16 {
return n
}

// Len return total bytes with padding
func (t *TransportLayerCC) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (t *TransportLayerCC) MarshalSize() int {
n := t.packetLen()
// has padding
if n%4 != 0 {
Expand Down Expand Up @@ -399,7 +399,7 @@ func (t TransportLayerCC) Marshal() ([]byte, error) {
return nil, err
}

payload := make([]byte, t.Len()-headerLength)
payload := make([]byte, t.MarshalSize()-headerLength)
binary.BigEndian.PutUint32(payload, t.SenderSSRC)
binary.BigEndian.PutUint32(payload[4:], t.MediaSSRC)
binary.BigEndian.PutUint16(payload[baseSequenceNumberOffset:], t.BaseSequenceNumber)
Expand Down Expand Up @@ -430,7 +430,7 @@ func (t TransportLayerCC) Marshal() ([]byte, error) {
}

if t.Header.Padding {
payload[len(payload)-1] = uint8(t.Len() - int(t.packetLen()))
payload[len(payload)-1] = uint8(t.MarshalSize() - int(t.packetLen()))
}

return append(header, payload...), nil
Expand Down
6 changes: 3 additions & 3 deletions transport_layer_nack.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ func (p *TransportLayerNack) Unmarshal(rawPacket []byte) error {
return nil
}

// Len returns the length of the TransportLayerNack when encoded as binary.
func (p *TransportLayerNack) Len() int {
// MarshalSize returns the size of the packet once marshaled
func (p *TransportLayerNack) MarshalSize() int {
return headerLength + nackOffset + (len(p.Nacks) * 4)
}

Expand All @@ -161,7 +161,7 @@ func (p *TransportLayerNack) Header() Header {
return Header{
Count: FormatTLN,
Type: TypeTransportSpecificFeedback,
Length: uint16((p.Len() / 4) - 1),
Length: uint16((p.MarshalSize() / 4) - 1),
}
}

Expand Down

0 comments on commit 4bef349

Please sign in to comment.