code: func writeMessage(c context.Context, w http.ResponseWriter, msg proto.Message, format Format) {
  	if msg == nil {
  		panic("msg is nil")
  	}
  
  	var body []byte
  	var err error
  	switch format {
  	case FormatBinary:
  		body, err = proto.Marshal(msg)
  
  	case FormatJSONPB:
  		var buf bytes.Buffer
  		buf.WriteString(JSONPBPrefix)
  		m := jsonpb.Marshaler{}
  		err = m.Marshal(&buf, msg)
  		if err == nil {
  			_, err = buf.WriteRune('\n')
  		}
  		body = buf.Bytes()
  
  	case FormatText:
  		var buf bytes.Buffer
  		err = proto.MarshalText(&buf, msg)
  		body = buf.Bytes()
  
  	default:
  		panic(fmt.Errorf("impossible: invalid format %d", format))
  
  	}
  	if err != nil {
  		writeError(c, w, withCode(err, codes.Internal))
  		return
  	}
  
  	w.Header().Set(HeaderGRPCCode, strconv.Itoa(int(codes.OK)))
  	w.Header().Set(headerContentType, format.MediaType())
  	w.Header().Set("X-Content-Type-Options", "nosniff")
  	if _, err := w.Write(body); err != nil {
  		logging.WithError(err).Errorf(c, "prpc: failed to write response body")
  	}
  }
docs: // writeMessage writes msg to w in the specified format.
  // c is used to log errors.
  // panics if msg is nil.