fix StreamID len in StreamFrame TypeByte if len was calculated by MinLength

fixes #166
This commit is contained in:
Marten Seemann
2016-06-07 13:47:38 +07:00
parent 4f49a242ff
commit 995c020b39
2 changed files with 14 additions and 1 deletions

View File

@@ -106,8 +106,8 @@ func (f *StreamFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) err
if f.streamIDLen == 0 {
f.calculateStreamIDLength()
typeByte ^= uint8(f.streamIDLen) - 1
}
typeByte ^= uint8(f.streamIDLen) - 1
b.WriteByte(typeByte)

View File

@@ -302,6 +302,19 @@ var _ = Describe("StreamFrame", func() {
Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x3)))
Expect(b.Bytes()[1:5]).To(Equal([]byte{0xAD, 0xFB, 0xCA, 0xDE}))
})
It("writes a multiple byte StreamID, after the Stream length was already determined by MinLenght()", func() {
b := &bytes.Buffer{}
frame := &StreamFrame{
StreamID: 0xDECAFBAD,
Data: []byte("foobar"),
}
frame.MinLength()
err := frame.Write(b, 0)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x3)))
Expect(b.Bytes()[1:5]).To(Equal([]byte{0xAD, 0xFB, 0xCA, 0xDE}))
})
})
})