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 #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

bundlepolicy.go

Lines changed: 5 additions & 2 deletions
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

bundlepolicy_test.go

Lines changed: 2 additions & 2 deletions
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"},

constants.go

Lines changed: 0 additions & 5 deletions
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

datachannelstate.go

Lines changed: 5 additions & 2 deletions
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

datachannelstate_test.go

Lines changed: 2 additions & 2 deletions
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"},

dtlsrole.go

Lines changed: 5 additions & 2 deletions
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

dtlsrole_test.go

Lines changed: 1 addition & 1 deletion
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"},

dtlstransportstate.go

Lines changed: 5 additions & 2 deletions
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

dtlstransportstate_test.go

Lines changed: 2 additions & 2 deletions
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"},

icecandidatetype.go

Lines changed: 6 additions & 3 deletions
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

0 commit comments

Comments
 (0)