package wire

import (
	

	
	
)

// A StreamsBlockedFrame is a STREAMS_BLOCKED frame
type StreamsBlockedFrame struct {
	Type        protocol.StreamType
	StreamLimit protocol.StreamNum
}

func parseStreamsBlockedFrame( []byte,  FrameType,  protocol.Version) (*StreamsBlockedFrame, int, error) {
	 := &StreamsBlockedFrame{}
	//nolint:exhaustive // This will only be called with a BidiStreamBlockedFrameType or a UniStreamBlockedFrameType.
	switch  {
	case FrameTypeBidiStreamBlocked:
		.Type = protocol.StreamTypeBidi
	case FrameTypeUniStreamBlocked:
		.Type = protocol.StreamTypeUni
	}
	, ,  := quicvarint.Parse()
	if  != nil {
		return nil, 0, replaceUnexpectedEOF()
	}
	.StreamLimit = protocol.StreamNum()
	if .StreamLimit > protocol.MaxStreamCount {
		return nil, 0, fmt.Errorf("%d exceeds the maximum stream count", .StreamLimit)
	}
	return , , nil
}

func ( *StreamsBlockedFrame) ( []byte,  protocol.Version) ([]byte, error) {
	switch .Type {
	case protocol.StreamTypeBidi:
		 = append(, byte(FrameTypeBidiStreamBlocked))
	case protocol.StreamTypeUni:
		 = append(, byte(FrameTypeUniStreamBlocked))
	}
	 = quicvarint.Append(, uint64(.StreamLimit))
	return , nil
}

// Length of a written frame
func ( *StreamsBlockedFrame) ( protocol.Version) protocol.ByteCount {
	return 1 + protocol.ByteCount(quicvarint.Len(uint64(.StreamLimit)))
}