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