forked from quic-go/quic-go
@@ -199,24 +199,3 @@ func (f *StreamFrame) MinLength() (protocol.ByteCount, error) {
|
||||
|
||||
return length + 1, nil
|
||||
}
|
||||
|
||||
// MaybeSplitOffFrame removes the first n bytes and returns them as a separate frame. If n >= len(n), nil is returned and nothing is modified.
|
||||
func (f *StreamFrame) MaybeSplitOffFrame(n protocol.ByteCount) *StreamFrame {
|
||||
minLength, _ := f.MinLength() // StreamFrame.MinLength *never* errors
|
||||
if n >= minLength-1+protocol.ByteCount(len(f.Data)) {
|
||||
return nil
|
||||
}
|
||||
n -= minLength - 1
|
||||
|
||||
defer func() {
|
||||
f.Data = f.Data[n:]
|
||||
f.Offset += n
|
||||
}()
|
||||
|
||||
return &StreamFrame{
|
||||
FinBit: false,
|
||||
StreamID: f.StreamID,
|
||||
Offset: f.Offset,
|
||||
Data: f.Data[:n],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,36 +371,4 @@ var _ = Describe("StreamFrame", func() {
|
||||
Expect(f.getOffsetLength()).To(Equal(protocol.ByteCount(8)))
|
||||
})
|
||||
})
|
||||
|
||||
Context("splitting off earlier stream frames", func() {
|
||||
It("splits off nothing", func() {
|
||||
f := &StreamFrame{
|
||||
StreamID: 1,
|
||||
Data: []byte("bar"),
|
||||
Offset: 3,
|
||||
}
|
||||
Expect(f.MaybeSplitOffFrame(1000)).To(BeNil())
|
||||
Expect(f.Offset).To(Equal(protocol.ByteCount(3)))
|
||||
})
|
||||
|
||||
It("splits off initial frame", func() {
|
||||
f := &StreamFrame{
|
||||
StreamID: 1,
|
||||
Data: []byte("foobar"),
|
||||
Offset: 3,
|
||||
FinBit: true,
|
||||
}
|
||||
minLength, _ := f.MinLength()
|
||||
previous := f.MaybeSplitOffFrame(minLength - 1 + 3)
|
||||
Expect(previous).ToNot(BeNil())
|
||||
Expect(previous.StreamID).To(Equal(protocol.StreamID(1)))
|
||||
Expect(previous.Data).To(Equal([]byte("foo")))
|
||||
Expect(previous.Offset).To(Equal(protocol.ByteCount(3)))
|
||||
Expect(previous.FinBit).To(BeFalse())
|
||||
Expect(f.StreamID).To(Equal(protocol.StreamID(1)))
|
||||
Expect(f.Data).To(Equal([]byte("bar")))
|
||||
Expect(f.Offset).To(Equal(protocol.ByteCount(6)))
|
||||
Expect(f.FinBit).To(BeTrue())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user