dnscrypt-proxy/vendor/github.com/quic-go/quic-go/internal/wire/streams_blocked_frame.go

51 lines
1.3 KiB
Go
Raw Normal View History

2022-07-21 18:50:10 +02:00
package wire
import (
"bytes"
"fmt"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/quicvarint"
2022-07-21 18:50:10 +02:00
)
// A StreamsBlockedFrame is a STREAMS_BLOCKED frame
type StreamsBlockedFrame struct {
Type protocol.StreamType
StreamLimit protocol.StreamNum
}
2024-03-26 19:56:06 +01:00
func parseStreamsBlockedFrame(r *bytes.Reader, typ uint64, _ protocol.Version) (*StreamsBlockedFrame, error) {
2022-07-21 18:50:10 +02:00
f := &StreamsBlockedFrame{}
2023-05-01 16:05:02 +02:00
switch typ {
case bidiStreamBlockedFrameType:
2022-07-21 18:50:10 +02:00
f.Type = protocol.StreamTypeBidi
2023-05-01 16:05:02 +02:00
case uniStreamBlockedFrameType:
2022-07-21 18:50:10 +02:00
f.Type = protocol.StreamTypeUni
}
streamLimit, err := quicvarint.Read(r)
if err != nil {
return nil, err
}
f.StreamLimit = protocol.StreamNum(streamLimit)
if f.StreamLimit > protocol.MaxStreamCount {
return nil, fmt.Errorf("%d exceeds the maximum stream count", f.StreamLimit)
}
return f, nil
}
2024-03-26 19:56:06 +01:00
func (f *StreamsBlockedFrame) Append(b []byte, _ protocol.Version) ([]byte, error) {
2022-07-21 18:50:10 +02:00
switch f.Type {
case protocol.StreamTypeBidi:
2023-05-01 16:05:02 +02:00
b = append(b, bidiStreamBlockedFrameType)
2022-07-21 18:50:10 +02:00
case protocol.StreamTypeUni:
2023-05-01 16:05:02 +02:00
b = append(b, uniStreamBlockedFrameType)
2022-07-21 18:50:10 +02:00
}
2022-10-24 10:20:25 +02:00
b = quicvarint.Append(b, uint64(f.StreamLimit))
return b, nil
2022-07-21 18:50:10 +02:00
}
// Length of a written frame
2024-03-26 19:56:06 +01:00
func (f *StreamsBlockedFrame) Length(_ protocol.Version) protocol.ByteCount {
2022-07-21 18:50:10 +02:00
return 1 + quicvarint.Len(uint64(f.StreamLimit))
}