correctly determine the length of STREAM frames for IETF QUIC

The length of the data has an influence on the length of the frame (if
it contains the data length), and the length can either consume 1 or 2
bytes due to variable length encoding.
This commit is contained in:
Marten Seemann
2018-02-05 09:01:15 +08:00
parent 38c420a35b
commit 5974c6c113
5 changed files with 134 additions and 4 deletions

View File

@@ -191,6 +191,14 @@ func (f *StreamFrame) minLengthLegacy(_ protocol.VersionNumber) protocol.ByteCou
return length
}
func (f *StreamFrame) maxDataLenLegacy(maxFrameSize protocol.ByteCount, version protocol.VersionNumber) protocol.ByteCount {
headerLen := f.minLengthLegacy(version)
if headerLen > maxFrameSize {
return 0
}
return maxFrameSize - headerLen
}
// DataLen gives the length of data in bytes
func (f *StreamFrame) DataLen() protocol.ByteCount {
return protocol.ByteCount(len(f.Data))