Files
webrtc/internal/util/util.go
Sean DuBois ed267f1cdb RTCP: Add util/GetPadding
Simple helper function to do 32bit padding calculation

Relates to #119
2018-09-20 21:19:15 -07:00

26 lines
551 B
Go

package util
import (
"math/rand"
"time"
)
// RandSeq generates a random alpha numeric sequence of the requested length
func RandSeq(n int) string {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, n)
for i := range b {
b[i] = letters[r.Intn(len(letters))]
}
return string(b)
}
// GetPadding Returns the padding required to make the length a multiple of 4
func GetPadding(len int) int {
if len%4 == 0 {
return 0
}
return 4 - (len % 4)
}