package wire

import (
	

	
	
)

// A MaxStreamsFrame is a MAX_STREAMS frame
type MaxStreamsFrame struct {
	Type         protocol.StreamType
	MaxStreamNum protocol.StreamNum
}

func parseMaxStreamsFrame( []byte,  FrameType,  protocol.Version) (*MaxStreamsFrame, int, error) {
	 := &MaxStreamsFrame{}
	//nolint:exhaustive // Function will only be called with BidiMaxStreamsFrameType or UniMaxStreamsFrameType
	switch  {
	case FrameTypeBidiMaxStreams:
		.Type = protocol.StreamTypeBidi
	case FrameTypeUniMaxStreams:
		.Type = protocol.StreamTypeUni
	}
	, ,  := quicvarint.Parse()
	if  != nil {
		return nil, 0, replaceUnexpectedEOF()
	}
	.MaxStreamNum = protocol.StreamNum()
	if .MaxStreamNum > protocol.MaxStreamCount {
		return nil, 0, fmt.Errorf("%d exceeds the maximum stream count", .MaxStreamNum)
	}
	return , , nil
}

func ( *MaxStreamsFrame) ( []byte,  protocol.Version) ([]byte, error) {
	switch .Type {
	case protocol.StreamTypeBidi:
		 = append(, byte(FrameTypeBidiMaxStreams))
	case protocol.StreamTypeUni:
		 = append(, byte(FrameTypeUniMaxStreams))
	}
	 = quicvarint.Append(, uint64(.MaxStreamNum))
	return , nil
}

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