forked from quic-go/quic-go
implement writing of RstStreamFrames
This commit is contained in:
@@ -16,12 +16,16 @@ type RstStreamFrame struct {
|
||||
|
||||
//Write writes a RST_STREAM frame
|
||||
func (f *RstStreamFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error {
|
||||
panic("RstStreamFrame: Write not yet implemented")
|
||||
b.WriteByte(0x01)
|
||||
utils.WriteUint32(b, uint32(f.StreamID))
|
||||
utils.WriteUint64(b, uint64(f.ByteOffset))
|
||||
utils.WriteUint32(b, f.ErrorCode)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MinLength of a written frame
|
||||
func (f *RstStreamFrame) MinLength() (protocol.ByteCount, error) {
|
||||
panic("RstStreamFrame: Write not yet implemented")
|
||||
return 1 + 4 + 8 + 4, nil
|
||||
}
|
||||
|
||||
// ParseRstStreamFrame parses a RST_STREAM frame
|
||||
|
||||
@@ -9,16 +9,36 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("RstStreamFrame", func() {
|
||||
Context("rst stream frames", func() {
|
||||
Context("when parsing", func() {
|
||||
It("accepts sample frame", func() {
|
||||
b := bytes.NewReader([]byte{0x01, 0xEF, 0xBE, 0xAD, 0xDE, 0x44, 0x33, 0x22, 0x11, 0xAD, 0xFB, 0xCA, 0xDE, 0x34, 0x12, 0x37, 0x13})
|
||||
frame, err := ParseRstStreamFrame(b)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame.StreamID).To(Equal(protocol.StreamID(0xDEADBEEF)))
|
||||
Expect(frame.ByteOffset).To(Equal(protocol.ByteCount(0xDECAFBAD11223344)))
|
||||
Expect(frame.ErrorCode).To(Equal(uint32(0x13371234)))
|
||||
})
|
||||
Context("when parsing", func() {
|
||||
It("accepts sample frame", func() {
|
||||
b := bytes.NewReader([]byte{0x01, 0xEF, 0xBE, 0xAD, 0xDE, 0x44, 0x33, 0x22, 0x11, 0xAD, 0xFB, 0xCA, 0xDE, 0x34, 0x12, 0x37, 0x13})
|
||||
frame, err := ParseRstStreamFrame(b)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame.StreamID).To(Equal(protocol.StreamID(0xDEADBEEF)))
|
||||
Expect(frame.ByteOffset).To(Equal(protocol.ByteCount(0xDECAFBAD11223344)))
|
||||
Expect(frame.ErrorCode).To(Equal(uint32(0x13371234)))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when writing", func() {
|
||||
It("writes a sample RstStreamFrame", func() {
|
||||
frame := RstStreamFrame{
|
||||
StreamID: 0x1337,
|
||||
ByteOffset: 0x11223344DECAFBAD,
|
||||
ErrorCode: 0xDEADBEEF,
|
||||
}
|
||||
b := &bytes.Buffer{}
|
||||
frame.Write(b, 0)
|
||||
Expect(b.Bytes()).To(Equal([]byte{0x01, 0x37, 0x13, 0, 0, 0xAD, 0xFB, 0xCA, 0xDE, 0x44, 0x33, 0x22, 0x11, 0xEF, 0xBE, 0xAD, 0xDE}))
|
||||
})
|
||||
|
||||
It("has the correct min length", func() {
|
||||
rst := RstStreamFrame{
|
||||
StreamID: 0x1337,
|
||||
ByteOffset: 0x1000,
|
||||
ErrorCode: 0xDE,
|
||||
}
|
||||
Expect(rst.MinLength()).To(Equal(protocol.ByteCount(17)))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user