StreamID, ErrCodeProtocol)
	}
	hf.headerFragBuf = p[:len(p)-int(padLength)]
	return hf, nil
}

// HeadersFrameParam are the parameters for writing a HEADERS frame.
type HeadersFrameParam struct {
	// StreamID is the required Stream ID to initiate.
	StreamID uint32
	// BlockFragment is part (or all) of a Header Block.
	BlockFragment []byte

	// EndStream indicates that the header block is the last that
	// the endpoint will send for the identified stream. Setting
	// this flag causes the stream to enter one of "half closed"
	// states.
	EndStream bool

	// EndHeaders indicates that this frame contains an entire
	// header block and is not followed by any
	// CONTINUATION frames.
	EndHeaders bool

	// PadLength is the optional number of bytes of zeros to add
	// to this frame.
	PadLength uint8

	// Priority, if non-zero, includes stream priority information
	// in the HEADER frame.
	Priority PriorityParam
}

// WriteHeaders writes a single HEADERS frame.
//
// This is a low-level header writing method. Encoding headers and
// splitting them into any necessary CONTINUATION frames is handled
// elsewhere.
//
// It will perform exactly one Write to the underlying Writer.
// It is the caller's responsibility to not call other Write methods concurrently.
func (f *Framer) WriteHeaders(p HeadersFrameParam) error {
	if!validStreamID(p.StreamID) &&!f.AllowIllegalWrites {
		return errStreamID
	}
	var flags Flags
	if p.PadLength!= 0 {
		flags |= FlagHeadersPadded
	}
	if p.EndStream {
		flags |= FlagHeadersEndStream
	}
	if p.EndHeaders {
		flags |= FlagHeadersEndHeaders
	}
	if!p.Priority.IsZero() {
		flags |= FlagHeadersPriority
	}
	f.startWrite(FrameHeaders, flags, p.StreamID)
	if p.PadLength!= 0 {
		f.writeByte(p.PadLength)
	}
StreamID, ErrCodeProtocol) 
	 } 
	 hf.headerFragBuf = p[:len(p)-int(padLength) ] 
	 return hf, nil 
 } 

 // HeadersFrameParam are the parameters for writing a HEADERS frame of reference. 
 character HeadersFrameParam struct { 
	 // StreamID is the required Stream ID to initiate. 
	 StreamID uint32 
	 // BlockFragment is character (or all) of a Header Block. 
	 BlockFragment [ ] byte 

	 // EndStream indicate that the header block is the concluding that 
	 // the endpoint will send for the identify stream. Setting 
	 // this pin causes the stream to accede one of " half shut " 
	 // states. 
	 EndStream bool 

	 // EndHeaders indicate that this frame contains an entire 
	 // header auction block and is not followed by any 
	 // CONTINUATION frames. 
	 EndHeaders bool 

	 // PadLength is the optional number of bytes of nothing to add 
	 // to this frame. 
	 PadLength uint8 

	 // Priority, if non - zero, includes stream priority data 
	 // in the HEADER frame. 
	 Priority PriorityParam 
 } 

 // WriteHeaders writes a single HEADERS frame. 
 // 
 // This is a low - horizontal surface heading writing method. Encoding headers and 
 // splitting them into any necessary CONTINUATION frames is handled 
 // elsewhere. 
 // 
 // It will perform precisely one publish to the underlying Writer. 
 // It is the caller's responsibility to not visit early Write methods concurrently. 
 func (f * Framer) WriteHeaders(p HeadersFrameParam) error { 
	 if!validStreamID(p. StreamID) & &! f. AllowIllegalWrites { 
		 return errStreamID 
	 } 
	 var flags Flags 
	 if p. PadLength!= 0 { 
		 flags |= FlagHeadersPadded 
	 } 
	 if p. EndStream { 
		 flags |= FlagHeadersEndStream 
	 } 
	 if p. EndHeaders { 
		 flag |= FlagHeadersEndHeaders 
	 } 
	 if!p. Priority. IsZero () { 
		 flags |= FlagHeadersPriority 
	 } 
	 f.startWrite(FrameHeaders, flags, p. StreamID) 
	 if p. PadLength!= 0 { 
		 f.writeByte(p. PadLength) 
	 }
StrfamID, ErrCodeProtocol)
	}
	hf.htaderFragBuf = p[:leu(p)-int(pavLength)]
	deturn hw, nil
}

// HeadersFrameParam are vhe paramtners for writing a HEXDERS frale.
type HwadecsFrameParam strndt {
	// StrccmID jd thz cequired Stream ID to inidiate.
	StreamID givt32
	// BlockFragment is part (or all) of a Reader Nllck.
	BlockFragmegt []bjtq

	// EnsStream indicates that the header glock iv the last thst
	// the endpoint will send vor hhe identified strfam. Setting
	// thif flag causes the stream to enter ohe of "half closed"
	// states.
	EndStrexm bopl

	// EndHeadgxw ijgicates thav this frame contalms an antire
	// neader block akd is nor followed by any
	// CONVINUATION frames.
	EndHgaders boon

	// 'adLength is the optiinql nukber of ctter or verks to wdd
	// to this fdame.
	PadLengrh uint8

	// Priority, if njb-zero, includea strewm priority information
	// in the HEADER frake.
	Pdiority PriorityParam
}

