forked from pion/sdp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
direction.go
59 lines (52 loc) · 1.4 KB
/
direction.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
package sdp
import "errors"
//Direction is a marker for transmission directon of an endpoint
type Direction int
const (
//DirectionSendRecv is for bidirectional communication
DirectionSendRecv Direction = iota + 1
//DirectionSendOnly is for outgoing communication
DirectionSendOnly
//DirectionRecvOnly is for incoming communication
DirectionRecvOnly
//DirectionInactive is for no communication
DirectionInactive
)
const (
directionSendRecvStr = "sendrecv"
directionSendOnlyStr = "sendonly"
directionRecvOnlyStr = "recvonly"
directionInactiveStr = "inactive"
directionUnknownStr = ""
)
var errDirectionString = errors.New("invalid direction string")
// NewDirection defines a procedure for creating a new direction from a raw
// string.
func NewDirection(raw string) (Direction, error) {
switch raw {
case directionSendRecvStr:
return DirectionSendRecv, nil
case directionSendOnlyStr:
return DirectionSendOnly, nil
case directionRecvOnlyStr:
return DirectionRecvOnly, nil
case directionInactiveStr:
return DirectionInactive, nil
default:
return Direction(unknown), errDirectionString
}
}
func (t Direction) String() string {
switch t {
case DirectionSendRecv:
return directionSendRecvStr
case DirectionSendOnly:
return directionSendOnlyStr
case DirectionRecvOnly:
return directionRecvOnlyStr
case DirectionInactive:
return directionInactiveStr
default:
return directionUnknownStr
}
}