Skip to content

Commit

Permalink
add a function to distinguish between short and long header packets
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Dec 6, 2020
1 parent a408e5e commit a83b724
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/wire/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"github.com/lucas-clemente/quic-go/internal/utils"
)

// IsLongHeader says if a packet is a long header packet.
func IsLongHeader(firstByte byte) bool {
return firstByte&0x80 > 0
}

// ParseConnectionID parses the destination connection ID of a packet.
// It uses the data slice for the connection ID.
// That means that the connection ID must not be used after the packet buffer is released.
Expand Down
5 changes: 5 additions & 0 deletions internal/wire/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ var _ = Describe("Header Parsing", func() {
return data
}

It("distinguishes between long and short header packets", func() {
Expect(IsLongHeader(0b10101011)).To(BeTrue())
Expect(IsLongHeader(0b00101011)).To(BeFalse())
})

Context("Parsing the Connection ID", func() {
It("parses the connection ID of a long header packet", func() {
buf := &bytes.Buffer{}
Expand Down

0 comments on commit a83b724

Please sign in to comment.