// currently only support unmarshal into a list of values, this makes it possible
// to support tuples without changing the query API. In the future this can be extend
// to allow unmarshalling into custom tuple types.
968495
func unmarshalTuple(info TypeInfo, data []byte, value interface{}) error {
	if v, ok := value.(Unmarshaler); ok {
		return v.UnmarshalCQL(info, data)
	}

	tuple := info.(TupleTypeInfo)
	switch v := value.(type) {
	case []interface{}:
		for i, elem := range tuple.Elems {
			// each element inside data is a [bytes]
			var p []byte
			p, data = readBytes(data)

			err := Unmarshal(elem, p, v[i])
			if err != nil {
				return err
			}
		}

		return nil
	}

	rv := reflect.ValueOf(value)
	if rv.Kind() != reflect.Ptr {
		return unmarshalErrorf("can not unmarshal into non-pointer %T", value)
	}

	rv = rv.Elem()
	t := rv.Type()
	k := t.Kind()

	switch k {
	case reflect.Struct:
		if v := t.NumField(); v != len(tuple.Elems) {
			return unmarshalErrorf("can not unmarshal tuple into struct %v, not enough fields have %d need %d", t, v, len(tuple.Elems))
		}

		for i, elem := range tuple.Elems {
			m := readInt(data)
			data = data[4:]

			v := elem.New()
			if err := Unmarshal(elem, data[:m], v); err != nil {
				return err
			}
			rv.Field(i).Set(reflect.ValueOf(v).Elem())

			data = data[m:]
		}

		return nil
	case reflect.Slice, reflect.Array:
		if k == reflect.Array {
			size := rv.Len()
			if size != len(tuple.Elems) {
				return unmarshalErrorf("can not unmarshal tuple into array of length %d need %d elements", size, len(tuple.Elems))
			}
		} else {
			rv.Set(reflect.MakeSlice(t, len(tuple.Elems), len(tuple.Elems)))
		}

		for i, elem := range tuple.Elems {
			m := readInt(data)
			data = data[4:]

			v := elem.New()
			if err := Unmarshal(elem, data[:m], v); err != nil {
				return err
			}
			rv.Index(i).Set(reflect.ValueOf(v).Elem())

			data = data[m:]
		}

		return nil
	}

	return unmarshalErrorf("cannot unmarshal %s into %T", info, value)
}
113471
func (r Response) Unmarshal(v interface{}) error {
	if r.err != nil {
		return r.err
	}
	return json.Unmarshal(r.body, v)
}
571740
func (sp *SerializerProto) Unmarshal(data []byte, protoData proto.Message) error {
	return proto.Unmarshal(data, protoData)
}
1003437
func (x *StringListExpr) UnmarshalJSON(data []byte) error {
	var v []*StringExpr
	err := json.Unmarshal(data, &v)
	if err == nil {
		x.Func = nil
		x.Literal = v
		return nil
	}

	// Perhaps we have a serialized function call (like `{"Ref": "Foo"}`)
	// so we'll try to unmarshal it with UnmarshalFunc. Not all Funcs also
	// implement StringListFunc, so we have to make sure that the referenced
	// function actually works in the boolean context
	funcCall, err2 := unmarshalFunc(data)
	if err2 == nil {
		stringFunc, ok := funcCall.(StringListFunc)
		if ok {
			x.Func = stringFunc
			return nil
		}

		// Possible that it's a Fn::GetAtt instance?
		getAttrFunc, ok := funcCall.(GetAttFunc)
		if ok {
			x.Func = StringList(getAttrFunc)
			return nil
		}
		return fmt.Errorf("%#v is not a StringListFunc", funcCall)
	}

	// Perhaps we have a single item, like "foo" which
	// occurs occasionally.
	var v2 StringExpr
	err3 := json.Unmarshal(data, &v2)
	if err3 == nil {
		x.Func = nil
		x.Literal = []*StringExpr{&v2}
		return nil
	}

	// Return the original error trying to unmarshal the literal expression,
	// which will be the most expressive.
	return err
}
787717
func (rs *ResultsStruct) UnmarshalJSON(buff []byte) error {
	emptyRow := []map[string]string{}
	rs.Queries = make(map[string][]map[string]string)
	rs.Statuses = make(map[string]OsqueryInt)
	// Queries can be []map[string]string OR an empty string
	// so we need to deal with an interface to accomodate two types
	intermediate := struct {
		Queries  map[string]interface{} `json:"queries"`
		Statuses map[string]OsqueryInt  `json:"statuses"`
	}{}
	if err := json.Unmarshal(buff, &intermediate); err != nil {
		return err
	}
	for queryName, status := range intermediate.Statuses {
		rs.Statuses[queryName] = status
		// Sometimes we have a status but don't have a corresponding
		// result.
		queryResult, ok := intermediate.Queries[queryName]
		if !ok {
			rs.Queries[queryName] = emptyRow
			continue
		}
		// Deal with structurally inconsistent results, sometimes a query
		// without any results is just a name with an empty string.
		switch val := queryResult.(type) {
		case string:
			rs.Queries[queryName] = emptyRow
		case []interface{}:
			results, err := convertRows(val)
			if err != nil {
				return err
			}
			rs.Queries[queryName] = results
		default:
			return fmt.Errorf("results for %q unknown type", queryName)
		}
	}
	return nil
}
176692
func (x *IntegerExpr) UnmarshalJSON(data []byte) error {
	var v int64
	err := json.Unmarshal(data, &v)
	if err == nil {
		x.Func = nil
		x.Literal = v
		return nil
	}

	// Cloudformation allows int values to be represented as strings
	var strValue string
	if err := json.Unmarshal(data, &strValue); err == nil {
		if v, err := strconv.ParseInt(strValue, 10, 64); err == nil {
			x.Func = nil
			x.Literal = v
			return nil
		}
	}

	// Perhaps we have a serialized function call (like `{"Ref": "Foo"}`)
	// so we'll try to unmarshal it with UnmarshalFunc. Not all Funcs also
	// implement IntegerFunc, so we have to make sure that the referenced
	// function actually works in the intean context
	funcCall, err2 := unmarshalFunc(data)
	if err2 == nil {
		intFunc, ok := funcCall.(IntegerFunc)
		if ok {
			x.Func = intFunc
			return nil
		}
	} else if unknownFunctionErr, ok := err2.(UnknownFunctionError); ok {
		return unknownFunctionErr
	}

	// Return the original error trying to unmarshal the literal expression,
	// which will be the most expressive.
	return err
}
1283969
func unmarshal(v reflect.Value, valuer func(name string) interface{}) error {
	if v.Kind() == reflect.Ptr {
		v = v.Elem()
	}
	t := v.Type()
	for i, num := 0, t.NumField(); i < num; i++ {
		var (
			f    = v.Field(i)
			sf   = t.Field(i)
			name = sf.Tag.Get("option") // todo: support default value
		)

		if sf.PkgPath != "" {
			continue
		}

		if name == "" {
			name = texts.Rename(sf.Name, texts.Lower)
		}
		opt := valuer(name)
		if opt == nil {
			// todo: read default value with option tag?
			continue
		}

		if err := unmarshalValue(f, opt); err != nil {
			return err
		}
	}
	return nil
}
1019664
func (e *G2) Unmarshal(m []byte) ([]byte, error) {
	// Each value is a 256-bit number.
	const numBytes = 256 / 8
	if len(m) != 4*numBytes {
		return nil, errors.New("bn256: not enough data")
	}
	// Unmarshal the points and check their caps
	if e.p == nil {
		e.p = newTwistPoint(nil)
	}
	e.p.x.x.SetBytes(m[0*numBytes : 1*numBytes])
	if e.p.x.x.Cmp(P) >= 0 {
		return nil, errors.New("bn256: coordinate exceeds modulus")
	}
	e.p.x.y.SetBytes(m[1*numBytes : 2*numBytes])
	if e.p.x.y.Cmp(P) >= 0 {
		return nil, errors.New("bn256: coordinate exceeds modulus")
	}
	e.p.y.x.SetBytes(m[2*numBytes : 3*numBytes])
	if e.p.y.x.Cmp(P) >= 0 {
		return nil, errors.New("bn256: coordinate exceeds modulus")
	}
	e.p.y.y.SetBytes(m[3*numBytes : 4*numBytes])
	if e.p.y.y.Cmp(P) >= 0 {
		return nil, errors.New("bn256: coordinate exceeds modulus")
	}
	// Ensure the point is on the curve
	if e.p.x.x.Sign() == 0 &&
		e.p.x.y.Sign() == 0 &&
		e.p.y.x.Sign() == 0 &&
		e.p.y.y.Sign() == 0 {
		// This is the point at infinity.
		e.p.y.SetOne()
		e.p.z.SetZero()
		e.p.t.SetZero()
	} else {
		e.p.z.SetOne()
		e.p.t.SetOne()

		if !e.p.IsOnCurve() {
			return nil, errors.New("bn256: malformed point")
		}
	}
	return m[4*numBytes:], nil
}
1341121
func (pTypeDef *SymTest) UnmarshalJSON(b []byte) error {
	var r rawSymTest
	err := json.Unmarshal(b, &r)
	if err == nil {
		o := SymTest(r)
		*pTypeDef = *((&o).Init())
		err = pTypeDef.Validate()
	}
	return err
}
825117
func (eui *AppEUI) Unmarshal(data []byte) error {
	*eui = [8]byte{} // Reset the receiver
	return eui.UnmarshalBinary(data)
}
888927
func (jsonMarshalerUnmarshaler) Unmarshal(data []byte, v interface{}) error {
	return json.Unmarshal(data, v)
}
418020
func (b *Uint64) UnmarshalGraphQL(input interface{}) error {
	var err error
	switch input := input.(type) {
	case string:
		return b.UnmarshalText([]byte(input))
	case int32:
		*b = Uint64(input)
	default:
		err = fmt.Errorf("Unexpected type for Long: %v", input)
	}
	return err
}
578831
func (StdJSON) Unmarshal(data []byte, v interface{}) error {
	return json.Unmarshal(data, v)
}
273979
func (s *SliceorMap) UnmarshalYAML(unmarshal func(interface{}) error) error {

	var sliceType []interface{}
	if err := unmarshal(&sliceType); err == nil {
		parts := map[string]string{}
		for _, s := range sliceType {
			if str, ok := s.(string); ok {
				str := strings.TrimSpace(str)
				keyValueSlice := strings.SplitN(str, "=", 2)

				key := keyValueSlice[0]
				val := ""
				if len(keyValueSlice) == 2 {
					val = keyValueSlice[1]
				}
				parts[key] = val
			} else {
				return fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", s, s)
			}
		}
		*s = parts
		return nil
	}

	var mapType map[interface{}]interface{}
	if err := unmarshal(&mapType); err == nil {
		parts := map[string]string{}
		for k, v := range mapType {
			if sk, ok := k.(string); ok {
				if sv, ok := v.(string); ok {
					parts[sk] = sv
				} else {
					return fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", v, v)
				}
			} else {
				return fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", k, k)
			}
		}
		*s = parts
		return nil
	}

	return errors.New("Failed to unmarshal SliceorMap")
}
964090
func (Attr *CategoricalAttribute) UnmarshalJSON(data []byte) error {
	var d map[string]interface{}
	err := json.Unmarshal(data, &d)
	if err != nil {
		return err
	}
	for _, v := range d["values"].([]interface{}) {
		Attr.values = append(Attr.values, v.(string))
	}
	return nil
}
224088
func (s *Serializer) Unmarshal(data []byte, v interface{}) error {
	pb, ok := v.(proto.Message)
	if !ok {
		return constants.ErrWrongValueType
	}
	return proto.Unmarshal(data, pb)
}
282105
func (b *Bytes) UnmarshalGraphQL(input interface{}) error {
	var err error
	switch input := input.(type) {
	case string:
		data, err := Decode(input)
		if err != nil {
			return err
		}
		*b = data
	default:
		err = fmt.Errorf("Unexpected type for Bytes: %v", input)
	}
	return err
}