diff --git a/example/main.go b/example/main.go index 3c1c801f0..53d7d5bdb 100644 --- a/example/main.go +++ b/example/main.go @@ -61,7 +61,7 @@ func handleStream(frame *frames.StreamFrame) []frames.Frame { } dataStreamFrame := &frames.StreamFrame{ - StreamID: h2frame.Header().StreamID, + StreamID: protocol.StreamID(h2frame.Header().StreamID), Data: []byte("Hello World!"), FinBit: true, } diff --git a/frames/stream_frame.go b/frames/stream_frame.go index afc011505..d7f5fc9cd 100644 --- a/frames/stream_frame.go +++ b/frames/stream_frame.go @@ -4,13 +4,14 @@ import ( "bytes" "io/ioutil" + "github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/utils" ) // A StreamFrame of QUIC type StreamFrame struct { FinBit bool - StreamID uint32 + StreamID protocol.StreamID Offset uint64 Data []byte } @@ -36,7 +37,7 @@ func ParseStreamFrame(r *bytes.Reader) (*StreamFrame, error) { if err != nil { return nil, err } - frame.StreamID = uint32(sid) + frame.StreamID = protocol.StreamID(sid) frame.Offset, err = utils.ReadUintN(r, offsetLen) if err != nil { @@ -79,7 +80,7 @@ func (f *StreamFrame) Write(b *bytes.Buffer) error { } typeByte ^= 0x03 // TODO: Send shorter stream ID if possible b.WriteByte(typeByte) - utils.WriteUint32(b, f.StreamID) + utils.WriteUint32(b, uint32(f.StreamID)) if f.Offset != 0 { utils.WriteUint64(b, f.Offset) } diff --git a/frames/stream_frame_test.go b/frames/stream_frame_test.go index 994990b72..391a47a1e 100644 --- a/frames/stream_frame_test.go +++ b/frames/stream_frame_test.go @@ -3,6 +3,7 @@ package frames import ( "bytes" + "github.com/lucas-clemente/quic-go/protocol" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -15,7 +16,7 @@ var _ = Describe("StreamFrame", func() { frame, err := ParseStreamFrame(b) Expect(err).ToNot(HaveOccurred()) Expect(frame.FinBit).To(BeFalse()) - Expect(frame.StreamID).To(Equal(uint32(1))) + Expect(frame.StreamID).To(Equal(protocol.StreamID(1))) Expect(frame.Offset).To(BeZero()) Expect(frame.Data).To(Equal([]byte("foobar"))) }) @@ -25,7 +26,7 @@ var _ = Describe("StreamFrame", func() { frame, err := ParseStreamFrame(b) Expect(err).ToNot(HaveOccurred()) Expect(frame.FinBit).To(BeFalse()) - Expect(frame.StreamID).To(Equal(uint32(1))) + Expect(frame.StreamID).To(Equal(protocol.StreamID(1))) Expect(frame.Offset).To(BeZero()) Expect(frame.Data).To(Equal([]byte("foobar"))) }) diff --git a/protocol/protocol.go b/protocol/protocol.go index 429c3d067..13b2ccc63 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -5,3 +5,6 @@ type PacketNumber uint64 // A ConnectionID in QUIC type ConnectionID uint64 + +// A StreamID in QUIC +type StreamID uint32