2022-07-21 18:50:10 +02:00
|
|
|
package wire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
2023-02-02 12:42:11 +01:00
|
|
|
"github.com/quic-go/quic-go/internal/protocol"
|
|
|
|
"github.com/quic-go/quic-go/quicvarint"
|
2022-07-21 18:50:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// A MaxStreamDataFrame is a MAX_STREAM_DATA frame
|
|
|
|
type MaxStreamDataFrame struct {
|
|
|
|
StreamID protocol.StreamID
|
|
|
|
MaximumStreamData protocol.ByteCount
|
|
|
|
}
|
|
|
|
|
2024-03-26 19:56:06 +01:00
|
|
|
func parseMaxStreamDataFrame(r *bytes.Reader, _ protocol.Version) (*MaxStreamDataFrame, error) {
|
2022-07-21 18:50:10 +02:00
|
|
|
sid, err := quicvarint.Read(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
offset, err := quicvarint.Read(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &MaxStreamDataFrame{
|
|
|
|
StreamID: protocol.StreamID(sid),
|
|
|
|
MaximumStreamData: protocol.ByteCount(offset),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-03-26 19:56:06 +01:00
|
|
|
func (f *MaxStreamDataFrame) Append(b []byte, version protocol.Version) ([]byte, error) {
|
2023-05-01 16:05:02 +02:00
|
|
|
b = append(b, maxStreamDataFrameType)
|
2022-10-24 10:20:25 +02:00
|
|
|
b = quicvarint.Append(b, uint64(f.StreamID))
|
|
|
|
b = quicvarint.Append(b, uint64(f.MaximumStreamData))
|
|
|
|
return b, nil
|
2022-07-21 18:50:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Length of a written frame
|
2024-03-26 19:56:06 +01:00
|
|
|
func (f *MaxStreamDataFrame) Length(version protocol.Version) protocol.ByteCount {
|
2022-07-21 18:50:10 +02:00
|
|
|
return 1 + quicvarint.Len(uint64(f.StreamID)) + quicvarint.Len(uint64(f.MaximumStreamData))
|
|
|
|
}
|