github.com/sagernet/quic-go@v0.43.1-beta.1/internal/wire/stream_data_blocked_frame.go (about) 1 package wire 2 3 import ( 4 "bytes" 5 6 "github.com/sagernet/quic-go/internal/protocol" 7 "github.com/sagernet/quic-go/quicvarint" 8 ) 9 10 // A StreamDataBlockedFrame is a STREAM_DATA_BLOCKED frame 11 type StreamDataBlockedFrame struct { 12 StreamID protocol.StreamID 13 MaximumStreamData protocol.ByteCount 14 } 15 16 func parseStreamDataBlockedFrame(r *bytes.Reader, _ protocol.Version) (*StreamDataBlockedFrame, 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 &StreamDataBlockedFrame{ 27 StreamID: protocol.StreamID(sid), 28 MaximumStreamData: protocol.ByteCount(offset), 29 }, nil 30 } 31 32 func (f *StreamDataBlockedFrame) Append(b []byte, _ protocol.Version) ([]byte, error) { 33 b = append(b, 0x15) 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 *StreamDataBlockedFrame) Length(protocol.Version) protocol.ByteCount { 41 return 1 + protocol.ByteCount(quicvarint.Len(uint64(f.StreamID))+quicvarint.Len(uint64(f.MaximumStreamData))) 42 }