code: func (c *channel) WriteExtended(data []byte, extendedCode uint32) (n int, err error) {
  	if c.sentEOF {
  		return 0, io.EOF
  	}
  	// 1 byte message type, 4 bytes remoteId, 4 bytes data length
  	opCode := byte(msgChannelData)
  	headerLength := uint32(9)
  	if extendedCode > 0 {
  		headerLength += 4
  		opCode = msgChannelExtendedData
  	}
  
  	c.writeMu.Lock()
  	packet := c.packetPool[extendedCode]
  	// We don't remove the buffer from packetPool, so
  	// WriteExtended calls from different goroutines will be
  	// flagged as errors by the race detector.
  	c.writeMu.Unlock()
  
  	for len(data) > 0 {
  		space := min(c.maxRemotePayload, len(data))
  		if space, err = c.remoteWin.reserve(space); err != nil {
  			return n, err
  		}
  		if want := headerLength + space; uint32(cap(packet)) < want {
  			packet = make([]byte, want)
  		} else {
  			packet = packet[:want]
  		}
  
  		todo := data[:space]
  
  		packet[0] = opCode
  		binary.BigEndian.PutUint32(packet[1:], c.remoteId)
  		if extendedCode > 0 {
  			binary.BigEndian.PutUint32(packet[5:], uint32(extendedCode))
  		}
  		binary.BigEndian.PutUint32(packet[headerLength-4:], uint32(len(todo)))
  		copy(packet[headerLength:], todo)
  		if err = c.writePacket(packet); err != nil {
  			return n, err
  		}
  
  		n += len(todo)
  		data = data[len(todo):]
  	}
  
  	c.writeMu.Lock()
  	c.packetPool[extendedCode] = packet
  	c.writeMu.Unlock()
  
  	return n, err
  }
docs: // WriteExtended writes data to a specific extended stream. These streams are
  // used, for example, for stderr.