forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prioritytype.go
71 lines (62 loc) · 1.55 KB
/
prioritytype.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
62
63
64
65
66
67
68
69
70
71
package webrtc
// PriorityType determines the priority type of a data channel.
type PriorityType int
const (
// PriorityTypeVeryLow corresponds to "below normal".
PriorityTypeVeryLow PriorityType = iota + 1
// PriorityTypeLow corresponds to "normal".
PriorityTypeLow
// PriorityTypeMedium corresponds to "high".
PriorityTypeMedium
// PriorityTypeHigh corresponds to "extra high".
PriorityTypeHigh
)
// This is done this way because of a linter.
const (
priorityTypeVeryLowStr = "very-low"
priorityTypeLowStr = "low"
priorityTypeMediumStr = "medium"
priorityTypeHighStr = "high"
)
func newPriorityTypeFromString(raw string) PriorityType {
switch raw {
case priorityTypeVeryLowStr:
return PriorityTypeVeryLow
case priorityTypeLowStr:
return PriorityTypeLow
case priorityTypeMediumStr:
return PriorityTypeMedium
case priorityTypeHighStr:
return PriorityTypeHigh
default:
return PriorityType(Unknown)
}
}
func newPriorityTypeFromUint16(raw uint16) PriorityType {
switch {
case raw <= 128:
return PriorityTypeVeryLow
case 129 <= raw && raw <= 256:
return PriorityTypeLow
case 257 <= raw && raw <= 512:
return PriorityTypeMedium
case 513 <= raw:
return PriorityTypeHigh
default:
return PriorityType(Unknown)
}
}
func (p PriorityType) String() string {
switch p {
case PriorityTypeVeryLow:
return priorityTypeVeryLowStr
case PriorityTypeLow:
return priorityTypeLowStr
case PriorityTypeMedium:
return priorityTypeMediumStr
case PriorityTypeHigh:
return priorityTypeHighStr
default:
return ErrUnknownType.Error()
}
}