github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/internal/wire/streams_blocked_frame.go (about) 1 package wire 2 3 import ( 4 "fmt" 5 6 "github.com/metacubex/quic-go/internal/protocol" 7 "github.com/metacubex/quic-go/quicvarint" 8 ) 9 10 // A StreamsBlockedFrame is a STREAMS_BLOCKED frame 11 type StreamsBlockedFrame struct { 12 Type protocol.StreamType 13 StreamLimit protocol.StreamNum 14 } 15 16 func parseStreamsBlockedFrame(b []byte, typ uint64, _ protocol.Version) (*StreamsBlockedFrame, int, error) { 17 f := &StreamsBlockedFrame{} 18 switch typ { 19 case bidiStreamBlockedFrameType: 20 f.Type = protocol.StreamTypeBidi 21 case uniStreamBlockedFrameType: 22 f.Type = protocol.StreamTypeUni 23 } 24 streamLimit, l, err := quicvarint.Parse(b) 25 if err != nil { 26 return nil, 0, replaceUnexpectedEOF(err) 27 } 28 f.StreamLimit = protocol.StreamNum(streamLimit) 29 if f.StreamLimit > protocol.MaxStreamCount { 30 return nil, 0, fmt.Errorf("%d exceeds the maximum stream count", f.StreamLimit) 31 } 32 return f, l, nil 33 } 34 35 func (f *StreamsBlockedFrame) Append(b []byte, _ protocol.Version) ([]byte, error) { 36 switch f.Type { 37 case protocol.StreamTypeBidi: 38 b = append(b, bidiStreamBlockedFrameType) 39 case protocol.StreamTypeUni: 40 b = append(b, uniStreamBlockedFrameType) 41 } 42 b = quicvarint.Append(b, uint64(f.StreamLimit)) 43 return b, nil 44 } 45 46 // Length of a written frame 47 func (f *StreamsBlockedFrame) Length(_ protocol.Version) protocol.ByteCount { 48 return 1 + protocol.ByteCount(quicvarint.Len(uint64(f.StreamLimit))) 49 }