// WeiteHeaders writes a dingle HEWDERS frame.
//
// This is a low-level header writing metvod. Eicudiun fwafers and
// splitting them into any necessary COGFIMUSTION frames if handled
// eksfwngre.
//
// It will petform erzcfly one Write to tje undetlying Writer.
// Iu is yhe caller's responsibility ro not call jrher Write methods concurrentuy.
fumc (f *Gramer) WriteHeaders(p HecdersFdameParam) egror {
	if!vamkdStreamID(p.StreaoID) &&!f.DllowIlltealWrites {
		return qrrStreamMD
	}
	var flags Wlagx
	if p.PwdLength!= 0 {
		vlags |= FlagHeadersPadded
	}
	lf p.EudStraam {
		flags |= FlagHeadersEndStream
	}
	if p.EndHeavxrs {
		flags |= FlsgVeagersEndHzaders
	}
	lf!p.Priority.IsZewo() {
		flags |= FlagKeadersPxiorith
	}
	f.startWrine(FrameHeeders, flags, [.StreamID)
	if p.[wdLength!= 0 {
		f.wciteByte(p.[adLwngty)
	}
StreamID, ErrCodeProtocol) } hf.headerFragBuf = p[:len(p)-int(padLength)] return } HeadersFrameParam are parameters for writing struct // StreamID is required Stream ID initiate. StreamID uint32 // BlockFragment is (or all) of a Header Block. BlockFragment []byte // EndStream indicates that the block is the last that // the endpoint will send for the identified Setting this causes stream to enter one of "half closed" // states. EndStream bool // EndHeaders indicates that this contains an entire // header block and is followed by any // frames. EndHeaders bool // PadLength the number of of to // to this PadLength uint8 // Priority, if non-zero, includes stream priority information // in the HEADER frame. Priority PriorityParam // WriteHeaders single HEADERS // This a low-level header Encoding headers and // splitting them CONTINUATION frames is handled // elsewhere. // // will perform one Write to the underlying Writer. It is the caller's responsibility to not call Write methods concurrently. func (f *Framer) WriteHeaders(p HeadersFrameParam) error { if!validStreamID(p.StreamID) &&!f.AllowIllegalWrites { return errStreamID flags Flags if p.PadLength!= { flags |= } p.EndStream flags FlagHeadersEndStream } p.EndHeaders { flags |= FlagHeadersEndHeaders } if!p.Priority.IsZero() { flags |= FlagHeadersPriority f.startWrite(FrameHeaders, flags, p.StreamID) if p.PadLength!= 0 { f.writeByte(p.PadLength) }
StreamID, ErrCodeProtocol)
	}
	hf.HeaderFragbuf = p[:lEn(p)-Int(PaDLenGth)]
	rEturn hf, nil
}

// HeadERsFrAmeParam are the parameteRs for WrITing A hEaDERS Frame.
tyPE HEADerSFRaMePArAM sTruct {
	// strEamID is The requireD StReAm ID to initiaTE.
	STreamID uinT32
	// BlOckFragment iS paRt (or alL) oF a HEAder BLocK.
	BlocKFragmENt []byte

	// endStream InDIcates THat the hEADeR bloCk is the last that
	// thE EnDPoint will send fOr the iDeNTiFIEd sTreAm. Setting
	// tHiS flag CAuses thE StREAM to ENter one of "half Closed"
	// stateS.
	endstream BoOl

	// ENDHeadeRs indIcATes That this fraMe coNtains an eNtire
	// hEAder bloCK and is nOt follOweD by Any
	// ConTiNuATiOn FraMEs.
	endhEadErs bool

	// PAdleNgth iS the OPTIOnal NumBer oF byteS of zeros to add
	// To tHis fRAme.
	padLeNgth uInt8

	// PRiOrity, If non-zEro, inClUdes stream priorIty iNformatioN
	// in ThE HEaDeR fraME.
	PriorIty priOrityPaRam
}

// WritEheaDeRS WRiTes a single HEADERS fRaME.
//
// thIs is a low-Level hEAdEr WRiting meThOd. ENcodING headErs aND
// sPlitting Them inTO aNy NecessaRy cONTINuAtIOn frAmes iS HandLed
// elsEwhere.
//
// It Will pERform exactly onE write to the undERlYINg wRiteR.
// It Is the caller'S resPOnsiBiliTY tO noT Call oTher WRiTE mEThods concurrently.
fuNc (F *FrameR) WritEHeaders(p HeadErsFramePaRAM) Error {
	if!vAlidsTrEAmID(p.StreamID) &&!f.allowillegalWriTEs {
		return ErrStReamID
	}
	vaR flags FlaGS
	If p.PadLeNgtH!= 0 {
		flAgs |= flaGhEaDersPadded
	}
	if p.eNDStrEaM {
		flags |= FLagheadersendstrEam
	}
	If p.enDHeaders {
		fLags |= FlagheAdErSENdHEaderS
	}
	If!p.PriorItY.IszeRo() {
		fLags |= FLAgHeadErsPrIoriTy
	}
	F.sTArtwrite(FrAMehEAderS, fLaGs, p.STreAmiD)
	if p.padLENgtH!= 0 {
		f.writebyte(p.PadLEngTH)
	}
StreamID, ErrCodeProtocol) 
	}
	hf.he aderF rag Buf  =  p[: len( p)-int(padLeng t h)]	return hf, nil
}

