forked from quic-go/quic-go
rename frame.MaxLength() to frame.MinLength()
This commit is contained in:
@@ -67,8 +67,8 @@ func (f *AckFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, pa
|
||||
return nil
|
||||
}
|
||||
|
||||
// MaxLength of a written frame
|
||||
func (f *AckFrame) MaxLength() int {
|
||||
// MinLength of a written frame
|
||||
func (f *AckFrame) MinLength() int {
|
||||
l := 1 + 1 + 6 + 2 + 1 + 1 + 4
|
||||
l += (1 + 2) * 0 /* TODO: num_timestamps */
|
||||
if f.HasNACK() {
|
||||
|
||||
@@ -247,17 +247,17 @@ var _ = Describe("AckFrame", func() {
|
||||
Expect(packetNumber2).To(BeEquivalentTo([]byte{1, 0, 0, 0, 0, 0}))
|
||||
})
|
||||
|
||||
It("has proper max length", func() {
|
||||
It("has proper min length", func() {
|
||||
b := &bytes.Buffer{}
|
||||
f := &AckFrame{
|
||||
Entropy: 2,
|
||||
LargestObserved: 1,
|
||||
}
|
||||
f.Write(b, 1, 6)
|
||||
Expect(f.MaxLength()).To(Equal(b.Len()))
|
||||
Expect(f.MinLength()).To(Equal(b.Len()))
|
||||
})
|
||||
|
||||
It("has proper max length with nack ranges", func() {
|
||||
It("has proper min length with nack ranges", func() {
|
||||
b := &bytes.Buffer{}
|
||||
f := &AckFrame{
|
||||
Entropy: 2,
|
||||
@@ -271,7 +271,7 @@ var _ = Describe("AckFrame", func() {
|
||||
}
|
||||
err := f.Write(b, 1, 6)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(f.MaxLength()).To(Equal(b.Len()))
|
||||
Expect(f.MinLength()).To(Equal(b.Len()))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ func ParseConnectionCloseFrame(r *bytes.Reader) (*ConnectionCloseFrame, error) {
|
||||
return frame, nil
|
||||
}
|
||||
|
||||
// MaxLength of a written frame
|
||||
func (f *ConnectionCloseFrame) MaxLength() int {
|
||||
// MinLength of a written frame
|
||||
func (f *ConnectionCloseFrame) MinLength() int {
|
||||
return 1 + 4 + 2 + len(f.ReasonPhrase)
|
||||
}
|
||||
|
||||
|
||||
@@ -71,14 +71,14 @@ var _ = Describe("ConnectionCloseFrame", func() {
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("has proper max length", func() {
|
||||
It("has proper min length", func() {
|
||||
b := &bytes.Buffer{}
|
||||
f := &ConnectionCloseFrame{
|
||||
ErrorCode: 0xDEADBEEF,
|
||||
ReasonPhrase: "foobar",
|
||||
}
|
||||
f.Write(b, 1, 6)
|
||||
Expect(f.MaxLength()).To(Equal(b.Len()))
|
||||
Expect(f.MinLength()).To(Equal(b.Len()))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@ import (
|
||||
// A Frame in QUIC
|
||||
type Frame interface {
|
||||
Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen uint8) error
|
||||
MaxLength() int
|
||||
MinLength() int
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ func (f *RstStreamFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumb
|
||||
panic("RstStreamFrame: Write not yet implemented")
|
||||
}
|
||||
|
||||
// MaxLength of a written frame
|
||||
func (f *RstStreamFrame) MaxLength() int {
|
||||
// MinLength of a written frame
|
||||
func (f *RstStreamFrame) MinLength() int {
|
||||
panic("RstStreamFrame: Write not yet implemented")
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ func (f *StopWaitingFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNu
|
||||
return nil
|
||||
}
|
||||
|
||||
// MaxLength of a written frame
|
||||
func (f *StopWaitingFrame) MaxLength() int {
|
||||
// MinLength of a written frame
|
||||
func (f *StopWaitingFrame) MinLength() int {
|
||||
return 1 + 1 + 6
|
||||
}
|
||||
|
||||
|
||||
@@ -89,17 +89,17 @@ func (f *StreamFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber,
|
||||
return nil
|
||||
}
|
||||
|
||||
// MaxLength of a written frame
|
||||
func (f *StreamFrame) MaxLength() int {
|
||||
// MinLength of a written frame
|
||||
func (f *StreamFrame) MinLength() int {
|
||||
return 1 + 4 + 8 + 2 + 1
|
||||
}
|
||||
|
||||
// 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 int) *StreamFrame {
|
||||
if n >= f.MaxLength()-1+len(f.Data) {
|
||||
if n >= f.MinLength()-1+len(f.Data) {
|
||||
return nil
|
||||
}
|
||||
n -= f.MaxLength() - 1
|
||||
n -= f.MinLength() - 1
|
||||
|
||||
defer func() {
|
||||
f.Data = f.Data[n:]
|
||||
|
||||
@@ -51,7 +51,7 @@ var _ = Describe("StreamFrame", func() {
|
||||
Expect(b.Bytes()).To(Equal([]byte{0xbf, 0x1, 0, 0, 0, 0x10, 0, 0, 0, 0, 0, 0, 0, 0x06, 0x00, 'f', 'o', 'o', 'b', 'a', 'r'}))
|
||||
})
|
||||
|
||||
It("has proper max length", func() {
|
||||
It("has proper min length", func() {
|
||||
b := &bytes.Buffer{}
|
||||
f := &StreamFrame{
|
||||
StreamID: 1,
|
||||
@@ -59,7 +59,7 @@ var _ = Describe("StreamFrame", func() {
|
||||
Offset: 1,
|
||||
}
|
||||
f.Write(b, 1, 6)
|
||||
Expect(f.MaxLength()).To(Equal(b.Len()))
|
||||
Expect(f.MinLength()).To(Equal(b.Len()))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -81,7 +81,7 @@ var _ = Describe("StreamFrame", func() {
|
||||
Offset: 3,
|
||||
FinBit: true,
|
||||
}
|
||||
previous := f.MaybeSplitOffFrame(f.MaxLength() - 1 + 3)
|
||||
previous := f.MaybeSplitOffFrame(f.MinLength() - 1 + 3)
|
||||
Expect(previous).ToNot(BeNil())
|
||||
Expect(previous.StreamID).To(Equal(protocol.StreamID(1)))
|
||||
Expect(previous.Data).To(Equal([]byte("foo")))
|
||||
|
||||
@@ -18,8 +18,8 @@ func (f *WindowUpdateFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketN
|
||||
panic("WindowUpdateFrame: Write not yet implemented")
|
||||
}
|
||||
|
||||
// MaxLength of a written frame
|
||||
func (f *WindowUpdateFrame) MaxLength() int {
|
||||
// MinLength of a written frame
|
||||
func (f *WindowUpdateFrame) MinLength() int {
|
||||
panic("WindowUpdateFrame: Write not yet implemented")
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ func (p *packetPacker) composeNextPayload(currentPacketNumber protocol.PacketNum
|
||||
}
|
||||
|
||||
// Does the frame fit into the remaining space?
|
||||
if payload.Len()-1+frame.MaxLength() > protocol.MaxFrameSize {
|
||||
if payload.Len()-1+frame.MinLength() > protocol.MaxFrameSize {
|
||||
return payload.Bytes(), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user