// converPayload returns payload casted in []byte.
// If the payload is a structure, it's encoded to JSON.
338366
func convertPayload(payload interface{}, onlyFields []string) (body []byte, err error) {
	if payload != nil {
		switch t := payload.(type) {
		case string:
			body = []byte(t)
		case []byte:
			body = t
		default:
			v := reflect.Indirect(reflect.ValueOf(payload))
			if v.Kind() == reflect.Ptr {
				return convertPayload(v.Interface(), onlyFields)
			} else if v.Kind() == reflect.Struct {
				body, err = json.Marshal(buildMap(v, onlyFields))
				if err != nil {
					return body, err
				}
			}
		}
		if DebugLevel == LevelDebugFull {
			log.Println("Body:", string(body))
		}
	}
	return body, err
}
728012
func (o *GetFqdnCacheBadRequest) WithPayload(payload models.Error) *GetFqdnCacheBadRequest {
	o.Payload = payload
	return o
}
448930
func (o *GetPrefilterOK) WithPayload(payload *models.Prefilter) *GetPrefilterOK {
	o.Payload = payload
	return o
}
1138675
func (o *PatchPrefilterOK) WithPayload(payload *models.Prefilter) *PatchPrefilterOK {
	o.Payload = payload
	return o
}
34275
func (o *GetItemsOK) WithPayload(payload []models.Item) *GetItemsOK {
	o.Payload = payload
	return o
}
481708
func (o *ElapseOK) WithPayload(payload io.ReadCloser) *ElapseOK {
	o.Payload = payload
	return o
}
375766
func (m *Message) PopPayload() (data []byte, err error) {
	if m.payload.Empty() {
		err = errors.New("No payload available")
		return
	}

	data = m.payload.Pop().([]byte)

	return
}
472550
func (o *FindTodosOK) WithPayload(payload []*models.Item) *FindTodosOK {
	o.Payload = payload
	return o
}
239968
func (e *Event) ParsePayload() (payload interface{}, err error) {
	switch *e.Type {
	case "CheckRunEvent":
		payload = &CheckRunEvent{}
	case "CheckSuiteEvent":
		payload = &CheckSuiteEvent{}
	case "CommitCommentEvent":
		payload = &CommitCommentEvent{}
	case "CreateEvent":
		payload = &CreateEvent{}
	case "DeleteEvent":
		payload = &DeleteEvent{}
	case "DeployKeyEvent":
		payload = &DeployKeyEvent{}
	case "DeploymentEvent":
		payload = &DeploymentEvent{}
	case "DeploymentStatusEvent":
		payload = &DeploymentStatusEvent{}
	case "ForkEvent":
		payload = &ForkEvent{}
	case "GitHubAppAuthorizationEvent":
		payload = &GitHubAppAuthorizationEvent{}
	case "GollumEvent":
		payload = &GollumEvent{}
	case "InstallationEvent":
		payload = &InstallationEvent{}
	case "InstallationRepositoriesEvent":
		payload = &InstallationRepositoriesEvent{}
	case "IssueCommentEvent":
		payload = &IssueCommentEvent{}
	case "IssuesEvent":
		payload = &IssuesEvent{}
	case "LabelEvent":
		payload = &LabelEvent{}
	case "MarketplacePurchaseEvent":
		payload = &MarketplacePurchaseEvent{}
	case "MemberEvent":
		payload = &MemberEvent{}
	case "MembershipEvent":
		payload = &MembershipEvent{}
	case "MetaEvent":
		payload = &MetaEvent{}
	case "MilestoneEvent":
		payload = &MilestoneEvent{}
	case "OrganizationEvent":
		payload = &OrganizationEvent{}
	case "OrgBlockEvent":
		payload = &OrgBlockEvent{}
	case "PageBuildEvent":
		payload = &PageBuildEvent{}
	case "PingEvent":
		payload = &PingEvent{}
	case "ProjectEvent":
		payload = &ProjectEvent{}
	case "ProjectCardEvent":
		payload = &ProjectCardEvent{}
	case "ProjectColumnEvent":
		payload = &ProjectColumnEvent{}
	case "PublicEvent":
		payload = &PublicEvent{}
	case "PullRequestEvent":
		payload = &PullRequestEvent{}
	case "PullRequestReviewEvent":
		payload = &PullRequestReviewEvent{}
	case "PullRequestReviewCommentEvent":
		payload = &PullRequestReviewCommentEvent{}
	case "PushEvent":
		payload = &PushEvent{}
	case "ReleaseEvent":
		payload = &ReleaseEvent{}
	case "RepositoryEvent":
		payload = &RepositoryEvent{}
	case "RepositoryVulnerabilityAlertEvent":
		payload = &RepositoryVulnerabilityAlertEvent{}
	case "StarEvent":
		payload = &StarEvent{}
	case "StatusEvent":
		payload = &StatusEvent{}
	case "TeamEvent":
		payload = &TeamEvent{}
	case "TeamAddEvent":
		payload = &TeamAddEvent{}
	case "WatchEvent":
		payload = &WatchEvent{}
	}
	err = json.Unmarshal(*e.RawPayload, &payload)
	return payload, err
}
1229968
func (o *PetUploadImageOK) WithPayload(payload *models.APIResponse) *PetUploadImageOK {
	o.Payload = payload
	return o
}
1297942
func (o *GetTaskCommentsDefault) WithPayload(payload *models.Error) *GetTaskCommentsDefault {
	o.Payload = payload
	return o
}
222639
func GetBytesPayload(payl *common.Payload) ([]byte, error) {
	bytes, err := proto.Marshal(payl)
	return bytes, errors.Wrap(err, "error marshaling Payload")
}
857665
func (o *UpdateOneDefault) WithPayload(payload *models.Error) *UpdateOneDefault {
	o.Payload = payload
	return o
}
1289489
func decryptPayload(keys [][]byte, msg []byte, data []byte) ([]byte, error) {
	// Ensure we have at least one byte
	if len(msg) == 0 {
		return nil, fmt.Errorf("Cannot decrypt empty payload")
	}

	// Verify the version
	vsn := encryptionVersion(msg[0])
	if vsn > maxEncryptionVersion {
		return nil, fmt.Errorf("Unsupported encryption version %d", msg[0])
	}

	// Ensure the length is sane
	if len(msg) < encryptedLength(vsn, 0) {
		return nil, fmt.Errorf("Payload is too small to decrypt: %d", len(msg))
	}

	for _, key := range keys {
		plain, err := decryptMessage(key, msg, data)
		if err == nil {
			// Remove the PKCS7 padding for vsn 0
			if vsn == 0 {
				return pkcs7decode(plain, aes.BlockSize), nil
			} else {
				return plain, nil
			}
		}
	}

	return nil, fmt.Errorf("No installed keys could decrypt the message")
}
443589
func (nsPayloads_) asPayloads(docs []payloadDoc) []payload.FullPayloadInfo {
	payloads := make([]payload.FullPayloadInfo, 0, len(docs))
	for _, doc := range docs {
		payloads = append(payloads, nsPayloads.asPayload(doc))
	}
	return payloads
}
935860
func (s *GossipStateProviderImpl) AddPayload(payload *proto.Payload) error {
	return s.addPayload(payload, s.config.BlockingMode)
}
236140
func (o *GetUserByNameOK) WithPayload(payload *models.User) *GetUserByNameOK {
	o.Payload = payload
	return o
}