github.com/apernet/quic-go@v0.43.1-0.20240515053213-5e9e635fd9f0/internal/wire/max_stream_data_frame.go (about) 1 package wire 2 3 import ( 4 "bytes" 5 6 "github.com/apernet/quic-go/internal/protocol" 7 "github.com/apernet/quic-go/quicvarint" 8 ) 9 10 // A MaxStreamDataFrame is a MAX_STREAM_DATA frame 11 type MaxStreamDataFrame struct { 12 StreamID protocol.StreamID 13 MaximumStreamData protocol.ByteCount 14 } 15 16 func parseMaxStreamDataFrame(r *bytes.Reader, _ protocol.Version) (*MaxStreamDataFrame, error) { 17 sid, err := quicvarint.Read(r) 18 if err != nil { 19 return nil, err 20 } 21 offset, err := quicvarint.Read(r) 22 if err != nil { 23 return nil, err 24 } 25 26 return &MaxStreamDataFrame{ 27 StreamID: protocol.StreamID(sid), 28 MaximumStreamData: protocol.ByteCount(offset), 29 }, nil 30 } 31 32 func (f *MaxStreamDataFrame) Append(b []byte, _ protocol.Version) ([]byte, error) { 33 b = append(b, maxStreamDataFrameType) 34 b = quicvarint.Append(b, uint64(f.StreamID)) 35 b = quicvarint.Append(b, uint64(f.MaximumStreamData)) 36 return b, nil 37 } 38 39 // Length of a written frame 40 func (f *MaxStreamDataFrame) Length(protocol.Version) protocol.ByteCount { 41 return 1 + protocol.ByteCount(quicvarint.Len(uint64(f.StreamID))+quicvarint.Len(uint64(f.MaximumStreamData))) 42 }