// Maps the given reflect.Type to the given reflect.Value and returns
// the Typemapper the mapping has been registered in.
325050
func (i *injector) Set(typ reflect.Type, val reflect.Value) TypeMapper {
	i.values[typ] = val
	return i
}
640779
func (r *Reflector) Reflect(v interface{}) *Schema {
	return r.ReflectFromType(reflect.TypeOf(v))
}
697236
func (typedData *TypedData) Map() map[string]interface{} {
	dataMap := map[string]interface{}{
		"types":       typedData.Types,
		"domain":      typedData.Domain.Map(),
		"primaryType": typedData.PrimaryType,
		"message":     typedData.Message,
	}
	return dataMap
}
944952
func Map(f, input interface{}) interface{} {
	inputValue := reflect.ValueOf(input)
	funcValue := reflect.ValueOf(f)
	_len := inputValue.Len()
	retValue := reflect.MakeSlice(reflect.TypeOf(input), _len, _len)
	for i := 0; i < _len; i++ {
		out := funcValue.Call([]reflect.Value{inputValue.Index(i)})
		retValue.Index(i).Set(out[0])
	}
	return retValue.Interface()
}
123131
func (t Result) Map() map[string]Result {
	if t.Type != JSON {
		return map[string]Result{}
	}
	r := t.arrayOrMap('{', false)
	return r.o
}
1044238
func typeMismatchReason(p Property, v reflect.Value) string {
	entityType := "empty"
	switch p.Value.(type) {
	case int64:
		entityType = "int"
	case bool:
		entityType = "bool"
	case string:
		entityType = "string"
	case float64:
		entityType = "float"
	case *Key:
		entityType = "*datastore.Key"
	case time.Time:
		entityType = "time.Time"
	case appengine.BlobKey:
		entityType = "appengine.BlobKey"
	case appengine.GeoPoint:
		entityType = "appengine.GeoPoint"
	case ByteString:
		entityType = "datastore.ByteString"
	case []byte:
		entityType = "[]byte"
	}
	return fmt.Sprintf("type mismatch: %s versus %v", entityType, v.Type())
}
135154
func NewValue(t reflect.Type) (v reflect.Value) {
	v = reflect.New(t)
	ov := v
	for t.Kind() == reflect.Ptr {
		v = v.Elem()
		t = t.Elem()
		e := reflect.New(t)
		v.Set(e)
	}

	if e := v.Elem(); e.Kind() == reflect.Map && e.IsNil() {
		v.Elem().Set(reflect.MakeMap(v.Elem().Type()))
	}
	return ov
}
1296960
func Deref(t reflect.Type) reflect.Type {
	if t.Kind() == reflect.Ptr {
		t = t.Elem()
	}
	return t
}
96335
func LookupPatchMetadata(t reflect.Type, jsonField string) (reflect.Type, string, string, error) {
	if t.Kind() == reflect.Map {
		return t.Elem(), "", "", nil
	}
	if t.Kind() != reflect.Struct {
		return nil, "", "", fmt.Errorf("merging an object in json but data type is not map or struct, instead is: %s",
			t.Kind().String())
	}
	jf := []byte(jsonField)
	// Find the field that the JSON library would use.
	var f *field
	fields := cachedTypeFields(t)
	for i := range fields {
		ff := &fields[i]
		if bytes.Equal(ff.nameBytes, jf) {
			f = ff
			break
		}
		// Do case-insensitive comparison.
		if f == nil && ff.equalFold(ff.nameBytes, jf) {
			f = ff
		}
	}
	if f != nil {
		// Find the reflect.Value of the most preferential struct field.
		tjf := t.Field(f.index[0])
		// we must navigate down all the anonymously included structs in the chain
		for i := 1; i < len(f.index); i++ {
			tjf = tjf.Type.Field(f.index[i])
		}
		patchStrategy := tjf.Tag.Get("patchStrategy")
		patchMergeKey := tjf.Tag.Get("patchMergeKey")
		return tjf.Type, patchStrategy, patchMergeKey, nil
	}
	return nil, "", "", fmt.Errorf("unable to find api field in struct %s for the json field %q", t.Name(), jsonField)
}
617082
func (s Shrink) Map(f interface{}) Shrink {
	mapperVal := reflect.ValueOf(f)
	mapperType := mapperVal.Type()

	if mapperVal.Kind() != reflect.Func {
		panic(fmt.Sprintf("Param of Map has to be a func, but is %v", mapperType.Kind()))
	}
	if mapperType.NumIn() != 1 {
		panic(fmt.Sprintf("Param of Map has to be a func with one param, but is %v", mapperType.NumIn()))
	}
	if mapperType.NumOut() != 1 {
		panic(fmt.Sprintf("Param of Map has to be a func with one return value, but is %v", mapperType.NumOut()))
	}

	return func() (interface{}, bool) {
		value, ok := s()
		if ok {
			return mapperVal.Call([]reflect.Value{reflect.ValueOf(value)})[0].Interface(), ok
		}
		return nil, false
	}
}
86954
func (r *Reflector) ReflectFromType(t reflect.Type) *Schema {
	definitions := Definitions{}
	if r.ExpandedStruct {
		st := &Type{
			Version:              Version,
			Type:                 "object",
			Properties:           map[string]*Type{},
			AdditionalProperties: []byte("false"),
		}
		if r.AllowAdditionalProperties {
			st.AdditionalProperties = []byte("true")
		}
		r.reflectStructFields(st, definitions, t)
		r.reflectStruct(definitions, t)
		delete(definitions, t.Name())
		return &Schema{Type: st, Definitions: definitions}
	}

	s := &Schema{
		Type:        r.reflectTypeToSchema(definitions, t),
		Definitions: definitions,
	}
	return s
}
647567
func (j *Json) Map() (map[string]interface{}, error) {
	if m, ok := (j.data).(map[string]interface{}); ok {
		return m, nil
	}
	return nil, errors.New("type assertion to map[string]interface{} failed")
}
1004439
func typeFields(t reflect.Type) []field {
	// Anonymous fields to explore at the current level and the next.
	current := []field{}
	next := []field{{typ: t}}

	// Count of queued names for current level and the next.
	count := map[reflect.Type]int{}
	nextCount := map[reflect.Type]int{}

	// Types already visited at an earlier level.
	visited := map[reflect.Type]bool{}

	// Fields found.
	var fields []field

	for len(next) > 0 {
		current, next = next, current[:0]
		count, nextCount = nextCount, map[reflect.Type]int{}

		for _, f := range current {
			if visited[f.typ] {
				continue
			}
			visited[f.typ] = true

			// Scan f.typ for fields to include.
			for i := 0; i < f.typ.NumField(); i++ {
				sf := f.typ.Field(i)
				if sf.PkgPath != "" && !sf.Anonymous { // unexported
					continue
				}
				// Extract field name from tag
				tag := getTag(sf)
				if tag == "-" {
					continue
				}
				name, opts := parseTag(tag)
				name, compoundIndex, isCompound := parseCompoundIndex(name)
				if !isValidTag(name) {
					name = ""
				}
				// Extract referenced field from tags
				refTag := getRefTag(sf)
				ref, _ := parseTag(refTag)
				if !isValidTag(ref) {
					ref = ""
				}

				index := make([]int, len(f.index)+1)
				copy(index, f.index)
				index[len(f.index)] = i

				ft := sf.Type
				if ft.Name() == "" && ft.Kind() == reflect.Ptr {
					// Follow pointer.
					ft = ft.Elem()
				}

				// Record found field and index sequence.
				if name != "" || !sf.Anonymous || ft.Kind() != reflect.Struct || isPseudoType(ft) {
					tagged := name != ""
					if name == "" {
						name = sf.Name
					}
					fields = append(fields, fillField(field{
						name:          name,
						tag:           tagged,
						index:         index,
						typ:           ft,
						omitEmpty:     opts.Contains("omitempty"),
						reference:     opts.Contains("reference"),
						refName:       ref,
						compound:      isCompound,
						compoundIndex: compoundIndex,
					}))
					if count[f.typ] > 1 {
						// If there were multiple instances, add a second,
						// so that the annihilation code will see a duplicate.
						// It only cares about the distinction between 1 or 2,
						// so don't bother generating any more copies.
						fields = append(fields, fields[len(fields)-1])
					}
					continue
				}

				// Record new anonymous struct to explore in next round.
				nextCount[ft]++
				if nextCount[ft] == 1 {
					next = append(next, fillField(field{name: ft.Name(), index: index, typ: ft}))
				}
			}
		}
	}

	sort.Sort(byName(fields))

	// Delete all fields that are hidden by the Go rules for embedded fields,
	// except that fields with valid tags are promoted.

	// The fields are sorted in primary order of name, secondary order
	// of field index length. Loop over names; for each name, delete
	// hidden fields by choosing the one dominant field that survives.
	out := fields[:0]
	for advance, i := 0, 0; i < len(fields); i += advance {
		// One iteration per name.
		// Find the sequence of fields with the name of this first field.
		fi := fields[i]
		for advance = 1; i+advance < len(fields); advance++ {
			fj := fields[i+advance]
			if fj.name != fi.name {
				break
			}
			if fi.compound && fj.compound && fi.compoundIndex != fj.compoundIndex {
				break
			}

		}
		if advance == 1 { // Only one field with this name
			out = append(out, fi)
			continue
		}
		dominant, ok := dominantField(fields[i : i+advance])
		if ok {
			out = append(out, dominant)
		}
	}

	fields = out
	sort.Sort(byIndex(fields))

	return fields
}
605044
func convertMap(in map[interface{}]interface{}) map[string]interface{} {
  rtn := make(map[string]interface{})
  for key, val := range in {
    // if the value is a map of interface interfaces
    // make sure to convert them as well    
    var newValue interface{}
    switch val.(type) {
      case []interface{}:
        newValue = convertArray(val.([]interface{}))
      case map[interface{}]interface{}:
        newValue = convertMap(val.(map[interface{}]interface{}))
      default:
        newValue = val
    }

    switch key.(type) {
    case string:
      rtn[key.(string)] = newValue
    }
  }

  return rtn  
}
1208660
func typeReferencePtr(g Generator, spec compile.TypeSpec) (string, error) {
	ref, err := typeName(g, spec)
	if err != nil {
		return "", err
	}
	if !isReferenceType(spec) {
		// need * prefix for everything but map, string, and list.
		return "*" + ref, nil
	}
	return ref, nil
}
266158
func (s *PutMappingService) Type(typ string) *PutMappingService {
	s.typ = typ
	return s
}
1042599
func IsMap(val Value) bool {
	r := reflect.Indirect(reflect.ValueOf(val))
	return r.Kind() == reflect.Map
}