wire: use quicvarint.Parse when parsing frames (#4484)

* wire: add benchmarks for the frame parser

* wire: use quicvarint.Parse when parsing frames

* wire: always use io.EOF for too short frames
This commit is contained in:
Marten Seemann
2024-05-05 19:28:28 +08:00
committed by GitHub
parent 1514095afb
commit f12ee48617
38 changed files with 572 additions and 453 deletions

View File

@@ -1,7 +1,6 @@
package wire
import (
"bytes"
"io"
"github.com/quic-go/quic-go/internal/protocol"
@@ -13,19 +12,20 @@ import (
var _ = Describe("PATH_RESPONSE frame", func() {
Context("when parsing", func() {
It("accepts sample frame", func() {
b := bytes.NewReader([]byte{1, 2, 3, 4, 5, 6, 7, 8})
f, err := parsePathResponseFrame(b, protocol.Version1)
b := []byte{1, 2, 3, 4, 5, 6, 7, 8}
f, l, err := parsePathResponseFrame(b, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(b.Len()).To(BeZero())
Expect(f.Data).To(Equal([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
Expect(l).To(Equal(len(b)))
})
It("errors on EOFs", func() {
data := []byte{1, 2, 3, 4, 5, 6, 7, 8}
_, err := parsePathResponseFrame(bytes.NewReader(data), protocol.Version1)
_, l, err := parsePathResponseFrame(data, protocol.Version1)
Expect(err).NotTo(HaveOccurred())
Expect(l).To(Equal(len(data)))
for i := range data {
_, err := parsePathResponseFrame(bytes.NewReader(data[:i]), protocol.Version1)
_, _, err := parsePathResponseFrame(data[:i], protocol.Version1)
Expect(err).To(MatchError(io.EOF))
}
})