direction.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package sdp
  2. import "errors"
  3. // Direction is a marker for transmission directon of an endpoint
  4. type Direction int
  5. const (
  6. // DirectionSendRecv is for bidirectional communication
  7. DirectionSendRecv Direction = iota + 1
  8. // DirectionSendOnly is for outgoing communication
  9. DirectionSendOnly
  10. // DirectionRecvOnly is for incoming communication
  11. DirectionRecvOnly
  12. // DirectionInactive is for no communication
  13. DirectionInactive
  14. )
  15. const (
  16. directionSendRecvStr = "sendrecv"
  17. directionSendOnlyStr = "sendonly"
  18. directionRecvOnlyStr = "recvonly"
  19. directionInactiveStr = "inactive"
  20. directionUnknownStr = ""
  21. )
  22. var errDirectionString = errors.New("invalid direction string")
  23. // NewDirection defines a procedure for creating a new direction from a raw
  24. // string.
  25. func NewDirection(raw string) (Direction, error) {
  26. switch raw {
  27. case directionSendRecvStr:
  28. return DirectionSendRecv, nil
  29. case directionSendOnlyStr:
  30. return DirectionSendOnly, nil
  31. case directionRecvOnlyStr:
  32. return DirectionRecvOnly, nil
  33. case directionInactiveStr:
  34. return DirectionInactive, nil
  35. default:
  36. return Direction(unknown), errDirectionString
  37. }
  38. }
  39. func (t Direction) String() string {
  40. switch t {
  41. case DirectionSendRecv:
  42. return directionSendRecvStr
  43. case DirectionSendOnly:
  44. return directionSendOnlyStr
  45. case DirectionRecvOnly:
  46. return directionRecvOnlyStr
  47. case DirectionInactive:
  48. return directionInactiveStr
  49. default:
  50. return directionUnknownStr
  51. }
  52. }