// unmarshalValue unmarshals JSON value into v.
// v must be addressable and not obtained by the use of unexported
// struct fields, otherwise unmarshalValue will panic.
165800
func unmarshalValue(value json.Token, v reflect.Value) error {
	b, err := json.Marshal(value) // TODO: Short-circuit (if profiling says it's worth it).
	if err != nil {
		return err
	}
	return json.Unmarshal(b, v.Addr().Interface())
}
622835
func unmarshal(data []byte, container ConfigContainer) error {
	unmarshalFunc := func(v interface{}) error {
		return config.Unmarshal(data, v)
	}

	var err error
	unmarshaller, ok := container.(Unmarshaller)
	if ok {
		err = unmarshaller.Unmarshal(unmarshalFunc)
	} else {
		err = unmarshalFunc(container)
	}
	return err
}
1166018
func UnmarshalValue(value reflect.Value, s string, seps ...rune) error {
	sliceSeparator, mapKeySeparator := separators(seps)

	switch value.Type() {
	case urlType:
		v, err := url.Parse(s)
		if err != nil {
			return err
		}
		value.Set(reflect.ValueOf(v))
		return nil
	case htmltemplateType:
		v, err := htemplate.New("").Parse(s)
		if err != nil {
			return err
		}
		value.Set(reflect.ValueOf(v))
		return nil
	case texttemplateType:
		v, err := template.New("").Parse(s)
		if err != nil {
			return err
		}
		value.Set(reflect.ValueOf(v))
		return nil
	case regexpType:
		v, err := regexp.Compile(s)
		if err != nil {
			return err
		}
		value.Set(reflect.ValueOf(v))
		return nil
	case timeType:
		//TODO add UTC parsing
		v, err := cast.StringToDate(s)
		if err != nil {
			return err
		}
		value.Set(reflect.ValueOf(v))
		return nil
	case durationType:
		v, err := time.ParseDuration(s)
		if err != nil {
			return err
		}
		value.SetInt(int64(v))
		return nil
	case ipaddrType:
		v := net.ParseIP(s)
		value.Set(reflect.ValueOf(v))
		return nil
	case ipnetType:
		_, v, err := net.ParseCIDR(s)
		if err != nil {
			return err
		}
		value.Set(reflect.ValueOf(v))
		return nil
	}

	if dec, ok := ptrValue(value).Interface().(encoding.TextUnmarshaler); ok {
		return dec.UnmarshalText([]byte(s))
	}

	switch value.Kind() {
	default:
		return fmt.Errorf("%v: %v", errCannotUnmarshal, value.Interface())

	case reflect.Bool:
		v, err := strconv.ParseBool(s)
		if err != nil {
			return err
		}
		value.SetBool(v)

	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		v, err := strconv.ParseInt(s, 0, 64)
		if err != nil {
			return err
		}
		value.SetInt(v)

	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		v, err := strconv.ParseUint(s, 0, 64)
		if err != nil {
			return err
		}
		value.SetUint(v)

	case reflect.Float32, reflect.Float64:
		v, err := strconv.ParseFloat(s, 64)
		if err != nil {
			return err
		}
		value.SetFloat(v)

	case reflect.String:
		value.SetString(s)

	case reflect.Array:
		r := newcsvreadwriter(sliceSeparator)
		values, err := r.read(s)
		if err != nil {
			return err
		}
		// Make sure the input and array sizes do fit.
		n := value.Len()
		if m := len(values); m < n {
			n = m
		}
		for i := 0; i < n; i++ {
			s := values[i]
			v := value.Index(i)
			if v.Kind() == reflect.Ptr {
				v = v.Elem()
			}
			if err := UnmarshalValue(v, s); err != nil {
				return fmt.Errorf("%s: %v", s, err)
			}
		}

	case reflect.Slice:
		r := newcsvreadwriter(sliceSeparator)
		values, err := r.read(s)
		if err != nil {
			return err
		}
		elem := value.Type().Elem()
		sliceValues := reflect.MakeSlice(value.Type(), 0, len(values))
		for _, s := range values {
			v := reflect.New(elem).Elem()
			if err := UnmarshalValue(v, s); err != nil {
				return fmt.Errorf("%s: %v", s, err)
			}
			sliceValues = reflect.Append(sliceValues, v)
		}
		value.Set(sliceValues)

	case reflect.Map:
		r := newcsvreadwriter(sliceSeparator)
		values, err := r.read(s)
		if err != nil {
			return err
		}
		vType := value.Type()
		keyType := vType.Key()
		elemType := vType.Elem()
		mapValues := reflect.MakeMap(value.Type())

		keyreader := newcsvreadwriter(mapKeySeparator)
		for _, s := range values {
			data, err := keyreader.read(s)
			if err != nil {
				return fmt.Errorf("%s: %v", s, err)
			}
			if len(data) != 2 {
				return fmt.Errorf("%s: %v", s, errInvalidMapKey)
			}
			key := reflect.New(keyType).Elem()
			if err := UnmarshalValue(key, data[0]); err != nil {
				return fmt.Errorf("%s: %v", s, err)
			}
			v := reflect.New(elemType).Elem()
			if err := UnmarshalValue(v, data[1]); err != nil {
				return fmt.Errorf("%s: %v", s, err)
			}
			mapValues.SetMapIndex(key, v)
		}
		value.Set(mapValues)
	}
	return nil
}
593649
func (j *JSONBuiltin) Unmarshal(data []byte, v interface{}) error {
	return json.Unmarshal(data, v)
}
1265236
func (p *DLChannelAnsPayload) UnmarshalBinary(data []byte) error {
	if len(data) != 1 {
		return errors.New("lorawan: 1 byte of data is expected")
	}

	p.ChannelFrequencyOK = data[0]&1 > 0
	p.UplinkFrequencyExists = data[0]&(1<<1) > 0
	return nil
}
1131699
func UnmarshalAny(any *types.Any) (interface{}, error) {
	t, err := getTypeByURL(any.TypeUrl)
	if err != nil {
		return nil, err
	}
	v := reflect.New(t.t).Interface()
	if t.isProto {
		err = proto.Unmarshal(any.Value, v.(proto.Message))
	} else {
		err = json.Unmarshal(any.Value, v)
	}
	return v, err
}
416835
func (v *VolumeSnapshot) UnmarshalJSON(data []byte) error {
	tmp := VolumeSnapshotCopy{}
	err := json.Unmarshal(data, &tmp)
	if err != nil {
		return err
	}
	tmp2 := VolumeSnapshot(tmp)
	*v = tmp2
	return nil
}
23823
func Unmarshal(data []byte, v interface{}) error {
	if pb, ok := v.(proto.Message); ok {
		return annotate(data, jsonpb.Unmarshal(bytes.NewBuffer(data), pb))
	}
	return annotate(data, json.Unmarshal(data, v))
}
447190
func UnmarshalJSON(v interface{}, stream io.Reader) error {
	var out interface{}

	err := json.NewDecoder(stream).Decode(&out)
	if err == io.EOF {
		return nil
	} else if err != nil {
		return err
	}

	return unmarshalAny(reflect.ValueOf(v), out, "")
}
394729
func (v *Volumes) UnmarshalYAML(unmarshal func(interface{}) error) error {
	var sliceType []interface{}
	if err := unmarshal(&sliceType); err == nil {
		v.Volumes = []*Volume{}
		for _, volume := range sliceType {
			name, ok := volume.(string)
			if !ok {
				return fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name)
			}
			elts := strings.SplitN(name, ":", 3)
			var vol *Volume
			switch {
			case len(elts) == 1:
				vol = &Volume{
					Destination: elts[0],
				}
			case len(elts) == 2:
				vol = &Volume{
					Source:      elts[0],
					Destination: elts[1],
				}
			case len(elts) == 3:
				vol = &Volume{
					Source:      elts[0],
					Destination: elts[1],
					AccessMode:  elts[2],
				}
			default:
				// FIXME
				return fmt.Errorf("")
			}
			v.Volumes = append(v.Volumes, vol)
		}
		return nil
	}

	return errors.New("Failed to unmarshal Volumes")
}
1280271
func (gobMarshalerUnmarshaler) Unmarshal(data []byte, v interface{}) error {
	buff := bytes.NewBuffer(data)
	dec := gob.NewDecoder(buff)
	if err := dec.Decode(v); err != nil {
		return err
	}
	return nil
}
1213229
func (key *AppSKey) Unmarshal(data []byte) error {
	*key = [16]byte{} // Reset the receiver
	return key.UnmarshalBinary(data)
}
864801
func UnmarshalValidatorData(data interface{}) (ValidatorData, error) {
	raw, ok := data.(map[string]interface{})
	if !ok {
		return ValidatorData{}, errors.New("validator input is not a map[string]interface{}")
	}
	addr, ok := raw["address"].(string)
	if !ok {
		return ValidatorData{}, errors.New("validator address is not sent as a string")
	}
	addrBytes, err := hexutil.Decode(addr)
	if err != nil {
		return ValidatorData{}, err
	}
	if !ok || len(addrBytes) == 0 {
		return ValidatorData{}, errors.New("validator address is undefined")
	}

	message, ok := raw["message"].(string)
	if !ok {
		return ValidatorData{}, errors.New("message is not sent as a string")
	}
	messageBytes, err := hexutil.Decode(message)
	if err != nil {
		return ValidatorData{}, err
	}
	if !ok || len(messageBytes) == 0 {
		return ValidatorData{}, errors.New("message is undefined")
	}

	return ValidatorData{
		Address: common.BytesToAddress(addrBytes),
		Message: messageBytes,
	}, nil
}
578831
func (StdJSON) Unmarshal(data []byte, v interface{}) error {
	return json.Unmarshal(data, v)
}
934373
func (level *Level) UnmarshalJSON(data []byte) error {
	var (
		s   string
		err error
	)
	if len(data) >= 2 {
		s, err = strconv.Unquote(string(data))
		if err != nil {
			return err
		}
	} else {
		s = string(data)
	}
	return level.Decode(s)
}
591220
func Unmarshal(data []byte, v interface{}, opts ...Option) error {
	if len(opts) == 0 {
		return json.Unmarshal(data, v)
	}
	buf := bytes.NewBuffer(data)
	node, err := Read(buf, opts...)
	if err != nil {
		return err
	}
	buf.Reset()
	if err := Write(buf, node); err != nil {
		return err
	}
	return json.Unmarshal(buf.Bytes(), v)
}
695262
func (vd *VolumeSnapshotList) UnmarshalJSON(data []byte) error {
	tmp := VolumeSnapshotListCopy{}
	err := json.Unmarshal(data, &tmp)
	if err != nil {
		return err
	}
	tmp2 := VolumeSnapshotList(tmp)
	*vd = tmp2
	return nil
}