diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2021-11-29 01:46:27 +0100 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2021-11-29 18:14:16 +0100 |
commit | 18f52af5be3a9a0c73811706108f790d65ee9c67 (patch) | |
tree | e13cbacb47d56919caa9c44a2b45dec1497a7860 /vendor/github.com/pion/srtp/v2/util.go | |
parent | ebcef0d57b6ecb5a40c6579f6be07182dd3033ba (diff) |
[pkg] update vendor
Diffstat (limited to 'vendor/github.com/pion/srtp/v2/util.go')
-rw-r--r-- | vendor/github.com/pion/srtp/v2/util.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/vendor/github.com/pion/srtp/v2/util.go b/vendor/github.com/pion/srtp/v2/util.go new file mode 100644 index 0000000..1ae34a6 --- /dev/null +++ b/vendor/github.com/pion/srtp/v2/util.go @@ -0,0 +1,33 @@ +package srtp + +import "bytes" + +// Grow the buffer size to the given number of bytes. +func growBufferSize(buf []byte, size int) []byte { + if size <= cap(buf) { + return buf[:size] + } + + buf2 := make([]byte, size) + copy(buf2, buf) + return buf2 +} + +// Check if buffers match, if not allocate a new buffer and return it +func allocateIfMismatch(dst, src []byte) []byte { + if dst == nil { + dst = make([]byte, len(src)) + copy(dst, src) + } else if !bytes.Equal(dst, src) { // bytes.Equal returns on ref equality, no optimization needed + extraNeeded := len(src) - len(dst) + if extraNeeded > 0 { + dst = append(dst, make([]byte, extraNeeded)...) + } else if extraNeeded < 0 { + dst = dst[:len(dst)+extraNeeded] + } + + copy(dst, src) + } + + return dst +} |