forked from quic-go/quic-go
add WindowUpdate frame parsing
This commit is contained in:
48
frames/window_update_frame.go
Normal file
48
frames/window_update_frame.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package frames
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/utils"
|
||||
)
|
||||
|
||||
// A WindowUpdateFrame in QUIC
|
||||
type WindowUpdateFrame struct {
|
||||
StreamID protocol.StreamID
|
||||
ByteOffset uint64
|
||||
}
|
||||
|
||||
//Write writes a RST_STREAM frame
|
||||
func (f *WindowUpdateFrame) Write(b *bytes.Buffer) error {
|
||||
panic("WindowUpdateFrame: Write not yet implemented")
|
||||
}
|
||||
|
||||
// MaxLength of a written frame
|
||||
func (f *WindowUpdateFrame) MaxLength() int {
|
||||
panic("WindowUpdateFrame: Write not yet implemented")
|
||||
}
|
||||
|
||||
// ParseWindowUpdateFrame parses a RST_STREAM frame
|
||||
func ParseWindowUpdateFrame(r *bytes.Reader) (*WindowUpdateFrame, error) {
|
||||
frame := &WindowUpdateFrame{}
|
||||
|
||||
// read the TypeByte
|
||||
_, err := r.ReadByte()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sid, err := utils.ReadUint32(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
frame.StreamID = protocol.StreamID(sid)
|
||||
|
||||
frame.ByteOffset, err = utils.ReadUint64(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return frame, nil
|
||||
}
|
||||
24
frames/window_update_frame_test.go
Normal file
24
frames/window_update_frame_test.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package frames
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("WindowUpdateFrame", func() {
|
||||
Context("window update frames", func() {
|
||||
Context("when parsing", func() {
|
||||
It("accepts sample frame", func() {
|
||||
b := bytes.NewReader([]byte{0x04, 0xEF, 0xBE, 0xAD, 0xDE, 0x44, 0x33, 0x22, 0x11, 0xAD, 0xFB, 0xCA, 0xDE})
|
||||
frame, err := ParseWindowUpdateFrame(b)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame.StreamID).To(Equal(protocol.StreamID(0xDEADBEEF)))
|
||||
Expect(frame.ByteOffset).To(Equal(uint64(0xDECAFBAD11223344)))
|
||||
Expect(b.Len()).To(Equal(0))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user