// Decode will decode the body into the given resource, and parse the hypermedia
// relations.  This is meant to be called after an HTTP request, and will close
// the response body.  The decoder is set from the response's MediaType.
549197
func (r *Response) Decode(resource interface{}) error {
	if r.BodyClosed {
		return errors.New("Body is already closed")
	}

	if r.MediaType == nil {
		return errors.New("No media type for this response")
	}

	if r.ResponseError != nil {
		return errors.New("Existing Response error")
	}

	defer r.Body.Close()
	r.BodyClosed = true

	r.ResponseError = r.DecodeFrom(resource, r.Body)
	if r.ResponseError == nil {
		rels := hypermedia.Rels(resource)
		if err := r.Cacher.SetRels(r.Request, rels); err == nil {
			if cachedResource, ok := resource.(hypermedia.CachedResource); ok {
				cachedResource.CacheRels(rels)
			}
		}
	}

	return r.ResponseError
}
477802
func (sp *Subscribe) Decode(src []byte) (int, error) {
	total := 0

	// decode header
	hl, _, rl, err := headerDecode(src[total:], SUBSCRIBE)
	total += hl
	if err != nil {
		return total, err
	}

	// check buffer length
	if len(src) < total+2 {
		return total, makeError(sp.Type(), "insufficient buffer size, expected %d, got %d", total+2, len(src))
	}

	// read packet id
	sp.ID = ID(binary.BigEndian.Uint16(src[total:]))
	total += 2

	// check packet id
	if !sp.ID.Valid() {
		return total, makeError(sp.Type(), "packet id must be grater than zero")
	}

	// reset subscriptions
	sp.Subscriptions = sp.Subscriptions[:0]

	// calculate number of subscriptions
	sl := int(rl) - 2

	for sl > 0 {
		// read topic
		t, n, err := readLPString(src[total:], sp.Type())
		total += n
		if err != nil {
			return total, err
		}

		// check buffer length
		if len(src) < total+1 {
			return total, makeError(sp.Type(), "insufficient buffer size, expected %d, got %d", total+1, len(src))
		}

		// read qos
		qos := QOS(src[total])
		if !qos.Successful() {
			return total, makeError(sp.Type(), "invalid QOS level (%d)", qos)
		}

		// read qos and add subscription
		sp.Subscriptions = append(sp.Subscriptions, Subscription{t, qos})
		total++

		// decrement counter
		sl = sl - n - 1
	}

	// check for empty subscription list
	if len(sp.Subscriptions) == 0 {
		return total, makeError(sp.Type(), "empty subscription list")
	}

	return total, nil
}
1165119
func Decode(in string) (image Image, err error) {
	repo, tag := parseRepositoryTag(in)
	image.Registry, image.Repository = splitRepository(repo)

	if strings.Contains(tag, ":") {
		image.Digest = tag
	} else {
		image.Tag = tag
	}

	if image.Repository == "" {
		err = ErrInvalidImage
		return
	}

	return
}
1324880
func decodeBody(req *http.Request, out interface{}, cb func(interface{}) error) error {
	// This generally only happens in tests since real HTTP requests set
	// a non-nil body with no content. We guard against it anyways to prevent
	// a panic. The EOF response is the same behavior as an empty reader.
	if req.Body == nil {
		return io.EOF
	}

	var raw interface{}
	dec := json.NewDecoder(req.Body)
	if err := dec.Decode(&raw); err != nil {
		return err
	}

	// Invoke the callback prior to decode
	if cb != nil {
		if err := cb(raw); err != nil {
			return err
		}
	}

	decodeConf := &mapstructure.DecoderConfig{
		DecodeHook: mapstructure.ComposeDecodeHookFunc(
			mapstructure.StringToTimeDurationHookFunc(),
			stringToReadableDurationFunc(),
		),
		Result: &out,
	}

	decoder, err := mapstructure.NewDecoder(decodeConf)
	if err != nil {
		return err
	}

	return decoder.Decode(raw)
}
859354
func Decode(context *qor.Context, result interface{}, res Resourcer) error {
	var errors qor.Errors
	var err error
	var metaValues *MetaValues
	metaors := res.GetMetas([]string{})

	if strings.Contains(context.Request.Header.Get("Content-Type"), "json") {
		metaValues, err = ConvertJSONToMetaValues(context.Request.Body, metaors)
		context.Request.Body.Close()
	} else {
		metaValues, err = ConvertFormToMetaValues(context.Request, metaors, "QorResource.")
	}

	errors.AddError(err)
	errors.AddError(DecodeToResource(res, result, metaValues, context).Start())
	return errors
}
315683
func (j *jsonEncoder) Decode(data []byte, v interface{}) error {
	return json.Unmarshal(data, v)
}
219314
func (codec *StringCodec) Decode(in *ByteBuf) (bool, interface{}, error) {
	value := string(in.GetMarkedRemindData())
	in.MarkedBytesReaded()
	return true, value, nil
}
336970
func (d *Decoder) Decode(v interface{}) (int, error) {
	if v == nil {
		msg := "can't unmarshal to nil interface"
		return 0, unmarshalError("Unmarshal", ErrNilInterface, msg, nil,
			nil)
	}

	vv := reflect.ValueOf(v)
	if vv.Kind() != reflect.Ptr {
		msg := fmt.Sprintf("can't unmarshal to non-pointer '%v' - use "+
			"& operator", vv.Type().String())
		err := unmarshalError("Unmarshal", ErrBadArguments, msg, nil, nil)
		return 0, err
	}
	if vv.IsNil() && !vv.CanSet() {
		msg := fmt.Sprintf("can't unmarshal to unsettable '%v' - use "+
			"& operator", vv.Type().String())
		err := unmarshalError("Unmarshal", ErrNotSettable, msg, nil, nil)
		return 0, err
	}

	return d.decode(vv)
}
621959
func Decode(r io.Reader) (m image.Image, err error) {
	data, err := ioutil.ReadAll(r)
	if err != nil {
		return
	}
	if m, err = DecodeRGBA(data); err != nil {
		return
	}
	return
}
678611
func (j *JSON) Decode(octets []byte) ([]codec.Span, error) {
	var spans []span
	err := json.Unmarshal(octets, &spans)
	if err != nil {
		return nil, err
	}

	res := make([]codec.Span, len(spans))
	for i := range spans {
		if err := spans[i].Validate(); err != nil {
			return nil, err
		}
		res[i] = &spans[i]
	}
	return res, nil
}
299714
func (pp *Pubcomp) Decode(src []byte) (int, error) {
	n, pid, err := identifiedDecode(src, PUBCOMP)
	pp.ID = pid
	return n, err
}
1295680
func (resp *AppendEntriesResponse) Decode(r io.Reader) (int, error) {
	data, err := ioutil.ReadAll(r)
	if err != nil {
		return -1, err
	}

	resp.pb = new(protobuf.AppendEntriesResponse)
	if err := proto.Unmarshal(data, resp.pb); err != nil {
		return -1, err
	}

	return len(data), nil
}
250177
func Decode(cookie *http.Cookie, secret string) string {
	return DecodeStr(cookie.Value, secret)
}
1154054
func (m *MediaType) Decoder(body io.Reader) (Decoder, error) {
	if decfunc, ok := decoders[m.Format]; ok {
		return decfunc(body), nil
	}
	return nil, fmt.Errorf("No decoder found for format %s (%s)", m.Format, m.String())
}
726333
func decode(b64 []byte) []byte {
	var b []byte

	// Allocate a single block of memory large enough to store the Base64 data
	// (if padding is required), UTF-16-BE bytes, and decoded UTF-8 bytes.
	// Since a 2-byte UTF-16 sequence may expand into a 3-byte UTF-8 sequence,
	// double the space allocation for UTF-8.
	if n := len(b64); b64[n-1] == '=' {
		return nil
	} else if n&3 == 0 {
		b = make([]byte, b64Enc.DecodedLen(n)*3)
	} else {
		n += 4 - n&3
		b = make([]byte, n+b64Enc.DecodedLen(n)*3)
		copy(b[copy(b, b64):n], []byte("=="))
		b64, b = b[:n], b[n:]
	}

	// Decode Base64 into the first 1/3rd of b
	n, err := b64Enc.Decode(b, b64)
	if err != nil || n&1 == 1 {
		return nil
	}

	// Decode UTF-16-BE into the remaining 2/3rds of b
	b, s := b[:n], b[n:]
	j := 0
	for i := 0; i < n; i += 2 {
		r := rune(b[i])<<8 | rune(b[i+1])
		if utf16.IsSurrogate(r) {
			if i += 2; i == n {
				return nil
			}
			r2 := rune(b[i])<<8 | rune(b[i+1])
			if r = utf16.DecodeRune(r, r2); r == repl {
				return nil
			}
		} else if min <= r && r <= max {
			return nil
		}
		j += utf8.EncodeRune(s[j:], r)
	}
	return s[:j]
}
1026567
func (m *RequestDataStream) Decode(buf []byte) {
	data := bytes.NewBuffer(buf)
	binary.Read(data, binary.LittleEndian, &m.REQ_MESSAGE_RATE)
	binary.Read(data, binary.LittleEndian, &m.TARGET_SYSTEM)
	binary.Read(data, binary.LittleEndian, &m.TARGET_COMPONENT)
	binary.Read(data, binary.LittleEndian, &m.REQ_STREAM_ID)
	binary.Read(data, binary.LittleEndian, &m.START_STOP)
}
1148976
func (c *config) Decode(body []byte) error {
	return yaml.Unmarshal(body, c)
}