code: func readMessage(r *http.Request, msg proto.Message) *protocolError {
  	format, err := FormatFromContentType(r.Header.Get(headerContentType))
  	if err != nil {
  		// Spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16
  		return errorf(http.StatusUnsupportedMediaType, "Content-Type header: %s", err)
  	}
  
  	buf, err := ioutil.ReadAll(r.Body)
  	if err != nil {
  		return errorf(http.StatusBadRequest, "could not read body: %s", err)
  	}
  	switch format {
  	// Do not redefine "err" below.
  
  	case FormatJSONPB:
  		err = jsonpb.Unmarshal(bytes.NewBuffer(buf), msg)
  
  	case FormatText:
  		err = proto.UnmarshalText(string(buf), msg)
  
  	case FormatBinary:
  		err = proto.Unmarshal(buf, msg)
  
  	default:
  		panic(fmt.Errorf("impossible: invalid format %v", format))
  	}
  	if err != nil {
  		return errorf(http.StatusBadRequest, "could not decode body: %s", err)
  	}
  	return nil
  }
docs: // readMessage decodes a protobuf message from an HTTP request.
  // Does not close the request body.