Skip to content

Commit 1345033

Browse files
wdouglassSean-Der
authored andcommitted
Remove the "Unknown" constant
This commit replaces the Unknown constant with separate constants for each enumeration that uses it. Fixes pion#1293
1 parent 7e598b5 commit 1345033

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+163
-122
lines changed

Diff for: bundlepolicy.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ import (
1414
type BundlePolicy int
1515

1616
const (
17+
// BundlePolicyUnknown is the enum's zero-value
18+
BundlePolicyUnknown BundlePolicy = iota
19+
1720
// BundlePolicyBalanced indicates to gather ICE candidates for each
1821
// media type in use (audio, video, and data). If the remote endpoint is
1922
// not bundle-aware, negotiate only one audio and video track on separate
2023
// transports.
21-
BundlePolicyBalanced BundlePolicy = iota + 1
24+
BundlePolicyBalanced
2225

2326
// BundlePolicyMaxCompat indicates to gather ICE candidates for each
2427
// track. If the remote endpoint is not bundle-aware, negotiate all media
@@ -47,7 +50,7 @@ func newBundlePolicy(raw string) BundlePolicy {
4750
case bundlePolicyMaxBundleStr:
4851
return BundlePolicyMaxBundle
4952
default:
50-
return BundlePolicy(Unknown)
53+
return BundlePolicyUnknown
5154
}
5255
}
5356

Diff for: bundlepolicy_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestNewBundlePolicy(t *testing.T) {
1414
policyString string
1515
expectedPolicy BundlePolicy
1616
}{
17-
{unknownStr, BundlePolicy(Unknown)},
17+
{ErrUnknownType.Error(), BundlePolicyUnknown},
1818
{"balanced", BundlePolicyBalanced},
1919
{"max-compat", BundlePolicyMaxCompat},
2020
{"max-bundle", BundlePolicyMaxBundle},
@@ -34,7 +34,7 @@ func TestBundlePolicy_String(t *testing.T) {
3434
policy BundlePolicy
3535
expectedString string
3636
}{
37-
{BundlePolicy(Unknown), unknownStr},
37+
{BundlePolicyUnknown, ErrUnknownType.Error()},
3838
{BundlePolicyBalanced, "balanced"},
3939
{BundlePolicyMaxCompat, "max-compat"},
4040
{BundlePolicyMaxBundle, "max-bundle"},

Diff for: constants.go

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ package webrtc
66
import "github.com/pion/dtls/v2"
77

88
const (
9-
// Unknown defines default public constant to use for "enum" like struct
10-
// comparisons when no value was defined.
11-
Unknown = iota
12-
unknownStr = "unknown"
13-
149
// Equal to UDP MTU
1510
receiveMTU = 1460
1611

Diff for: datachannelstate.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ package webrtc
77
type DataChannelState int
88

99
const (
10+
// DataChannelStateUnknown is the enum's zero-value
11+
DataChannelStateUnknown DataChannelState = iota
12+
1013
// DataChannelStateConnecting indicates that the data channel is being
1114
// established. This is the initial state of DataChannel, whether created
1215
// with CreateDataChannel, or dispatched as a part of an DataChannelEvent.
13-
DataChannelStateConnecting DataChannelState = iota + 1
16+
DataChannelStateConnecting
1417

1518
// DataChannelStateOpen indicates that the underlying data transport is
1619
// established and communication is possible.
@@ -44,7 +47,7 @@ func newDataChannelState(raw string) DataChannelState {
4447
case dataChannelStateClosedStr:
4548
return DataChannelStateClosed
4649
default:
47-
return DataChannelState(Unknown)
50+
return DataChannelStateUnknown
4851
}
4952
}
5053

Diff for: datachannelstate_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestNewDataChannelState(t *testing.T) {
1414
stateString string
1515
expectedState DataChannelState
1616
}{
17-
{unknownStr, DataChannelState(Unknown)},
17+
{ErrUnknownType.Error(), DataChannelStateUnknown},
1818
{"connecting", DataChannelStateConnecting},
1919
{"open", DataChannelStateOpen},
2020
{"closing", DataChannelStateClosing},
@@ -35,7 +35,7 @@ func TestDataChannelState_String(t *testing.T) {
3535
state DataChannelState
3636
expectedString string
3737
}{
38-
{DataChannelState(Unknown), unknownStr},
38+
{DataChannelStateUnknown, ErrUnknownType.Error()},
3939
{DataChannelStateConnecting, "connecting"},
4040
{DataChannelStateOpen, "open"},
4141
{DataChannelStateClosing, "closing"},

Diff for: dtlsrole.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ import (
1111
type DTLSRole byte
1212

1313
const (
14+
// DTLSRoleUnknown is the enum's zero-value
15+
DTLSRoleUnknown DTLSRole = iota
16+
1417
// DTLSRoleAuto defines the DTLS role is determined based on
1518
// the resolved ICE role: the ICE controlled role acts as the DTLS
1619
// client and the ICE controlling role acts as the DTLS server.
17-
DTLSRoleAuto DTLSRole = iota + 1
20+
DTLSRoleAuto
1821

1922
// DTLSRoleClient defines the DTLS client role.
2023
DTLSRoleClient
@@ -51,7 +54,7 @@ func (r DTLSRole) String() string {
5154
case DTLSRoleServer:
5255
return "server"
5356
default:
54-
return unknownStr
57+
return ErrUnknownType.Error()
5558
}
5659
}
5760

Diff for: dtlsrole_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestDTLSRole_String(t *testing.T) {
1616
role DTLSRole
1717
expectedString string
1818
}{
19-
{DTLSRole(Unknown), unknownStr},
19+
{DTLSRoleUnknown, ErrUnknownType.Error()},
2020
{DTLSRoleAuto, "auto"},
2121
{DTLSRoleClient, "client"},
2222
{DTLSRoleServer, "server"},

Diff for: dtlstransportstate.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ package webrtc
77
type DTLSTransportState int
88

99
const (
10+
// DTLSTransportStateUnknown is the enum's zero-value
11+
DTLSTransportStateUnknown DTLSTransportState = iota
12+
1013
// DTLSTransportStateNew indicates that DTLS has not started negotiating
1114
// yet.
12-
DTLSTransportStateNew DTLSTransportState = iota + 1
15+
DTLSTransportStateNew
1316

1417
// DTLSTransportStateConnecting indicates that DTLS is in the process of
1518
// negotiating a secure connection and verifying the remote fingerprint.
@@ -52,7 +55,7 @@ func newDTLSTransportState(raw string) DTLSTransportState {
5255
case dtlsTransportStateFailedStr:
5356
return DTLSTransportStateFailed
5457
default:
55-
return DTLSTransportState(Unknown)
58+
return DTLSTransportStateUnknown
5659
}
5760
}
5861

Diff for: dtlstransportstate_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestNewDTLSTransportState(t *testing.T) {
1414
stateString string
1515
expectedState DTLSTransportState
1616
}{
17-
{unknownStr, DTLSTransportState(Unknown)},
17+
{ErrUnknownType.Error(), DTLSTransportStateUnknown},
1818
{"new", DTLSTransportStateNew},
1919
{"connecting", DTLSTransportStateConnecting},
2020
{"connected", DTLSTransportStateConnected},
@@ -36,7 +36,7 @@ func TestDTLSTransportState_String(t *testing.T) {
3636
state DTLSTransportState
3737
expectedString string
3838
}{
39-
{DTLSTransportState(Unknown), unknownStr},
39+
{DTLSTransportStateUnknown, ErrUnknownType.Error()},
4040
{DTLSTransportStateNew, "new"},
4141
{DTLSTransportStateConnecting, "connecting"},
4242
{DTLSTransportStateConnected, "connected"},

Diff for: icecandidatetype.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ import (
1313
type ICECandidateType int
1414

1515
const (
16+
// ICECandidateTypeUnknown is the enum's zero-value
17+
ICECandidateTypeUnknown ICECandidateType = iota
18+
1619
// ICECandidateTypeHost indicates that the candidate is of Host type as
1720
// described in https://tools.ietf.org/html/rfc8445#section-5.1.1.1. A
1821
// candidate obtained by binding to a specific port from an IP address on
1922
// the host. This includes IP addresses on physical interfaces and logical
2023
// ones, such as ones obtained through VPNs.
21-
ICECandidateTypeHost ICECandidateType = iota + 1
24+
ICECandidateTypeHost
2225

2326
// ICECandidateTypeSrflx indicates the the candidate is of Server
2427
// Reflexive type as described
@@ -60,7 +63,7 @@ func NewICECandidateType(raw string) (ICECandidateType, error) {
6063
case iceCandidateTypeRelayStr:
6164
return ICECandidateTypeRelay, nil
6265
default:
63-
return ICECandidateType(Unknown), fmt.Errorf("%w: %s", errICECandidateTypeUnknown, raw)
66+
return ICECandidateTypeUnknown, fmt.Errorf("%w: %s", errICECandidateTypeUnknown, raw)
6467
}
6568
}
6669

@@ -92,7 +95,7 @@ func getCandidateType(candidateType ice.CandidateType) (ICECandidateType, error)
9295
default:
9396
// NOTE: this should never happen[tm]
9497
err := fmt.Errorf("%w: %s", errICEInvalidConvertCandidateType, candidateType.String())
95-
return ICECandidateType(Unknown), err
98+
return ICECandidateTypeUnknown, err
9699
}
97100
}
98101

Diff for: icecandidatetype_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestICECandidateType(t *testing.T) {
1515
shouldFail bool
1616
expectedType ICECandidateType
1717
}{
18-
{unknownStr, true, ICECandidateType(Unknown)},
18+
{ErrUnknownType.Error(), true, ICECandidateTypeUnknown},
1919
{"host", false, ICECandidateTypeHost},
2020
{"srflx", false, ICECandidateTypeSrflx},
2121
{"prflx", false, ICECandidateTypePrflx},
@@ -40,7 +40,7 @@ func TestICECandidateType_String(t *testing.T) {
4040
cType ICECandidateType
4141
expectedString string
4242
}{
43-
{ICECandidateType(Unknown), unknownStr},
43+
{ICECandidateTypeUnknown, ErrUnknownType.Error()},
4444
{ICECandidateTypeHost, "host"},
4545
{ICECandidateTypeSrflx, "srflx"},
4646
{ICECandidateTypePrflx, "prflx"},

Diff for: icecomponent.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ package webrtc
88
type ICEComponent int
99

1010
const (
11+
// ICEComponentUnknown is the enum's zero-value
12+
ICEComponentUnknown ICEComponent = iota
13+
1114
// ICEComponentRTP indicates that the ICE Transport is used for RTP (or
1215
// RTCP multiplexing), as defined in
1316
// https://tools.ietf.org/html/rfc5245#section-4.1.1.1. Protocols
1417
// multiplexed with RTP (e.g. data channel) share its component ID. This
1518
// represents the component-id value 1 when encoded in candidate-attribute.
16-
ICEComponentRTP ICEComponent = iota + 1
19+
ICEComponentRTP
1720

1821
// ICEComponentRTCP indicates that the ICE Transport is used for RTCP as
1922
// defined by https://tools.ietf.org/html/rfc5245#section-4.1.1.1. This
@@ -34,7 +37,7 @@ func newICEComponent(raw string) ICEComponent {
3437
case iceComponentRTCPStr:
3538
return ICEComponentRTCP
3639
default:
37-
return ICEComponent(Unknown)
40+
return ICEComponentUnknown
3841
}
3942
}
4043

Diff for: icecomponent_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestICEComponent(t *testing.T) {
1414
componentString string
1515
expectedComponent ICEComponent
1616
}{
17-
{unknownStr, ICEComponent(Unknown)},
17+
{ErrUnknownType.Error(), ICEComponentUnknown},
1818
{"rtp", ICEComponentRTP},
1919
{"rtcp", ICEComponentRTCP},
2020
}
@@ -33,7 +33,7 @@ func TestICEComponent_String(t *testing.T) {
3333
state ICEComponent
3434
expectedString string
3535
}{
36-
{ICEComponent(Unknown), unknownStr},
36+
{ICEComponentUnknown, ErrUnknownType.Error()},
3737
{ICEComponentRTP, "rtp"},
3838
{ICEComponentRTCP, "rtcp"},
3939
}

Diff for: iceconnectionstate.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ package webrtc
77
type ICEConnectionState int
88

99
const (
10+
// ICEConnectionStateUnknown is the enum's zero-value
11+
ICEConnectionStateUnknown ICEConnectionState = iota
12+
1013
// ICEConnectionStateNew indicates that any of the ICETransports are
1114
// in the "new" state and none of them are in the "checking", "disconnected"
1215
// or "failed" state, or all ICETransports are in the "closed" state, or
1316
// there are no transports.
14-
ICEConnectionStateNew ICEConnectionState = iota + 1
17+
ICEConnectionStateNew
1518

1619
// ICEConnectionStateChecking indicates that any of the ICETransports
1720
// are in the "checking" state and none of them are in the "disconnected"
@@ -71,7 +74,7 @@ func NewICEConnectionState(raw string) ICEConnectionState {
7174
case iceConnectionStateClosedStr:
7275
return ICEConnectionStateClosed
7376
default:
74-
return ICEConnectionState(Unknown)
77+
return ICEConnectionStateUnknown
7578
}
7679
}
7780

Diff for: iceconnectionstate_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestNewICEConnectionState(t *testing.T) {
1414
stateString string
1515
expectedState ICEConnectionState
1616
}{
17-
{unknownStr, ICEConnectionState(Unknown)},
17+
{ErrUnknownType.Error(), ICEConnectionStateUnknown},
1818
{"new", ICEConnectionStateNew},
1919
{"checking", ICEConnectionStateChecking},
2020
{"connected", ICEConnectionStateConnected},
@@ -38,7 +38,7 @@ func TestICEConnectionState_String(t *testing.T) {
3838
state ICEConnectionState
3939
expectedString string
4040
}{
41-
{ICEConnectionState(Unknown), unknownStr},
41+
{ICEConnectionStateUnknown, ErrUnknownType.Error()},
4242
{ICEConnectionStateNew, "new"},
4343
{ICEConnectionStateChecking, "checking"},
4444
{ICEConnectionStateConnected, "connected"},

Diff for: icegathererstate.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import (
1111
type ICEGathererState uint32
1212

1313
const (
14+
// ICEGathererStateUnknown is the enum's zero-value
15+
ICEGathererStateUnknown ICEGathererState = iota
16+
1417
// ICEGathererStateNew indicates object has been created but
1518
// gather() has not been called.
16-
ICEGathererStateNew ICEGathererState = iota + 1
19+
ICEGathererStateNew
1720

1821
// ICEGathererStateGathering indicates gather() has been called,
1922
// and the ICEGatherer is in the process of gathering candidates.
@@ -38,7 +41,7 @@ func (s ICEGathererState) String() string {
3841
case ICEGathererStateClosed:
3942
return "closed"
4043
default:
41-
return unknownStr
44+
return ErrUnknownType.Error()
4245
}
4346
}
4447

Diff for: icegathererstate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestICEGathererState_String(t *testing.T) {
1414
state ICEGathererState
1515
expectedString string
1616
}{
17-
{ICEGathererState(Unknown), unknownStr},
17+
{ICEGathererStateUnknown, ErrUnknownType.Error()},
1818
{ICEGathererStateNew, "new"},
1919
{ICEGathererStateGathering, "gathering"},
2020
{ICEGathererStateComplete, "complete"},

Diff for: icegatheringstate.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ package webrtc
77
type ICEGatheringState int
88

99
const (
10+
// ICEGatheringStateUnknown is the enum's zero-value
11+
ICEGatheringStateUnknown ICEGatheringState = iota
12+
1013
// ICEGatheringStateNew indicates that any of the ICETransports are
1114
// in the "new" gathering state and none of the transports are in the
1215
// "gathering" state, or there are no transports.
13-
ICEGatheringStateNew ICEGatheringState = iota + 1
16+
ICEGatheringStateNew
1417

1518
// ICEGatheringStateGathering indicates that any of the ICETransports
1619
// are in the "gathering" state.
@@ -38,7 +41,7 @@ func NewICEGatheringState(raw string) ICEGatheringState {
3841
case iceGatheringStateCompleteStr:
3942
return ICEGatheringStateComplete
4043
default:
41-
return ICEGatheringState(Unknown)
44+
return ICEGatheringStateUnknown
4245
}
4346
}
4447

Diff for: icegatheringstate_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestNewICEGatheringState(t *testing.T) {
1414
stateString string
1515
expectedState ICEGatheringState
1616
}{
17-
{unknownStr, ICEGatheringState(Unknown)},
17+
{ErrUnknownType.Error(), ICEGatheringStateUnknown},
1818
{"new", ICEGatheringStateNew},
1919
{"gathering", ICEGatheringStateGathering},
2020
{"complete", ICEGatheringStateComplete},
@@ -34,7 +34,7 @@ func TestICEGatheringState_String(t *testing.T) {
3434
state ICEGatheringState
3535
expectedString string
3636
}{
37-
{ICEGatheringState(Unknown), unknownStr},
37+
{ICEGatheringStateUnknown, ErrUnknownType.Error()},
3838
{ICEGatheringStateNew, "new"},
3939
{ICEGatheringStateGathering, "gathering"},
4040
{ICEGatheringStateComplete, "complete"},

0 commit comments

Comments
 (0)