-
Notifications
You must be signed in to change notification settings - Fork 79
/
util.go
61 lines (47 loc) · 1.23 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package sctp
const (
paddingMultiple = 4
)
func getPadding(l int) int {
return (paddingMultiple - (l % paddingMultiple)) % paddingMultiple
}
func padByte(in []byte, cnt int) []byte {
if cnt < 0 {
cnt = 0
}
padding := make([]byte, cnt)
return append(in, padding...)
}
// Serial Number Arithmetic (RFC 1982)
func sna32LT(i1, i2 uint32) bool {
return (i1 < i2 && i2-i1 < 1<<31) || (i1 > i2 && i1-i2 > 1<<31)
}
func sna32LTE(i1, i2 uint32) bool {
return i1 == i2 || sna32LT(i1, i2)
}
func sna32GT(i1, i2 uint32) bool {
return (i1 < i2 && (i2-i1) >= 1<<31) || (i1 > i2 && (i1-i2) <= 1<<31)
}
func sna32GTE(i1, i2 uint32) bool {
return i1 == i2 || sna32GT(i1, i2)
}
func sna32EQ(i1, i2 uint32) bool {
return i1 == i2
}
func sna16LT(i1, i2 uint16) bool {
return (i1 < i2 && (i2-i1) < 1<<15) || (i1 > i2 && (i1-i2) > 1<<15)
}
func sna16LTE(i1, i2 uint16) bool {
return i1 == i2 || sna16LT(i1, i2)
}
func sna16GT(i1, i2 uint16) bool {
return (i1 < i2 && (i2-i1) >= 1<<15) || (i1 > i2 && (i1-i2) <= 1<<15)
}
func sna16GTE(i1, i2 uint16) bool {
return i1 == i2 || sna16GT(i1, i2)
}
func sna16EQ(i1, i2 uint16) bool {
return i1 == i2
}