Skip to content

Commit 57bce0e

Browse files
committed
quic: move packetType.String out of test-only code
This is also used when GODEBUG=quiclogpackets=1 is set. For golang/go#58547 Change-Id: I8ae27629090d12a8a23131e7f1adc93cc6ea8715 Reviewed-on: https://go-review.googlesource.com/c/net/+/527579 Reviewed-by: Jonathan Amsterdam <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent cae7dab commit 57bce0e

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

internal/quic/packet.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
package quic
88

9+
import "fmt"
10+
911
// packetType is a QUIC packet type.
1012
// https://www.rfc-editor.org/rfc/rfc9000.html#section-17
1113
type packetType byte
@@ -20,6 +22,22 @@ const (
2022
packetTypeVersionNegotiation
2123
)
2224

25+
func (p packetType) String() string {
26+
switch p {
27+
case packetTypeInitial:
28+
return "Initial"
29+
case packetType0RTT:
30+
return "0-RTT"
31+
case packetTypeHandshake:
32+
return "Handshake"
33+
case packetTypeRetry:
34+
return "Retry"
35+
case packetType1RTT:
36+
return "1-RTT"
37+
}
38+
return fmt.Sprintf("unknown packet type %v", byte(p))
39+
}
40+
2341
// Bits set in the first byte of a packet.
2442
const (
2543
headerFormLong = 0x80 // https://www.rfc-editor.org/rfc/rfc9000.html#section-17.2-3.2.1

internal/quic/packet_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,10 @@ package quic
99
import (
1010
"bytes"
1111
"encoding/hex"
12-
"fmt"
1312
"strings"
1413
"testing"
1514
)
1615

17-
func (p packetType) String() string {
18-
switch p {
19-
case packetTypeInitial:
20-
return "Initial"
21-
case packetType0RTT:
22-
return "0-RTT"
23-
case packetTypeHandshake:
24-
return "Handshake"
25-
case packetTypeRetry:
26-
return "Retry"
27-
case packetType1RTT:
28-
return "1-RTT"
29-
}
30-
return fmt.Sprintf("unknown packet type %v", byte(p))
31-
}
32-
3316
func TestPacketHeader(t *testing.T) {
3417
for _, test := range []struct {
3518
name string

0 commit comments

Comments
 (0)