// Variant of MapsToStructs() with relaxed signature.
333088
func MapsToStructs2(Maps []interface{}, SlicePointer interface{}, converter Converter, tag string) {
	m := make([]map[string]interface{}, len(Maps))
	for index, i := range Maps {
		m[index] = i.(map[string]interface{})
	}
	MapsToStructs(m, SlicePointer, converter, tag)
}
1158792
func (st *StructTypeInfo) FieldInfos() FieldInfos {
	var fields FieldInfos
	for _, field := range st.AstStructType().Fields.List {
		fields = append(fields, (*FieldInfo)(field))
	}

	return fields
}
621310
func parseStructTag(tag string) map[string]string {
	re := regexp.MustCompile("^([^:\"]+):\"([^\"]*)\" *(.*)")
	result := map[string]string{}

	if tag[0] != '`' || tag[len(tag)-1] != '`' {
		panic(fmt.Sprintf("Expected tag to begin and end with `, got: \"%s\"", tag))
	}

	parseStructTagInner(re, result, tag[1:len(tag)-1])
	return result
}
1266322
func MapToSortedStrings(m map[string]struct{}) []string {
	ss := []string{}
	for k := range m {
		ss = append(ss, k)
	}
	sort.Strings(ss)
	return ss
}
516928
func IsStruct(obj interface{}) bool {
	return obj != nil && reflect.TypeOf(obj).Kind() == reflect.Struct
}
1301318
func (q *Queryx) BindStructMap(arg0 interface{}, arg1 map[string]interface{}) *Queryx {
	arglist, err := bindStructArgs(q.Names, arg0, arg1, q.Mapper)
	if err != nil {
		q.err = fmt.Errorf("bind error: %s", err)
	} else {
		q.err = nil
		q.Bind(arglist...)
	}

	return q
}
708658
func (w *Writer) WriteStruct(st interface{}) error {
	row, err := w.e.GetRow(st)
	if err != nil {
		return err
	}
	w.r++
	return w.w.Write(row)
}
1224677
func MessageToStruct(msg proto.Message) (*types.Struct, error) {
	if msg == nil {
		return nil, errors.New("nil message")
	}

	buf := &bytes.Buffer{}
	if err := (&jsonpb.Marshaler{OrigName: true}).Marshal(buf, msg); err != nil {
		return nil, err
	}

	pbs := &types.Struct{}
	if err := jsonpb.Unmarshal(buf, pbs); err != nil {
		return nil, err
	}

	return pbs, nil
}
457705
func (p *parser) parseStruct(st reflect.Value, path []flagNameComponent) (err error) {
	posStarted := false
	foreachStructField(st, func(f reflect.Value, sf reflect.StructField) (stop bool) {
		if !posStarted && f.Type() == reflect.TypeOf(StartPos{}) {
			posStarted = true
			return false
		}
		if f.Type() == reflect.TypeOf(ExcessArgs{}) {
			p.excess = f.Addr().Interface().(*ExcessArgs)
			return false
		}
		if sf.PkgPath != "" {
			return false
		}
		if p.excess != nil {
			err = ErrFieldsAfterExcessArgs
			return true
		}
		if canMarshal(f) {
			if posStarted {
				err = p.addPos(f, sf, path)
			} else {
				err = p.addFlag(f, sf, path)
				if err != nil {
					err = fmt.Errorf("error adding flag in %s: %s", st.Type(), err)
				}
			}
			return err != nil
		}
		if f.Kind() == reflect.Struct {
			if canMarshal(f.Addr()) {
				err = fmt.Errorf("field %q has type %s, did you mean to use %s?", sf.Name, f.Type(), f.Addr().Type())
				return true
			}
			err = p.parseStruct(f, append(path, structFieldFlagNameComponent(sf)))
			return err != nil
		}
		err = fmt.Errorf("field has bad type: %v", f.Type())
		return true
	})
	return
}
1054504
func CastToMapStringInterface(value interface{}) (map[string]interface{}, bool) {
	castedValue, ok := value.(map[interface{}]interface{})
	desiredMap := map[string]interface{}{}
	for key, value := range castedValue {
		keyStr, ok := key.(string)
		if !ok {
			return map[string]interface{}{}, false
		}
		desiredMap[keyStr] = value
	}
	return desiredMap, ok
}
1019930
func serializeStruct(src interface{}) ([]byte, error) {
	if src == nil {
		return serializeProperties(nil, false)
	}
	if k := reflect.Indirect(reflect.ValueOf(src)).Type().Kind(); k != reflect.Struct {
		return nil, fmt.Errorf("goon: Expected struct, got instead: %v", k)
	}

	var err error
	var props []datastore.Property
	if pls, ok := src.(datastore.PropertyLoadSaver); ok {
		props, err = pls.Save()
	} else {
		props, err = datastore.SaveStruct(src)
	}
	if err != nil {
		return nil, err
	}

	return serializeProperties(props, true)
}
29228
func AnalyzeStructParams(
	requestStruct interface{},
	funcArgs *RequestParams,
	params *RequestParams,
	extraStructs *ExtraStructs,
) {
	reflectStruct, ok := requestStruct.(reflect.Type)
	if !ok {
		reflectStruct = reflect.TypeOf(requestStruct)
	}
	for i := 0; i < reflectStruct.NumField(); i++ {
		field := reflectStruct.Field(i)

		if fieldTag := field.Tag.Get("apijs"); fieldTag == "inherit" {
			AnalyzeStructParams(field.Type, funcArgs, params, extraStructs)
			continue
		}

		if fieldTag := field.Tag.Get("json"); fieldTag != "" {
			if tags := strings.Split(fieldTag, ","); len(tags) > 0 {
				jsonName := tags[0]
				if jsonName == "-" {
					continue
				}

				funcArgs.Upsert(jsonName, &field)
				params.Upsert(jsonName, &field)

				structType := ensureReflectStruct(field.Type)
				switch structType.Kind() {
				case reflect.Struct:
					extraStruct := extraStructs.Upsert(jsonName, field.Type)
					AnalyzeStructParams(
						structType,
						&extraStruct.Params,
						nil,
						extraStructs,
					)
				}
			}
		}
	}
}
563152
func mapToArray(m stringmapflag.Value) []*swarming.SwarmingRpcsStringPair {
	a := make([]*swarming.SwarmingRpcsStringPair, 0, len(m))
	for k, v := range m {
		a = append(a, &swarming.SwarmingRpcsStringPair{Key: k, Value: v})
	}

	sort.Sort(array(a))
	return a
}
345884
func NewStructuralCopy(of FixedDataGrid) *DenseInstances {
	ret, _, _ := copyFixedDataGridStructure(of)
	return ret
}
100903
func CopyMapKeys(m interface{}, typeHint interface{}) interface{} {
	mapVal := reflect.ValueOf(m)
	keys := reflect.MakeSlice(reflect.TypeOf(typeHint), 0, mapVal.Len())
	for _, k := range mapVal.MapKeys() {
		keys = reflect.Append(keys, k)
	}
	return keys.Interface()
}
844721
func (w *Writer) WriteStructs(st interface{}) error {
	rows, err := w.e.Marshal(st)
	if err != nil {
		return err
	}
	w.r = len(rows)
	w.w.WriteAll(rows)
	w.w.Flush()
	return w.w.Error()
}
442344
func convertFromStruct(p interface{}, tagName string) interface{} {
	result := make(map[string]interface{})
	return convertFromStructDeep(result, tagName, toType(p), toValue(p))
}