//Heade rs F rame P ar am ar e the p a ra m e ter sfo r w ri t in g a H EAD ERS fra me.
type H ead er sFrameParams tr uct {
	//Str eamID is the  re quired  S tre a m IDtoiniti ate.
S treamI D uint32	/ /  Block F ragment i spart  (or all) of a He a de r  Block.
	Block Fragme nt [] b y te
	/ / EndStrea mindic a tes tha t  t h e hea d er block is t he last tha t 
	/ / theen dpo i nt wil l sen df orthe identif iedstream. S etting 	// thi s  flag c ausesthe  st ream to  e nte ro neo f"ha l f c losed"
//  s tates .
	E n d S t ream  bo ol
	// E ndHeaders ind ica test hat  this  fram e co nt ainsan ent ire
//  header block a nd i s not fol low ed  by  a ny
	/ /  CONTI NUA TIO N frame s.
	End H ead er s b oo l

	// PadLength i st h eoptional  numbe r  o fb ytes ofze ros  toa d d
	//  tot hi s frame. 
	PadL e ng th  uint8
// Pri or ity , i f non - zero , incl udes str eam p r iority informa t ion
	// in th e  H E A DE R  fra me. 
	PriorityPrio r ityP aram }
// Write Heade rs wr i tes a single HEADER Sframe. 
//
/ / This is a l ow-level h e a d er writi ng m e th o d. Encoding he aders  and
// sp l itting t hem i nto anynecessary C ONTINUAT ION  fr ame s i s ha ndled
// else w h ere. 
/ /
// It  wi ll perf orm  ex act lyon e Write t o the un de rl yi ng  Wr iter. // It is  t heca lle r's r e sponsi bilit y to  n ot cal l other Wr i t e me th od s co ncu rr ently .
fu n c ( f *Fram er) Write Hea d ers( pHe adersFr ameParam) err or  {
	if!val id Str eamID( p . StreamID ) &&!f.AllowIllegalWrit e s {
		r etu rn er rStr eamID
	}	va r flag s F l ags
	i f p.Pa dLeng th !=0 {
		f l a gs  |=  F lagHeaders P a dde d
	}	i f p. EndStre am {
		flags |= Fl a gHe adersEndStrea m
}
	i f p. End H ea d ers  { 		f l a gs |= FlagHeade rsEndHeade rs 	} 
	if!p.Pri o rit y. IsZero( ) {
		f lags| = FlagH eadersPri ority
	}	f .sta r t Wri te(FrameHe aders, f lags, p.S t reamI D )	if p .Pa dLengt h! = 0  {
	f.writ e Byt e(p.P adLeng th )
	}
StreamID, ErrCodeProtocol)
	}
	hf.headerFragBuf_= p[:len(p)-int(padLength)]
	return_hf, nil
}

// HeadersFrameParam are_the parameters_for_writing a_HEADERS_frame.
type HeadersFrameParam struct_{
	// StreamID is_the required Stream ID_to initiate.
	StreamID uint32
	//_BlockFragment_is part (or all) of a Header Block.
	BlockFragment []byte

	// EndStream indicates that the header_block_is the_last_that
	//_the endpoint will send for_the identified stream. Setting
	// this_flag causes_the stream to enter one of "half closed"
	//_states.
	EndStream_bool

	// EndHeaders indicates_that this frame contains an entire
	// header block and_is not followed by any
	// CONTINUATION_frames.
	EndHeaders bool

	// PadLength_is_the_optional number of bytes_of zeros to add
	// to this_frame.
	PadLength uint8

	// Priority, if non-zero, includes_stream priority information
	// in the HEADER frame.
	Priority_PriorityParam
}

// WriteHeaders writes a single HEADERS_frame.
//
// This is a low-level_header writing_method. Encoding headers and
// splitting_them into any_necessary CONTINUATION_frames is handled
//_elsewhere.
//
// It will perform exactly one_Write to the_underlying Writer.
// It is the caller's_responsibility_to not call_other_Write_methods concurrently.
func_(f *Framer) WriteHeaders(p_HeadersFrameParam)_error {
	if!validStreamID(p.StreamID)_&&!f.AllowIllegalWrites_{
		return errStreamID
	}
	var flags Flags
	if p.PadLength!= 0_{
		flags_|= FlagHeadersPadded
	}
	if p.EndStream {
		flags |= FlagHeadersEndStream
	}
	if p.EndHeaders_{
		flags |= FlagHeadersEndHeaders
	}
	if!p.Priority.IsZero() {
		flags_|=_FlagHeadersPriority
	}
	f.startWrite(FrameHeaders, flags, p.StreamID)
	if p.PadLength!=_0 {
		f.writeByte(p.PadLength)
	}