diff --git a/internal/protocol/protocol.go b/internal/protocol/protocol.go index 98bc9ffb..b8104882 100644 --- a/internal/protocol/protocol.go +++ b/internal/protocol/protocol.go @@ -43,6 +43,21 @@ const ( ECNCE // 11 ) +func (e ECN) String() string { + switch e { + case ECNNon: + return "Not-ECT" + case ECT1: + return "ECT(1)" + case ECT0: + return "ECT(0)" + case ECNCE: + return "CE" + default: + return fmt.Sprintf("invalid ECN value: %d", e) + } +} + // A ByteCount in QUIC type ByteCount int64 diff --git a/internal/protocol/protocol_test.go b/internal/protocol/protocol_test.go index d9048f01..e672d31e 100644 --- a/internal/protocol/protocol_test.go +++ b/internal/protocol/protocol_test.go @@ -22,4 +22,12 @@ var _ = Describe("Protocol", func() { Expect(ECN(0b00000001)).To(Equal(ECT1)) Expect(ECN(0b00000011)).To(Equal(ECNCE)) }) + + It("has a string representation for ECN", func() { + Expect(ECNNon.String()).To(Equal("Not-ECT")) + Expect(ECT0.String()).To(Equal("ECT(0)")) + Expect(ECT1.String()).To(Equal("ECT(1)")) + Expect(ECNCE.String()).To(Equal("CE")) + Expect(ECN(42).String()).To(Equal("invalid ECN value: 42")) + }) })