// Unmarshal parses the X-encoded data and stores the result in the value pointed to by v.
// Unmarshal uses the inverse of the encodings that Marshal uses, allocating maps,
// slices, and pointers as necessary.
489524
func (u UnmarshalerFunc) Unmarshal(data []byte, v interface{}) error {
	return u(data, v)
}
748954
func Unmarshal(data []byte, i interface{}) error {
	err := json.Unmarshal(data, i)
	if err != nil {
		syntaxErr, ok := err.(*json.SyntaxError)
		if !ok {
			return err
		}

		// We have a syntax error. Extract out the line number and friends.
		// https://groups.google.com/forum/#!topic/golang-nuts/fizimmXtVfc
		newline := []byte{'\x0a'}

		// Calculate the start/end position of the line where the error is
		start := bytes.LastIndex(data[:syntaxErr.Offset], newline) + 1
		end := len(data)
		if idx := bytes.Index(data[start:], newline); idx >= 0 {
			end = start + idx
		}

		// Count the line number we're on plus the offset in the line
		line := bytes.Count(data[:start], newline) + 1
		pos := int(syntaxErr.Offset) - start - 1

		err = fmt.Errorf("Error in line %d, char %d: %s\n%s",
			line, pos, syntaxErr, data[start:end])
		return err
	}

	return nil
}
559109
func Unmarshal(r io.Reader, pb proto.Message) error {
	return new(Unmarshaler).Unmarshal(r, pb)
}
153533
func (n *DevNonce) Unmarshal(data []byte) error {
	*n = [2]byte{} // Reset the receiver
	return n.UnmarshalBinary(data)
}
92818
func unmarshal(data []byte, ext string) *config {
	var config *config
	var err error
	if ext == ".json" {
		err = json.Unmarshal(data, &config)
	} else if ext == ".yml" || ext == ".yaml" {
		err = yaml.Unmarshal(data, &config)
	} else {
		panic(StatusError{errors.New("Unrecognized file extension"), 65})
	}
	if err != nil {
		err = displaySyntaxError(data, err)
		panic(StatusError{err, 65})
	}
	return config
}
197142
func (key *NwkSKey) Unmarshal(data []byte) error {
	*key = [16]byte{} // Reset the receiver
	return key.UnmarshalBinary(data)
}
135352
func (eui *DevEUI) Unmarshal(data []byte) error {
	*eui = [8]byte{} // Reset the receiver
	return eui.UnmarshalBinary(data)
}
310208
func (*yamlMarshaller) Unmarshal(data []byte, v interface{}) error {
	return yaml.Unmarshal(data, v)
}
1237032
func (t *Tree) Unmarshal(v interface{}) error {
	d := Decoder{tval: t, tagName: tagFieldName}
	return d.unmarshal(v)
}
134716
func (bm *BlockMeta) Unmarshal(bs []byte) error {
	return cdc.UnmarshalBinaryBare(bs, bm)
}
594616
func (j *GoGoJSONPb) Unmarshal(data []byte, v interface{}) error {
	return unmarshalGoGoJSONPb(data, v)
}
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
}
400950
func Unmarshal(data []byte, v interface{}) error {
	rv := reflect.ValueOf(v)
	if rv.Kind() != reflect.Ptr {
		return fmt.Errorf("not a pointer: %v", v)
	}

	rv = rv.Elem()
	if rv.Kind() != reflect.Struct && rv.Kind() != reflect.Map {
		return fmt.Errorf("not a pointer to a struct/map: %v", v)
	}

	l, err := data2map(data)
	if err != nil {
		return err
	}
	if rv.Kind() == reflect.Map {
		kt := rv.Type().Key()
		vt := rv.Type().Elem()
		if kt.Kind() != reflect.String || vt.Kind() != reflect.String {
			return fmt.Errorf("not a map[string]string")
		}
		for k, v := range l {
			kv := reflect.ValueOf(k).Convert(kt)
			vv := reflect.ValueOf(v).Convert(vt)
			rv.SetMapIndex(kv, vv)
		}
		return nil
	}

	t := rv.Type()
	errs := UnmarshalError{}
	for i := 0; i < t.NumField(); i++ {
		ft := t.Field(i)
		fv := rv.Field(i)

		tag := ft.Tag.Get("ltsv")
		tags := strings.Split(tag, ",")
		key := tags[0]
		if key == "-" {
			continue
		}
		if key == "" {
			key = strings.ToLower(ft.Name)
		}
		s, ok := l[key]
		if !ok {
			continue
		}
		potentiallyNull := s == "-" || s == ""
		if fv.Kind() == reflect.Ptr {
			if fv.IsNil() {
				if potentiallyNull {
					switch fv.Type().Elem().Kind() {
					case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64:
						continue
					}
				}
				fv.Set(reflect.New(fv.Type().Elem()))
			}
			fv = fv.Elem()
		}
		if !fv.CanSet() {
			continue
		}

		switch fv.Kind() {
		case reflect.String:
			fv.SetString(s)
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
			if potentiallyNull {
				continue
			}
			i, err := strconv.ParseInt(s, 10, 64)
			if err != nil || fv.OverflowInt(i) {
				errs[ft.Name] = &UnmarshalTypeError{"number " + s, fv.Type()}
				continue
			}
			fv.SetInt(i)
		case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			if potentiallyNull {
				continue
			}
			i, err := strconv.ParseUint(s, 10, 64)
			if err != nil || fv.OverflowUint(i) {
				errs[ft.Name] = &UnmarshalTypeError{"number " + s, fv.Type()}
				continue
			}
			fv.SetUint(i)
		case reflect.Float32, reflect.Float64:
			if potentiallyNull {
				continue
			}
			n, err := strconv.ParseFloat(s, fv.Type().Bits())
			if err != nil || fv.OverflowFloat(n) {
				errs[ft.Name] = &UnmarshalTypeError{"number " + s, fv.Type()}
				continue
			}
			fv.SetFloat(n)
		default:
			u := indirect(fv)
			if u == nil {
				errs[ft.Name] = &UnmarshalTypeError{s, fv.Type()}
			} else {
				err := u.UnmarshalText([]byte(s))
				if err != nil {
					errs[ft.Name] = err
				}
			}
		}
	}

	if len(errs) < 1 {
		return nil
	}
	return errs
}
154285
func (n *NetID) Unmarshal(data []byte) error {
	*n = [3]byte{} // Reset the receiver
	return n.UnmarshalBinary(data)
}
148019
func (sj *SerializerJSON) Unmarshal(data []byte, protoData proto.Message) error {
	return jsonpb.Unmarshal(bytes.NewBuffer(data), protoData)
}
1243392
func (e *TagBlockKeyElem) unmarshal(buf, data []byte) {
	start := len(buf)

	// Parse flag data.
	e.flag, buf = buf[0], buf[1:]

	// Parse data offset/size.
	e.data.offset, buf = binary.BigEndian.Uint64(buf), buf[8:]
	e.data.size, buf = binary.BigEndian.Uint64(buf), buf[8:]

	// Slice data.
	e.data.buf = data[e.data.offset:]
	e.data.buf = e.data.buf[:e.data.size]

	// Parse hash index offset/size.
	e.hashIndex.offset, buf = binary.BigEndian.Uint64(buf), buf[8:]
	e.hashIndex.size, buf = binary.BigEndian.Uint64(buf), buf[8:]

	// Slice hash index data.
	e.hashIndex.buf = data[e.hashIndex.offset:]
	e.hashIndex.buf = e.hashIndex.buf[:e.hashIndex.size]

	// Parse key.
	n, sz := binary.Uvarint(buf)
	e.key, buf = buf[sz:sz+int(n)], buf[int(n)+sz:]

	// Save length of elem.
	e.size = start - len(buf)
}
351789
func (r *Redis) Unmarshal(key string, object interface{}) error {
	value, err := r.Get(key)
	if err == nil {
		err = json.Unmarshal([]byte(value), object)
	}
	return err
}