// translate from one type to another, but deep copy all data
// precondition: vFrom and vTo are the same type as defined by translatable()
// precondition: vTo is addressable and settable
767942
func (t translator) translateSameType(vFrom, vTo reflect.Value) {
	k := vFrom.Kind()
	switch {
	case util.IsPrimitive(k):
		// Use convert, even if not needed; type alias to primitives are not
		// directly assignable and calling Convert on primitives does no harm
		vTo.Set(vFrom.Convert(vTo.Type()))
	case k == reflect.Ptr:
		if vFrom.IsNil() {
			return
		}
		vTo.Set(reflect.New(vTo.Type().Elem()))
		t.translate(vFrom.Elem(), vTo.Elem())
	case k == reflect.Slice:
		if vFrom.IsNil() {
			return
		}
		vTo.Set(reflect.MakeSlice(vTo.Type(), vFrom.Len(), vFrom.Len()))
		for i := 0; i < vFrom.Len(); i++ {
			t.translate(vFrom.Index(i), vTo.Index(i))
		}
	case k == reflect.Struct:
		for i := 0; i < vFrom.NumField(); i++ {
			t.translate(vFrom.Field(i), vTo.FieldByName(vFrom.Type().Field(i).Name))
		}
	default:
		panic("Encountered types that are not the same when they should be. This is a bug, please file a report")
	}
}
100296
func CanTransfer(db vm.StateDB, addr common.Address, amount *big.Int) bool {
	return db.GetBalance(addr).Cmp(amount) >= 0
}
545593
func (v *value) Equals(to Value) bool {
	vto, ok := to.(*value)
	if !ok {
		return false
	}
	if vv, ok := isValue(v.raw); ok {
		if vtov, ok := isValue(vto.raw); ok {
			return vv == vtov
		}
	}
	return reflect.DeepEqual(v.raw, vto.raw)
}
799287
func isExportedOrBuiltin(t reflect.Type) bool {
	for t.Kind() == reflect.Ptr {
		t = t.Elem()
	}
	// PkgPath will be non-empty even for an exported type,
	// so we need to check the type name as well.
	return isExported(t.Name()) || t.PkgPath() == ""
}
501847
func convert(a, b reflect.Value) (_ reflect.Value, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("%v", r)
		}
	}()
	return a.Convert(b.Type()), nil
}
677824
func (d *doubleIter) nextFrom() (err error) {
	d.from.current, err = d.from.iter.Next()
	return turnEOFIntoNil(err)
}
412451
func (ctx *context) Translate(format string, args ...interface{}) string {
	if cb, ok := ctx.values.Get(ctx.Application().ConfigurationReadOnly().GetTranslateFunctionContextKey()).(func(format string, args ...interface{}) string); ok {
		return cb(format, args...)
	}

	return ""
}
1127166
func (v *polValues) InvNTransform() poly {
	k := v.k
	n := v.n
	θshift := (n * _W) >> k

	// Perform an inverse Fourier transform to recover q.
	qbits := make([]big.Word, (n+1)<<k)
	q := make([]fermat, 1<<k)
	for i := range q {
		q[i] = fermat(qbits[i*(n+1) : (i+1)*(n+1)])
	}
	fourier(q, v.values, true, n, k)

	// Divide by K, and untwist q to recover p.
	u := make(fermat, n+1)
	a := make([]nat, 1<<k)
	for i := range q {
		u.Shift(q[i], -int(k)-i*θshift)
		copy(q[i], u)
		a[i] = nat(q[i])
	}
	return poly{k: k, m: 0, a: a}
}
221450
func (t translator) hasTranslator(tFrom, tTo reflect.Type) bool {
	return t.getTranslator(tFrom, tTo).IsValid()
}
271899
func NewToTransformation(d execute.Dataset, cache execute.TableBuilderCache, spec *ToProcedureSpec, deps ToDependencies) (*ToTransformation, error) {
	var fn *execute.RowMapFn
	var err error

	if spec.Spec.FieldFn != nil {
		if fn, err = execute.NewRowMapFn(spec.Spec.FieldFn); err != nil {
			return nil, err
		}
	}

	return &ToTransformation{
		d:     d,
		fn:    fn,
		cache: cache,
		spec:  spec,
		deps:  deps,
	}, nil
}
298243
func isLegalForIdenticalTo(t reflect.Type) (bool, error) {
	// Allow the zero type.
	if t == nil {
		return true, nil
	}

	// Reference types are always okay; we compare pointers.
	switch t.Kind() {
	case reflect.Slice, reflect.Map, reflect.Func, reflect.Chan:
		return true, nil
	}

	// Reject other non-comparable types.
	if !isComparable(t) {
		return false, errors.New(fmt.Sprintf("%v is not comparable", t))
	}

	return true, nil
}
27739
func ErrorFromVTRPC(err *vtrpcpb.RPCError) error {
	if err == nil {
		return nil
	}
	code := err.Code
	if code == vtrpcpb.Code_OK {
		code = vterrors.LegacyErrorCodeToCode(err.LegacyCode)
	}
	return vterrors.Errorf(code, "vttablet: %s", err.Message)
}
961024
func (fields FieldTransfer) To(target interface{}) {
	for k, v := range fields {
		val := reflect.ValueOf(target).Elem().FieldByNameFunc(func(n string) bool {
			return strings.ToLower(n) == strings.ToLower(k)
		})
		if val.IsValid() && val.CanSet() {
			val.SetString(v)
		}
	}
}
711961
func (original Transform) TransformFromJSON(from, to Transform, fncMap template.FuncMap) (string, error) {
	jsonParsed, _ := gabs.ParseJSON([]byte(from))
	ch, _ := jsonParsed.ChildrenMap()
	path := ""
	values := make(map[string]string)
	walkTreeJSON(ch, &path, values)
	oriParsed, _ := gabs.ParseJSON([]byte(original))
	parsedMap := make(map[string]string)
	for k, v := range values {
		parsedMap[cleanString(v)] = cleanString(oriParsed.Path(k).String())
	}
	return generateTransformedMessage(parsedMap, to, fncMap)
}
737638
func NewTeeFromJSON(js json.RawMessage) (*WriteOperations, error) {
	tmp := struct {
		Tee json.RawMessage `json:"tee"`
	}{}
	if err := json.Unmarshal(js, &tmp); err != nil {
		return nil, err
	} else if step, err := NewWriteOperationsFromJSON(tmp.Tee); err != nil {
		return nil, err
	} else {
		return step, nil
	}
}
1045709
func translateFunc(arg1, arg2, arg3 query) func(query, iterator) interface{} {
	return func(q query, t iterator) interface{} {
		str := asString(t, arg1.Evaluate(t))
		src := asString(t, arg2.Evaluate(t))
		dst := asString(t, arg3.Evaluate(t))

		var replace []string
		for i, s := range src {
			d := ""
			if i < len(dst) {
				d = string(dst[i])
			}
			replace = append(replace, string(s), d)
		}
		return strings.NewReplacer(replace...).Replace(str)
	}
}
45856
func (d *Decoder) valueFromTree(mtype reflect.Type, tval *Tree) (reflect.Value, error) {
	if mtype.Kind() == reflect.Ptr {
		return d.unwrapPointer(mtype, tval)
	}
	var mval reflect.Value
	switch mtype.Kind() {
	case reflect.Struct:
		mval = reflect.New(mtype).Elem()
		for i := 0; i < mtype.NumField(); i++ {
			mtypef := mtype.Field(i)
			an := annotation{tag: d.tagName}
			opts := tomlOptions(mtypef, an)
			if opts.include {
				baseKey := opts.name
				keysToTry := []string{
					baseKey,
					strings.ToLower(baseKey),
					strings.ToTitle(baseKey),
					strings.ToLower(string(baseKey[0])) + baseKey[1:],
				}

				found := false
				for _, key := range keysToTry {
					exists := tval.Has(key)
					if !exists {
						continue
					}
					val := tval.Get(key)
					mvalf, err := d.valueFromToml(mtypef.Type, val)
					if err != nil {
						return mval, formatError(err, tval.GetPosition(key))
					}
					mval.Field(i).Set(mvalf)
					found = true
					break
				}

				if !found && opts.defaultValue != "" {
					mvalf := mval.Field(i)
					var val interface{}
					var err error
					switch mvalf.Kind() {
					case reflect.Bool:
						val, err = strconv.ParseBool(opts.defaultValue)
						if err != nil {
							return mval.Field(i), err
						}
					case reflect.Int:
						val, err = strconv.Atoi(opts.defaultValue)
						if err != nil {
							return mval.Field(i), err
						}
					case reflect.String:
						val = opts.defaultValue
					case reflect.Int64:
						val, err = strconv.ParseInt(opts.defaultValue, 10, 64)
						if err != nil {
							return mval.Field(i), err
						}
					case reflect.Float64:
						val, err = strconv.ParseFloat(opts.defaultValue, 64)
						if err != nil {
							return mval.Field(i), err
						}
					default:
						return mval.Field(i), fmt.Errorf("unsuported field type for default option")
					}
					mval.Field(i).Set(reflect.ValueOf(val))
				}
			}
		}
	case reflect.Map:
		mval = reflect.MakeMap(mtype)
		for _, key := range tval.Keys() {
			// TODO: path splits key
			val := tval.GetPath([]string{key})
			mvalf, err := d.valueFromToml(mtype.Elem(), val)
			if err != nil {
				return mval, formatError(err, tval.GetPosition(key))
			}
			mval.SetMapIndex(reflect.ValueOf(key).Convert(mtype.Key()), mvalf)
		}
	}
	return mval, nil
}