// eatBytesAndGetPayloadError fast-forwards the reader to the payload, reads
// off the payload, and wraps the provided error with the payload in an
// AuthHeaderError.
513071
func eatBytesAndGetPayloadError(r io.Reader, n uint32, e error) error {
	written, err := io.CopyN(ioutil.Discard, r, int64(n))
	if err != nil {
		return ErrReadingBody
	}
	if written != int64(n) {
		return ErrReadingBody
	}
	payload, err := ReadLengthAndBytes(r)
	if err != nil {
		return err
	}
	return &AuthHeaderError{e, payload}
}
322036
func (h HandlerPayloadMarshal) MarshalPayload(w io.Writer, v interface{}) error {
	req := request.New(
		aws.Config{},
		metadata.ClientInfo{},
		request.Handlers{},
		nil,
		&request.Operation{HTTPMethod: "GET"},
		v,
		nil,
	)

	h.Marshalers.Run(req)

	if req.Error != nil {
		return req.Error
	}

	io.Copy(w, req.GetBody())

	return nil
}
306023
func writeDispatchPayload(base, filename string, payload []byte) error {
	renderTo := filepath.Join(base, filename)
	decoded, err := snappy.Decode(nil, payload)
	if err != nil {
		return err
	}

	if err := os.MkdirAll(filepath.Dir(renderTo), 0777); err != nil {
		return err
	}

	return ioutil.WriteFile(renderTo, decoded, 0777)
}
1095535
func (pl *Payload) ReadBinary(r io.Reader) error {
	dec := gob.NewDecoder(r)
	return pl.DecodeBinary(dec)
}
880029
func MakePayloadHeader(ch *cb.ChannelHeader, sh *cb.SignatureHeader) *cb.Header {
	return &cb.Header{
		ChannelHeader:   MarshalOrPanic(ch),
		SignatureHeader: MarshalOrPanic(sh),
	}
}
66108
func getError(body []byte) error {
	var errResp ErrorResponse
	if err := json.Unmarshal(body, &errResp); err != nil {
		return err
	}
	return errResp.Error
}
580292
func (s3) ParseHTTP(h http.Header) (err error) {
	if h.Get(SSEHeader) != SSEAlgorithmAES256 {
		err = ErrInvalidEncryptionMethod
	}
	return
}
818087
func (iter *Iterator) SkipAndReturnBytes() []byte {
	iter.startCapture(iter.head)
	iter.Skip()
	return iter.stopCapture()
}
755535
func (q *Query) GetPayload() string {
	j, err := json.Marshal(struct {
		Encoding string `json:"encoding"`
		Method   string `json:"method"`
		NS       string `json:"key"`
	}{
		Encoding: q.encoding,
		Method:   q.method,
		NS:       q.ns,
	})
	sharedutils.CheckError(err)
	return string(j) + "\n"
}
76816
func GetBytesProposalResponse(pr *peer.ProposalResponse) ([]byte, error) {
	respBytes, err := proto.Marshal(pr)
	return respBytes, errors.Wrap(err, "error marshaling ProposalResponse")
}
952403
func (o *GetHealthzOK) WithPayload(payload *models.StatusResponse) *GetHealthzOK {
	o.Payload = payload
	return o
}
1092620
func readAuthHeaderV1(r io.Reader) (sender Identity, tstamp time.Time, payload []byte, err error) {

	// Read in the length of everything up to the payload length
	var allLen uint32
	if err = binary.Read(r, byteOrder, &allLen); err != nil {
		return
	}

	// Read the signature
	var sig = make([]byte, 256)
	if err = binary.Read(r, byteOrder, sig); err != nil {
		return
	}

	var (
		signable  bytes.Buffer
		remaining = allLen
	)

	// Read into a tee reader so we can verify the signature on the original
	// data later
	teed := io.TeeReader(r, &signable)

	// Read and validate the timestamp
	var ts timestamp
	remaining -= uint32(binary.Size(ts))
	if err = binary.Read(teed, byteOrder, &ts); err != nil {
		err = eatBytesAndGetPayloadError(teed, remaining, err)
		return
	}
	tstamp = time.Unix(int64(ts), 0).UTC()
	cutoff := jwt.TimeFunc().UTC().Add(-ClockDriftDelta)
	if tstamp.Before(cutoff) {
		err = eatBytesAndGetPayloadError(teed, remaining, ErrHeaderExpired)
		return
	}

	// Read the token and validate it
	token := make([]byte, int(remaining))
	if err = binary.Read(teed, byteOrder, &token); err != nil {
		err = eatBytesAndGetPayloadError(teed, 0, err)
		return
	}
	sender, err = ParseJWTIdentity(string(token))
	if err != nil {
		err = eatBytesAndGetPayloadError(teed, 0, err)
		return
	}
	if sender == nil {
		err = eatBytesAndGetPayloadError(teed, 0, ErrBadToken)
		return
	}

	payload, err = ReadLengthAndBytes(teed)
	if err != nil {
		return
	}

	// Freeze the signable content for verification. Even though we don't plan
	// to read from the tee reader anymore, might as well be clear as to our
	// intentions.
	signableContent := signable.Bytes()

	// Verify the signature of the signable content
	var verifier Verifier
	verifier, err = sender.Verifier()
	if err != nil {
		err = &AuthHeaderError{err, payload}
		return
	}
	err = verifier.Verify(signableContent, sig)
	if err != nil {
		err = &AuthHeaderError{err, payload}
	}
	return
}
884083
func (s *Wrapper) GetReadError() error {
	s.RLock()
	defer s.RUnlock()
	return s.readErr
}
386434
func (m *InMessage) ConsumeBytes(n uintptr) (b []byte) {
	if n > m.Len() {
		return
	}

	b = m.remaining[:n]
	m.remaining = m.remaining[n:]

	return
}
881573
func GetPayloadList(ctx context.Context, requester Requester, r PayloadListRequest) (PayloadList, error) {
	req, err := PrepGetPayloadList(r)
	if err != nil {
		return PayloadList{}, err
	}

	resp, err := requester(ctx, req)
	if err != nil {
		return PayloadList{}, err
	}
	defer resp.Body.Close()

	return NewPayloadList(resp.Body)
}
1165711
func (r *Update) binaryGet(serializedData []byte) error {
	if len(serializedData) < minimumUpdateDataLength {
		return NewErrorf(ErrNothingToReturn, "chunk less than %d bytes cannot be a feed update chunk", minimumUpdateDataLength)
	}
	dataLength := len(serializedData) - idLength - headerLength
	// at this point we can be satisfied that we have the correct data length to read

	var cursor int

	// deserialize Header
	r.Header.Version = serializedData[cursor]                                      // extract the protocol version
	copy(r.Header.Padding[:headerLength-1], serializedData[cursor+1:headerLength]) // extract the padding
	cursor += headerLength

	if err := r.ID.binaryGet(serializedData[cursor : cursor+idLength]); err != nil {
		return err
	}
	cursor += idLength

	data := serializedData[cursor : cursor+dataLength]
	cursor += dataLength

	// now that all checks have passed, copy data into structure
	r.data = make([]byte, dataLength)
	copy(r.data, data)

	return nil

}
583577
func (o *GetHealthzFailed) WithPayload(payload models.Error) *GetHealthzFailed {
	o.Payload = payload
	return o
}