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 <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/internal/quic/packet.go b/internal/quic/packet.go
index 93a9102..00c6714 100644
--- a/internal/quic/packet.go
+++ b/internal/quic/packet.go
@@ -6,6 +6,8 @@
 
 package quic
 
+import "fmt"
+
 // packetType is a QUIC packet type.
 // https://www.rfc-editor.org/rfc/rfc9000.html#section-17
 type packetType byte
@@ -20,6 +22,22 @@
 	packetTypeVersionNegotiation
 )
 
+func (p packetType) String() string {
+	switch p {
+	case packetTypeInitial:
+		return "Initial"
+	case packetType0RTT:
+		return "0-RTT"
+	case packetTypeHandshake:
+		return "Handshake"
+	case packetTypeRetry:
+		return "Retry"
+	case packetType1RTT:
+		return "1-RTT"
+	}
+	return fmt.Sprintf("unknown packet type %v", byte(p))
+}
+
 // Bits set in the first byte of a packet.
 const (
 	headerFormLong  = 0x80 // https://www.rfc-editor.org/rfc/rfc9000.html#section-17.2-3.2.1
diff --git a/internal/quic/packet_test.go b/internal/quic/packet_test.go
index f3a8b7d..b13a587 100644
--- a/internal/quic/packet_test.go
+++ b/internal/quic/packet_test.go
@@ -9,27 +9,10 @@
 import (
 	"bytes"
 	"encoding/hex"
-	"fmt"
 	"strings"
 	"testing"
 )
 
-func (p packetType) String() string {
-	switch p {
-	case packetTypeInitial:
-		return "Initial"
-	case packetType0RTT:
-		return "0-RTT"
-	case packetTypeHandshake:
-		return "Handshake"
-	case packetTypeRetry:
-		return "Retry"
-	case packetType1RTT:
-		return "1-RTT"
-	}
-	return fmt.Sprintf("unknown packet type %v", byte(p))
-}
-
 func TestPacketHeader(t *testing.T) {
 	for _, test := range []struct {
 		name         string