Move Role to dedicated file

Relates to #118
This commit is contained in:
Sean DuBois
2020-02-23 22:05:13 -08:00
parent 086024fde6
commit cf1f69772b
2 changed files with 41 additions and 39 deletions
-39
View File
@@ -4,7 +4,6 @@ package ice
import (
"context"
"fmt"
"math/rand"
"net"
"strings"
@@ -1303,41 +1302,3 @@ func (a *Agent) GetRemoteCandidatesStats() []CandidateStats {
}
return <-resultChan
}
// Role represents ICE agent role, which can be controlling or controlled.
type Role byte
// UnmarshalText implements TextUnmarshaler.
func (r *Role) UnmarshalText(text []byte) error {
switch string(text) {
case "controlling":
*r = Controlling
case "controlled":
*r = Controlled
default:
return fmt.Errorf("unknown role %q", text)
}
return nil
}
// MarshalText implements TextMarshaler.
func (r Role) MarshalText() (text []byte, err error) {
return []byte(r.String()), nil
}
func (r Role) String() string {
switch r {
case Controlling:
return "controlling"
case Controlled:
return "controlled"
default:
return "unknown"
}
}
// Possible ICE agent roles.
const (
Controlling Role = iota
Controlled
)
+41
View File
@@ -0,0 +1,41 @@
package ice
import "fmt"
// Role represents ICE agent role, which can be controlling or controlled.
type Role byte
// Possible ICE agent roles.
const (
Controlling Role = iota
Controlled
)
// UnmarshalText implements TextUnmarshaler.
func (r *Role) UnmarshalText(text []byte) error {
switch string(text) {
case "controlling":
*r = Controlling
case "controlled":
*r = Controlled
default:
return fmt.Errorf("unknown role %q", text)
}
return nil
}
// MarshalText implements TextMarshaler.
func (r Role) MarshalText() (text []byte, err error) {
return []byte(r.String()), nil
}
func (r Role) String() string {
switch r {
case Controlling:
return "controlling"
case Controlled:
return "controlled"
default:
return "unknown"
}
}