Debian Codegraph @

util.go

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package rtcp
5
6 // getPadding Returns the padding required to make the length a multiple of 4.
7 func getPadding(packetLen int) int {
8 if packetLen%4 == 0 {
9 return 0
10 }
11
12 return 4 - (packetLen % 4)
13 }
14
15 // setNBitsOfUint16 will truncate the value to size, left-shift to startIndex position and set.
16 func setNBitsOfUint16(src, size, startIndex, val uint16) (uint16, error) {
17 if startIndex+size > 16 {
18 return 0, errInvalidSizeOrStartIndex
19 }
20
21 // truncate val to size bits
22 val &= (1 << size) - 1
23
24 return src | (val << (16 - size - startIndex)), nil
25 }
26
27 // appendBit32 will left-shift and append n bits of val.
28 func appendNBitsToUint32(src, n, val uint32) uint32 {
29 return (src << n) | (val & (0xFFFFFFFF >> (32 - n)))
30 }
31
32 // getNBit get n bits from 1 byte, begin with a position.
33 func getNBitsFromByte(b byte, begin, n uint16) uint16 {
34 endShift := 8 - (begin + n)
35 mask := (0xFF >> begin) & uint8(0xFF<<endShift)
36
37 return uint16(b&mask) >> endShift
38 }
39
40 // get24BitFromBytes get 24bits from `[3]byte` slice.
41 func get24BitsFromBytes(b []byte) uint32 {
42 return uint32(b[0])<<16 + uint32(b[1])<<8 + uint32(b[2])
43 }