// Create a new mutable FieldType with all of the properties from <code>ref</code>
327073
func NewFieldTypeFrom(ref *FieldType) *FieldType {
	ft := newFieldType()
	ft.indexed = ref.indexed
	ft.stored = ref.stored
	ft._tokenized = ref._tokenized
	ft.storeTermVectors = ref.storeTermVectors
	ft.storeTermVectorOffsets = ref.storeTermVectorOffsets
	ft.storeTermVectorPositions = ref.storeTermVectorPositions
	ft.storeTermVectorPayloads = ref.storeTermVectorPayloads
	ft._omitNorms = ref._omitNorms
	ft._indexOptions = ref._indexOptions
	ft._docValueType = ref._docValueType
	ft.numericType = ref.numericType
	// Do not copy frozen!
	return ft
}
1041220
func (t SimpleType) ConvertToModelWithType(newFieldType FieldType, v interface{}) (interface{}, error) {
	// Try to assign the old value to the new field
	newVal, err := newFieldType.ConvertToModel(v)
	if err == nil {
		return newVal, nil
	}

	// if the new type is a list, stuff the old value in a list and
	// try to assign it
	if newFieldType.GetKind() == KindList {
		newVal, err = newFieldType.ConvertToModel([]interface{}{v})
		if err == nil {
			return newVal, nil
		}
	}

	// if the old type is a list but the new one isn't check that
	// the list contains only one element and assign that
	if t.GetKind() == KindList && newFieldType.GetKind() != KindList {
		ifArr, ok := v.([]interface{})
		if !ok {
			return nil, errs.Errorf("failed to convert value to interface array: %+v", v)
		}
		if len(ifArr) == 1 {
			newVal, err = newFieldType.ConvertToModel(ifArr[0])
			if err == nil {
				return newVal, nil
			}
		}
	}
	return nil, errs.Errorf("failed to convert value %+v (%[1]T) to field type %+v (%[2]T)", v, newFieldType)
}
929931
func (r *Registry) newReference(item mo.Reference) types.ManagedObjectReference {
	ref := item.Reference()

	if ref.Type == "" {
		ref.Type = typeName(item)
	}

	if ref.Value == "" {
		n := atomic.AddInt64(&r.counter, 1)
		ref.Value = fmt.Sprintf("%s-%d", valuePrefix(ref.Type), n)
	}

	return ref
}
35844
func NewParametersOrReferences(in interface{}, context *compiler.Context) (*ParametersOrReferences, error) {
	errors := make([]error, 0)
	x := &ParametersOrReferences{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		// repeated NamedParameterOrReference additional_properties = 1;
		// MAP: ParameterOrReference
		x.AdditionalProperties = make([]*NamedParameterOrReference, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				pair := &NamedParameterOrReference{}
				pair.Name = k
				var err error
				pair.Value, err = NewParameterOrReference(v, compiler.NewContext(k, context))
				if err != nil {
					errors = append(errors, err)
				}
				x.AdditionalProperties = append(x.AdditionalProperties, pair)
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
1196803
func NewPropertyFieldTemplate(Name string, Description string, Type *PropertyType) *PropertyFieldTemplate {
	s := new(PropertyFieldTemplate)
	s.Name = Name
	s.Description = Description
	s.Type = Type
	return s
}
781034
func typeReference(g Generator, spec compile.TypeSpec) (string, error) {
	name, err := typeName(g, spec)
	if err != nil {
		return "", err
	}
	if isStructType(spec) {
		// Prepend "*" to the result if the field is not required and the type
		// isn't a reference type.
		name = "*" + name
	}
	return name, nil
}
491307
func Ref(ref interface{}) interface{} {
	switch v := ref.(type) {
	case NamedResource:
		ref = v.Name
	}
	return map[string]interface{}{"Ref": ref}
}
1176946
func NewBlobFieldDescriptor(nullable NullableColumn, metadata []byte) (
	fd FieldDescriptor,
	remaining []byte,
	err error) {

	if len(metadata) < 1 {
		return nil, nil, errors.New("Metadata has too few bytes")
	}

	packedLen := LittleEndian.Uint8(metadata)

	if packedLen > 4 {
		return nil, nil, errors.New("Invalid packed length")
	}

	return &blobFieldDescriptor{
		packedLengthFieldDescriptor: packedLengthFieldDescriptor{
			baseFieldDescriptor: baseFieldDescriptor{
				fieldType:  mysql_proto.FieldType_BLOB,
				isNullable: nullable,
			},
			packedLength: int(packedLen),
		},
	}, metadata[1:], nil
}
443528
func newFieldType() *FieldType {
	return &FieldType{
		_tokenized:           true,
		_indexOptions:        model.INDEX_OPT_DOCS_AND_FREQS_AND_POSITIONS,
		numericPrecisionStep: util.NUMERIC_PRECISION_STEP_DEFAULT,
	}
}
1349873
func newFields() *fields {
	f := new(fields)
	f.fields = make(map[string]*fieldInfo)
	f.fieldsLow = make(map[string]*fieldInfo)
	f.columns = make(map[string]*fieldInfo)
	f.fieldsByType = make(map[int][]*fieldInfo)
	return f
}
542566
func (fg FieldGroup) ForEachTypeReference(f func(TypeSpec) error) error {
	for _, field := range fg {
		if err := f(field.Type); err != nil {
			return err
		}
	}
	return nil
}
495110
func (b *FooJSONBuilder) Add(info *FooPropertyInfo) *FooJSONBuilder {
	b._properties[info.fieldName] = info
	return b
}
167585
func NewProperties(in interface{}, context *compiler.Context) (*Properties, error) {
	errors := make([]error, 0)
	x := &Properties{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		// repeated NamedSchemaOrReference additional_properties = 1;
		// MAP: SchemaOrReference
		x.AdditionalProperties = make([]*NamedSchemaOrReference, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				pair := &NamedSchemaOrReference{}
				pair.Name = k
				var err error
				pair.Value, err = NewSchemaOrReference(v, compiler.NewContext(k, context))
				if err != nil {
					errors = append(errors, err)
				}
				x.AdditionalProperties = append(x.AdditionalProperties, pair)
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
285692
func fieldUnmarshaler(f *reflect.StructField) unmarshaler {
	if f.Type.Kind() == reflect.Map {
		return makeUnmarshalMap(f)
	}
	return typeUnmarshaler(f.Type, f.Tag.Get("protobuf"))
}
992257
func (f *Field) Type() string {
	f.mu.RLock()
	defer f.mu.RUnlock()
	return f.options.Type
}
606805
func addTypeMetaProperties(s *spec.Schema) {
	s.SetProperty("apiVersion", getDefinition(typeMetaType).SchemaProps.Properties["apiVersion"])
	s.SetProperty("kind", getDefinition(typeMetaType).SchemaProps.Properties["kind"])
}
389107
func (gq *Schema) AppendType(objectType Type) error {
	if objectType.Error() != nil {
		return objectType.Error()
	}
	var err error
	gq.typeMap, err = typeMapReducer(gq, gq.typeMap, objectType)
	if err != nil {
		return err
	}
	//Now Add interface implementation..
	return gq.AddImplementation()
}