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