Skip to content

Commit

Permalink
protocol: add string representation for ECN values (#4008)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Aug 19, 2023
1 parent 5c5db8c commit 443c614
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/protocol/protocol.go
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions internal/protocol/protocol_test.go
Expand Up @@ -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"))
})
})

0 comments on commit 443c614

Please sign in to comment.