mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package wire
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("MAX_DATA frame", func() {
|
|
Context("when parsing", func() {
|
|
It("accepts sample frame", func() {
|
|
b := bytes.NewReader([]byte{0x4,
|
|
0xde, 0xca, 0xfb, 0xad, 0x11, 0x22, 0x33, 0x44, // byte offset
|
|
})
|
|
frame, err := ParseMaxDataFrame(b, versionBigEndian)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(frame.ByteOffset).To(Equal(protocol.ByteCount(0xdecafbad11223344)))
|
|
Expect(b.Len()).To(BeZero())
|
|
})
|
|
|
|
It("errors on EOFs", func() {
|
|
data := []byte{0x4,
|
|
0x44, 0x33, 0x22, 0x11, 0xad, 0xfb, 0xca, 0xde, // byte offset
|
|
}
|
|
_, err := ParseMaxDataFrame(bytes.NewReader(data), versionMaxDataFrame)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
for i := range data {
|
|
_, err := ParseMaxDataFrame(bytes.NewReader(data[0:i]), versionMaxDataFrame)
|
|
Expect(err).To(HaveOccurred())
|
|
}
|
|
})
|
|
})
|
|
|
|
Context("writing", func() {
|
|
It("has proper min length", func() {
|
|
f := &MaxDataFrame{
|
|
ByteOffset: 0xdeadbeef,
|
|
}
|
|
Expect(f.MinLength(versionMaxDataFrame)).To(Equal(protocol.ByteCount(1 + 8)))
|
|
})
|
|
|
|
It("writes a MAX_DATA frame", func() {
|
|
b := &bytes.Buffer{}
|
|
f := &MaxDataFrame{
|
|
ByteOffset: 0xdeadbeefcafe1337,
|
|
}
|
|
err := f.Write(b, versionMaxDataFrame)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(b.Bytes()).To(Equal([]byte{0x4,
|
|
0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37, // byte offset
|
|
}))
|
|
})
|
|
})
|
|
})
|