// decodeMap decodes input into r.
544114
func decodeMap(d map[string]interface{}, r interface{}) error {
	cfg := &mapstructure.DecoderConfig{
		WeaklyTypedInput: true,
		TagName:          "ms",
		Result:           r,
		DecodeHook:       timeHookFunc,
	}
	dec, err := mapstructure.NewDecoder(cfg)
	if err != nil {
		return err
	}
	return dec.Decode(d)
}
1335071
func decodeParams(arr string) map[string]string {

	p := make(map[string]string)
	var isQuoted = false
	var isParam = true
	var curParam string
	var curVal string
	for _, c := range arr {
		switch {
		// if string is quoted, wait till next quote
		// and capture content
		case c == '"':
			if isQuoted == false {
				isQuoted = true
			} else {
				p[curParam] = curVal
				isQuoted = false
			}
		case c == '=' && isQuoted == false:
			isParam = false
		case c == ';' && isQuoted == false:
			isParam = true
			p[curParam] = curVal
			curParam = ""
			curVal = ""
		default:
			if isParam {
				curParam = curParam + string(c)
			} else {
				curVal = curVal + string(c)
			}
		}
	}
	p[curParam] = curVal
	return p

}
1067852
func (cs *configSpec) Decode(attrs config.AttributeMap, opts ...mapdecode.Option) (*buildable, error) {
	inputConfig := reflect.New(cs.inputType)
	if err := attrs.Decode(inputConfig.Interface(), opts...); err != nil {
		return nil, fmt.Errorf("failed to decode %v: %v", cs.inputType, err)
	}
	return &buildable{factory: cs.factory, inputData: inputConfig.Elem()}, nil
}
1134613
func decodeMap(rdTmp io.Reader, path string, nest bool) (Map, error) {
	// Read doc length.
	docLen, err := readInt32(rdTmp)
	if err != nil {
		return nil, err
	}
	if docLen > maxDocLen {
		return nil, errors.New("Doc exceeded maximum size.")
	}
	rd := bufio.NewReader(io.LimitReader(rdTmp, int64(docLen-4)))

	// Read doc.
	dst := Map{}
	for {
		eType, err := rd.ReadByte()
		if err != nil {
			return nil, err
		}
		switch eType {
		case 0x00:
			return dst, nil
		case _FLOATING_POINT:
			name, val, err := decodeFloat(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _STRING:
			name, val, err := decodeString(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _EMBEDDED_DOCUMENT:
			// While decoding Map default to Map.
			// name
			name, err := readCstring(rd)
			if err != nil {
				return nil, err
			}
			if !nest {
				bs, err := ReadOne(rd)
				if err != nil {
					return nil, err
				}
				dst[name] = bs
			} else {
				// value
				val, err := decodeMap(rd, catpath(path, name), true)
				if err != nil {
					return nil, err
				}
				dst[name] = val
			}
		case _ARRAY:
			name, val, err := decodeArray(rd, path)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _BINARY_DATA:
			name, val, err := decodeBinary(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _UNDEFINED:
			name, val, err := decodeUndefined(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _OBJECT_ID:
			name, val, err := decodeObjectId(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _BOOLEAN:
			name, val, err := decodeBool(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _UTC_DATETIME:
			name, val, err := decodeUTCDateTime(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _NULL_VALUE:
			name, val, err := decodeNull(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _REGEXP:
			name, val, err := decodeRegexp(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _DBPOINTER:
			name, val, err := decodeDBPointer(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _JAVASCRIPT:
			name, val, err := decodeJavascript(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _SYMBOL:
			name, val, err := decodeSymbol(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _JAVASCRIPT_SCOPE:
			name, val, err := decodeJavascriptScope(rd, path)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _32BIT_INTEGER:
			name, val, err := decodeInt32(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _TIMESTAMP:
			name, val, err := decodeTimestamp(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _64BIT_INTEGER:
			name, val, err := decodeInt64(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _MIN_KEY:
			name, val, err := decodeMinKey(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		case _MAX_KEY:
			name, val, err := decodeMaxKey(rd)
			if err != nil {
				return nil, err
			}
			dst[name] = val
		default:
			return nil, fmt.Errorf("Unsupported type '%X'.", eType)
		}
	}
	return nil, 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
}
517213
func Decode(reader io.Reader) (map[string]interface{}, error) {
	decoder := decoder{*bufio.NewReader(reader)}
	if firstByte, err := decoder.ReadByte(); err != nil {
		return make(map[string]interface{}), nil
	} else if firstByte != 'd' {
		return nil, errors.New("bencode data must begin with a dictionary")
	}
	return decoder.readDictionary()
}
12268
func decodeFrom(opts *options, src interface{}) Into {
	return func(dest interface{}) error {
		var fieldHooks FieldHookFunc
		hooks := opts.DecodeHooks

		// fieldHook goes first because it may replace the source data map.
		if len(opts.FieldHooks) > 0 {
			fieldHooks = composeFieldHooks(opts.FieldHooks)
		}

		hooks = append(
			hooks,
			unmarshalerHook(opts),
			// durationHook must come before the strconvHook
			// because the Kind of time.Duration is Int64.
			durationHook,
			strconvHook,
		)

		cfg := mapstructure.DecoderConfig{
			ErrorUnused:    !opts.IgnoreUnused,
			Result:         dest,
			SquashEmbedded: true,
			DecodeHook: fromDecodeHookFunc(
				supportPointers(composeDecodeHooks(hooks)),
			),
			FieldHook: mapstructure.FieldHookFunc(fieldHooks),
			TagName:   opts.TagName,
		}

		decoder, err := mapstructure.NewDecoder(&cfg)
		if err != nil {
			return fmt.Errorf("failed to set up decoder: %v", err)
		}

		if err := decoder.Decode(src); err != nil {
			if merr, ok := err.(*mapstructure.Error); ok {
				return multierr.Combine(merr.WrappedErrors()...)
			}
			return err
		}

		return nil
	}
}
1032815
func Decode(bibstring string) (bibmap map[string]interface{}, err error) {
	entry, err := parseEntry(bibstring)
	if err != nil {
		return nil, err
	}

	name := parseName(bibstring)
	fields := parseFields(bibstring)

	bibmap = make(map[string]interface{})
	bibmap["entry"] = entry
	bibmap["name"] = name
	for k, v := range fields {
		bibmap[k] = v
	}

	if _, ok := bibmap["author"]; ok {
		bibmap["author"] = parseAuthors(bibmap["author"].(string))
	}

	return bibmap, err
}
1141702
func DecodeString(src string) (body []byte, err error) {
	body, err = Encoding.DecodeString(src)
	return
}
444921
func StringValueMap(src map[string]*string) map[string]string {
	dst := make(map[string]string)
	for k, val := range src {
		if val != nil {
			dst[k] = *val
		}
	}
	return dst
}
1143093
func DecodeString(in string, val interface{}) error {
	buf := strings.NewReader(in)
	d := NewDecoder(buf)
	return d.Decode(val)
}
1124181
func (d *Decoder) DecodeArray() ([]interface{}, error) {
	if c := d.skipSpaces(); c != '[' {
		return nil, d.error(c, "looking for beginning of array")
	}
	val, err := d.array()
	if err != nil {
		return nil, err
	}
	if c := d.skipSpaces(); d.pos < d.end {
		return nil, d.error(c, "after top-level value")
	}
	return val, nil
}
191346
func DecodeDict(data []byte, start int) (
	result interface{}, index int, err error) {

	if start >= len(data) || data[start] != 'd' {
		err = errors.New("invalid dict bencode")
		return
	}

	var item, key interface{}
	r := make(map[string]interface{})

	index = start + 1
	for index < len(data) {
		char, _ := utf8.DecodeRune(data[index:])
		if char == 'e' {
			break
		}

		if !unicode.IsDigit(char) {
			err = errors.New("invalid dict bencode")
			return
		}

		key, index, err = DecodeString(data, index)
		if err != nil {
			return
		}

		if index >= len(data) {
			err = errors.New("out of range")
			return
		}

		item, index, err = decodeItem(data, index)
		if err != nil {
			return
		}

		r[key.(string)] = item
	}

	if index == len(data) {
		err = errors.New("'e' not found when decode dict")
		return
	}
	index++

	result = r
	return
}
507010
func (d *Decoder) DecodeMapLen() (int, error) {
	c, err := d.readCode()
	if err != nil {
		return 0, err
	}

	if codes.IsExt(c) {
		if err = d.skipExtHeader(c); err != nil {
			return 0, err
		}

		c, err = d.readCode()
		if err != nil {
			return 0, err
		}
	}
	return d.mapLen(c)
}
803860
func Decode(r io.Reader, options *DecoderOptions) (dest image.Image, err error) {
	dinfo := newDecompress(r)
	if dinfo == nil {
		return nil, errors.New("allocation failed")
	}
	defer destroyDecompress(dinfo)

	// Recover panic
	defer func() {
		if r := recover(); r != nil {
			if _, ok := r.(error); !ok {
				err = fmt.Errorf("JPEG error: %v", r)
			}
		}
	}()

	C.jpeg_read_header(dinfo, C.TRUE)
	setupDecoderOptions(dinfo, options)

	switch dinfo.num_components {
	case 1:
		if dinfo.jpeg_color_space != C.JCS_GRAYSCALE {
			return nil, errors.New("Image has unsupported colorspace")
		}
		dest, err = decodeGray(dinfo)
	case 3:
		switch dinfo.jpeg_color_space {
		case C.JCS_YCbCr:
			dest, err = decodeYCbCr(dinfo)
		case C.JCS_RGB:
			dest, err = decodeRGB(dinfo)
		default:
			return nil, errors.New("Image has unsupported colorspace")
		}
	}
	return
}
605044
func convertMap(in map[interface{}]interface{}) map[string]interface{} {
  rtn := make(map[string]interface{})
  for key, val := range in {
    // if the value is a map of interface interfaces
    // make sure to convert them as well    
    var newValue interface{}
    switch val.(type) {
      case []interface{}:
        newValue = convertArray(val.([]interface{}))
      case map[interface{}]interface{}:
        newValue = convertMap(val.(map[interface{}]interface{}))
      default:
        newValue = val
    }

    switch key.(type) {
    case string:
      rtn[key.(string)] = newValue
    }
  }

  return rtn  
}
875647
func (m *Message) decodeSet() (err error) {
	pd := realDecoder{raw: m.Value}
	m.Set = &MessageSet{}
	return m.Set.decode(&pd)
}