// Payload gives access to sprite and image information for handlers
// to perform spriting functions.
436322
func Payload(load context.Context) option {
	return func(c *sass) error {
		c.ctx.Payload = load
		return nil
	}
}
790008
func (f *CustomUplinkFunctions) decode(payload []byte, port uint8) (map[string]interface{}, error) {
	if f.Decoder == "" {
		return nil, nil
	}

	env := map[string]interface{}{
		"payload": payload,
		"port":    port,
	}
	code := fmt.Sprintf(`
		%s;
		Decoder(payload.slice(0), port);
	`, f.Decoder)

	value, err := functions.RunCode("Decoder", code, env, timeOut, f.Logger)
	if err != nil {
		return nil, err
	}

	m, ok := value.(map[string]interface{})
	if !ok {
		return nil, errors.NewErrInvalidArgument("Decoder", "does not return an object")
	}
	return m, nil
}
126726
func (sa *StubAPIClient) ImagePull(ctx context.Context, refStr string, options types.ImagePullOptions) (io.ReadCloser, error) {
	sa.called()
	return sa.ImagePullFn(ctx, refStr, options)
}
692367
func (b *Bot) Raw(method string, payload interface{}) ([]byte, error) {
	url := fmt.Sprintf("%s/bot%s/%s", b.URL, b.Token, method)

	var buf bytes.Buffer
	if err := json.NewEncoder(&buf).Encode(payload); err != nil {
		return []byte{}, wrapSystem(err)
	}

	resp, err := b.client.Post(url, "application/json", &buf)
	if err != nil {
		return []byte{}, errors.Wrap(err, "http.Post failed")
	}
	resp.Close = true
	defer resp.Body.Close()
	json, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return []byte{}, wrapSystem(err)
	}

	return json, nil
}
336319
func HandleImage(f func(img image.Image, ctx *ProxyCtx) image.Image) RespHandler {
	return FuncRespHandler(func(resp *http.Response, ctx *ProxyCtx) *http.Response {
		if !RespIsImage.HandleResp(resp, ctx) {
			return resp
		}
		if resp.StatusCode != 200 {
			// we might get 304 - not modified response without data
			return resp
		}
		contentType := resp.Header.Get("Content-Type")

		const kb = 1024
		regret := regretable.NewRegretableReaderCloserSize(resp.Body, 16*kb)
		resp.Body = regret
		img, imgType, err := image.Decode(resp.Body)
		if err != nil {
			regret.Regret()
			ctx.Warnf("%s: %s", ctx.Req.Method+" "+ctx.Req.URL.String()+" Image from "+ctx.Req.RequestURI+"content type"+
				contentType+"cannot be decoded returning original image", err)
			return resp
		}
		result := f(img, ctx)
		buf := bytes.NewBuffer([]byte{})
		switch contentType {
		// No gif image encoder in go - convert to png
		case "image/gif", "image/png":
			if err := png.Encode(buf, result); err != nil {
				ctx.Warnf("Cannot encode image, returning orig %v %v", ctx.Req.URL.String(), err)
				return resp
			}
			resp.Header.Set("Content-Type", "image/png")
		case "image/jpeg", "image/pjpeg":
			if err := jpeg.Encode(buf, result, nil); err != nil {
				ctx.Warnf("Cannot encode image, returning orig %v %v", ctx.Req.URL.String(), err)
				return resp
			}
		case "application/octet-stream":
			switch imgType {
			case "jpeg":
				if err := jpeg.Encode(buf, result, nil); err != nil {
					ctx.Warnf("Cannot encode image as jpeg, returning orig %v %v", ctx.Req.URL.String(), err)
					return resp
				}
			case "png", "gif":
				if err := png.Encode(buf, result); err != nil {
					ctx.Warnf("Cannot encode image as png, returning orig %v %v", ctx.Req.URL.String(), err)
					return resp
				}
			}
		default:
			panic("unhandlable type" + contentType)
		}
		resp.Body = ioutil.NopCloser(buf)
		return resp
	})
}
1323238
func (s *Shape) PayloadRefName() string {
	if name := s.Payload; len(name) != 0 {
		// Root shape
		return name
	}

	for name, ref := range s.MemberRefs {
		if ref.IsEventPayload {
			return name
		}
	}

	return ""
}
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
}
1259326
func (hdr *Handler) Handle(im *imageserver.Image, params imageserver.Params) (*imageserver.Image, error) {
	if !params.Has(param) {
		return im, nil
	}
	params, err := params.GetParams(param)
	if err != nil {
		return nil, err
	}
	if params.Empty() {
		return im, nil
	}
	im, err = hdr.handle(im, params)
	if err != nil {
		if err, ok := err.(*imageserver.ParamError); ok {
			err.Param = param + "." + err.Param
		}
		return nil, err
	}
	return im, nil
}
20265
func (f ServiceFlags) Bytes() []byte {
	x := make([]byte, 8)
	var b [4]byte
	*(*uint32)(unsafe.Pointer(&b)) = uint32(f)
	copy(x[:4], b[:])
	*(*uint32)(unsafe.Pointer(&b)) = ^uint32(0)
	copy(x[4:], b[:])
	return x
}
1084406
func (b *PayloadsBufferImpl) Size() int {
	b.mutex.RLock()
	defer b.mutex.RUnlock()
	return len(b.buf)
}
698819
func (s *MultiTermvectorService) Payloads(payloads bool) *MultiTermvectorService {
	s.payloads = &payloads
	return s
}
865664
func Payload2api(p payload.FullPayloadInfo) params.Payload {
	labels := make([]string, len(p.Labels))
	copy(labels, p.Labels)

	var unitTag string
	if p.Unit != "" {
		unitTag = names.NewUnitTag(p.Unit).String()
	}
	var machineTag string
	if p.Machine != "" {
		machineTag = names.NewMachineTag(p.Machine).String()
	}

	return params.Payload{
		Class:   p.Name,
		Type:    p.Type,
		ID:      p.ID,
		Status:  p.Status,
		Labels:  labels,
		Unit:    unitTag,
		Machine: machineTag,
	}
}
1160470
func (c *DefaultPublisher) PublishAppEvent(appID string, eventType types.EventType, payload interface{}) error {
	key := ApplicationKey{appID, AppEvents, string(eventType)}
	msg, err := json.Marshal(payload)
	if err != nil {
		return fmt.Errorf("Unable to marshal the message payload: %s", err)
	}
	c.publish(key.String(), msg, time.Now())
	return nil
}
889810
func (d *Decoder) Decode(payload []byte, fPort uint8) (map[string]interface{}, bool, error) {
	decoder := protocol.NewDecoder(bytes.NewBuffer(payload))
	d.result = make(map[string]interface{})
	if err := decoder.DecodeUplink(d); err != nil {
		return nil, false, err
	}
	return d.result, true, nil
}
662699
func (b *PayloadsBufferImpl) Pop() *proto.Payload {
	b.mutex.Lock()
	defer b.mutex.Unlock()

	result := b.buf[b.Next()]

	if result != nil {
		// If there is such sequence in the buffer need to delete it
		delete(b.buf, b.Next())
		// Increment next expect block index
		atomic.AddUint64(&b.next, 1)

		b.drainReadChannel()

	}

	return result
}
126677
func (cs *ChaChaStream) Unpack(payload string) []byte {
	decoded, _ := base64.StdEncoding.DecodeString(payload)

	data := make([]byte, len(decoded))
	cs.cipher.XORKeyStream(data, decoded)
	return data
}
444383
func (client *Client) Payload(command Command) (url.Values, error) {
	params, err := prepareValues("", command)
	if err != nil {
		return nil, err
	}
	if hookReq, ok := command.(onBeforeHook); ok {
		if err := hookReq.onBeforeSend(params); err != nil {
			return params, err
		}
	}
	params.Set("apikey", client.APIKey)
	params.Set("command", client.APIName(command))
	params.Set("response", "json")

	if params.Get("expires") == "" && client.Expiration >= 0 {
		params.Set("signatureversion", "3")
		params.Set("expires", time.Now().Add(client.Expiration).Local().Format("2006-01-02T15:04:05-0700"))
	}

	return params, nil
}