// A wrapper around mapstructure.Decode that mimics the WeakDecode functionality
968750
func decode(input interface{}, config *mapstructure.DecoderConfig) error {
	decoder, err := mapstructure.NewDecoder(config)
	if err != nil {
		return err
	}
	return decoder.Decode(input)
}
1085435
func (e *socDecodeBuild) Decode(d int, bu []byte) (interface{}, error) {
	return e.handler(d, bu)
}
225559
func (jd *JSONDecoder) Decode(byteSet []byte) ([]*FileDataEntry, error) {
	if len(byteSet) == 0 {
		return []*FileDataEntry{}, nil
	}
	// Decode to type-specific structure
	jsonFile := jsonFile{}
	err := json.Unmarshal(byteSet, &jsonFile)
	if err != nil {
		return nil, fmt.Errorf("failed to decode json file: %v", err)
	}
	// Convert to common file data entry list structure
	var dataEntries []*FileDataEntry
	for _, dataEntry := range jsonFile.Data {
		dataEntries = append(dataEntries, &FileDataEntry{Key: dataEntry.Key, Value: dataEntry.Value})
	}
	return dataEntries, nil
}
978962
func DecodeAttrs(v []byte) (map[string]interface{}, error) {
	var pb internal.AttrMap
	if err := proto.Unmarshal(v, &pb); err != nil {
		return nil, err
	}
	return decodeAttrs(pb.GetAttrs()), nil
}
833183
func decodeMapFields(val reflect.Value, body map[string]*json.RawMessage) error {
	mapVal := val
	if mapVal.IsNil() {
		valType := val.Type()
		mapType := reflect.MapOf(valType.Key(), valType.Elem())
		mapVal = reflect.MakeMap(mapType)
	}
	for jsonName, raw := range body {
		var value interface{}
		if raw != nil {
			if err := json.Unmarshal(*raw, &value); err != nil {
				return driver.WithStack(err)
			}
		}
		mapVal.SetMapIndex(reflect.ValueOf(jsonName), reflect.ValueOf(value))
	}
	val.Set(mapVal)
	return nil
}
612469
func (d *YAMLOrJSONDecoder) Decode(into interface{}) error {
	if d.decoder == nil {
		buffer, origData, isJSON := GuessJSONStream(d.r, d.bufferSize)
		if isJSON {
			d.decoder = json.NewDecoder(buffer)
			d.rawData = origData
		} else {
			d.decoder = NewYAMLToJSONDecoder(buffer)
		}
	}
	err := d.decoder.Decode(into)
	if jsonDecoder, ok := d.decoder.(*json.Decoder); ok {
		if syntax, ok := err.(*json.SyntaxError); ok {
			data, readErr := ioutil.ReadAll(jsonDecoder.Buffered())
			if readErr != nil {
				klog.V(4).Infof("reading stream failed: %v", readErr)
			}
			js := string(data)

			// if contents from io.Reader are not complete,
			// use the original raw data to prevent panic
			if int64(len(js)) <= syntax.Offset {
				js = string(d.rawData)
			}

			start := strings.LastIndex(js[:syntax.Offset], "\n") + 1
			line := strings.Count(js[:start], "\n")
			return JSONSyntaxError{
				Line: line,
				Err:  fmt.Errorf(syntax.Error()),
			}
		}
	}
	return err
}
1005189
func (d *YAMLToJSONDecoder) Decode(into interface{}) error {
	if d.scanner.Scan() {
		data, err := yaml.YAMLToJSON(d.scanner.Bytes())
		if err != nil {
			return err
		}
		return json.Unmarshal(data, into)
	}
	err := d.scanner.Err()
	if err == nil {
		err = io.EOF
	}
	return err
}
600444
func (dec *skipDecoder) Decode(iter *Iterator) (bool, error) {
	if iter.Error() != nil {
		return false, iter.Error()
	}
	for iter.Valid() {
		key, _, err := mvccDecode(iter.Key())
		if err != nil {
			return false, errors.Trace(err)
		}
		if !bytes.Equal(key, dec.currKey) {
			dec.currKey = key
			return true, nil
		}
		iter.Next()
	}
	return false, nil
}
1191227
func (e *Encoder) marshalMap(m reflect.Value, child bool) (string, bool) {
	var ok bool
	if ok = supportedBaseKind(m); !ok {
		return "", false
	}
	// get the kind of the map value
	var row string
	var sv stringValues = m.MapKeys()
	// sort the map keys first
	// TODO have this work on things other than string?
	sort.Sort(sv)
	for i, key := range sv {
		val := m.MapIndex(key)
		kk, ok := e.marshal(key, true)
		if !ok {
			return "", false
		}
		var kval, vval string
		for j, tmp := range kk {
			if j > 0 && j < len(kk) {
				kval += ","
			}
			kval += tmp
		}
		if len(kk) > 1 {
			kval = fmt.Sprintf("%s%s%s", e.sepBeg, kval, e.sepEnd)
		}
		vv, ok := e.marshal(val, true)
		if !ok {
			return "", false
		}
		for j, tmp := range vv {
			if j > 0 && j < len(vv) {
				vval += ","
			}
			vval += tmp
		}
		if len(vv) > 1 {
			vval = fmt.Sprintf("%s%s%s", e.sepBeg, vval, e.sepEnd)
		}
		vval = fmt.Sprintf("%s:%s", kval, vval)
		if i == 0 {
			row = vval
		} else {
			row = fmt.Sprintf("%s,%s", row, vval)
		}
	}
	if child {
		row = fmt.Sprintf("%s%s%s", e.sepBeg, row, e.sepEnd)
	}
	return row, true
}
662082
func DecodeRowWithMap(b []byte, cols map[int64]*types.FieldType, loc *time.Location, row map[int64]types.Datum) (map[int64]types.Datum, error) {
	if row == nil {
		row = make(map[int64]types.Datum, len(cols))
	}
	if b == nil {
		return row, nil
	}
	if len(b) == 1 && b[0] == codec.NilFlag {
		return row, nil
	}
	cnt := 0
	var (
		data []byte
		err  error
	)
	for len(b) > 0 {
		// Get col id.
		data, b, err = codec.CutOne(b)
		if err != nil {
			return nil, errors.Trace(err)
		}
		_, cid, err := codec.DecodeOne(data)
		if err != nil {
			return nil, errors.Trace(err)
		}
		// Get col value.
		data, b, err = codec.CutOne(b)
		if err != nil {
			return nil, errors.Trace(err)
		}
		id := cid.GetInt64()
		ft, ok := cols[id]
		if ok {
			_, v, err := codec.DecodeOne(data)
			if err != nil {
				return nil, errors.Trace(err)
			}
			v, err = unflatten(v, ft, loc)
			if err != nil {
				return nil, errors.Trace(err)
			}
			row[id] = v
			cnt++
			if cnt == len(cols) {
				// Get enough data.
				break
			}
		}
	}
	return row, nil
}
1179237
func (dec *mvccEntryDecoder) Decode(iter *Iterator) (bool, error) {
	ldec := lockDecoder{expectKey: dec.expectKey}
	ok, err := ldec.Decode(iter)
	if err != nil {
		return ok, errors.Trace(err)
	}
	if ok {
		dec.mvccEntry.lock = &ldec.lock
	}
	for iter.Valid() {
		vdec := valueDecoder{expectKey: dec.expectKey}
		ok, err = vdec.Decode(iter)
		if err != nil {
			return ok, errors.Trace(err)
		}
		if !ok {
			break
		}
		dec.mvccEntry.values = append(dec.mvccEntry.values, vdec.value)
	}
	succ := dec.mvccEntry.lock != nil || len(dec.mvccEntry.values) > 0
	return succ, nil
}
264606
func (g GobEncoder) Decode(data []byte, v interface{}) error {
	e := gob.NewDecoder(bytes.NewBuffer(data))
	return e.Decode(v)
}
958335
func Encode(element interface{}) (map[string]string, error) {
	node, err := internal.EncodeToNode(element)
	if err != nil {
		return nil, err
	}

	return internal.EncodeNode(node), nil
}
626309
func (c *CodecMsgpack) Decode(buf []byte, obj interface{}) error {
	err := codec.NewDecoderBytes(buf, c.h).Decode(obj)
	if err != nil {
		return errors.Wrap(err, "failed to decode")
	}
	return nil
}
486109
func decodeSlice(elemType reflect.Type, slice reflect.Value, input map[string]interface{}) error {
	var v reflect.Value
	if elemType.Kind() == reflect.Ptr {
		v = reflect.New(elemType.Elem())
	} else {
		v = reflect.New(elemType)
	}

	if !v.CanInterface() {
		return fmt.Errorf("can't interface %#v", v)
	}

	if err := decodeMap(input, v.Interface()); err != nil {
		return err
	}

	if elemType.Kind() == reflect.Struct {
		v = v.Elem()
	}
	slice.Set(reflect.Append(slice, v))

	return nil
}
1117832
func Decode(labels map[string]string, element interface{}, filters ...string) error {
	node, err := internal.DecodeToNode(labels, filters...)
	if err != nil {
		return err
	}

	err = internal.AddMetadata(element, node)
	if err != nil {
		return err
	}

	err = internal.Fill(element, node)
	if err != nil {
		return err
	}

	return nil
}
456747
func mapKeys(vs []reflect.Value) sort.Interface {
	s := mapKeySorter{vs: vs}

	// Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps.
	if len(vs) == 0 {
		return s
	}
	switch vs[0].Kind() {
	case reflect.Int32, reflect.Int64:
		s.less = func(a, b reflect.Value) bool { return a.Int() < b.Int() }
	case reflect.Uint32, reflect.Uint64:
		s.less = func(a, b reflect.Value) bool { return a.Uint() < b.Uint() }
	case reflect.Bool:
		s.less = func(a, b reflect.Value) bool { return !a.Bool() && b.Bool() } // false < true
	case reflect.String:
		s.less = func(a, b reflect.Value) bool { return a.String() < b.String() }
	default:
		panic(fmt.Sprintf("unsupported map key type: %v", vs[0].Kind()))
	}

	return s
}