From 83f71e379ef043d4a479b9a056a23df8116e05c7 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 13 May 2016 00:59:02 +0700 Subject: [PATCH] implement WindowUpdateFrame writing work towards #19 --- frames/window_update_frame.go | 9 +++++-- frames/window_update_frame_test.go | 38 ++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/frames/window_update_frame.go b/frames/window_update_frame.go index 5b7919d8c..01bed55d8 100644 --- a/frames/window_update_frame.go +++ b/frames/window_update_frame.go @@ -15,12 +15,17 @@ type WindowUpdateFrame struct { //Write writes a RST_STREAM frame func (f *WindowUpdateFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error { - panic("WindowUpdateFrame: Write not yet implemented") + typeByte := uint8(0x04) + b.WriteByte(typeByte) + + utils.WriteUint32(b, uint32(f.StreamID)) + utils.WriteUint64(b, uint64(f.ByteOffset)) + return nil } // MinLength of a written frame func (f *WindowUpdateFrame) MinLength() (protocol.ByteCount, error) { - panic("WindowUpdateFrame: Write not yet implemented") + return 1 + 4 + 8, nil } // ParseWindowUpdateFrame parses a RST_STREAM frame diff --git a/frames/window_update_frame_test.go b/frames/window_update_frame_test.go index 66af092e1..bb7925efc 100644 --- a/frames/window_update_frame_test.go +++ b/frames/window_update_frame_test.go @@ -9,16 +9,34 @@ import ( ) 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(protocol.ByteCount(0xDECAFBAD11223344))) - Expect(b.Len()).To(Equal(0)) - }) + 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(protocol.ByteCount(0xDECAFBAD11223344))) + Expect(b.Len()).To(Equal(0)) + }) + }) + + Context("when writing", func() { + It("has proper min length", func() { + f := &WindowUpdateFrame{ + StreamID: 0x1337, + ByteOffset: 0xDEADBEEF, + } + Expect(f.MinLength()).To(Equal(protocol.ByteCount(13))) + }) + + It("writes a sample frame", func() { + b := &bytes.Buffer{} + f := &WindowUpdateFrame{ + StreamID: 0xDECAFBAD, + ByteOffset: 0xDEADBEEFCAFE1337, + } + f.Write(b, 0) + Expect(b.Bytes()).To(Equal([]byte{0x04, 0xAD, 0xFB, 0xCA, 0xDE, 0x37, 0x13, 0xFE, 0xCA, 0xEF, 0xBE, 0xAD, 0xDE})) }) }) })