// ValidateStruct receives any kind of type, but only performed struct or pointer to struct type.
334341
func (v *defaultValidator) ValidateStruct(obj interface{}) error {
	value := reflect.ValueOf(obj)
	valueType := value.Kind()
	if valueType == reflect.Ptr {
		valueType = value.Elem().Kind()
	}
	if valueType == reflect.Struct {
		v.lazyinit()
		if err := v.validate.Struct(obj); err != nil {
			return err
		}
	}
	return nil
}
163725
func validate(um *Unmarshaller, s interface{}, headers []string) error {
	concreteType := reflect.TypeOf(s)
	if concreteType.Kind() == reflect.Ptr {
		concreteType = concreteType.Elem()
	}
	if err := ensureOutInnerType(concreteType); err != nil {
		return err
	}
	structInfo := getStructInfo(concreteType) // Get struct info to get CSV annotations.
	if len(structInfo.Fields) == 0 {
		return errors.New("no csv struct tags found")
	}
	csvHeaders := make(map[int]string)                                   // Map of columm index to header name
	csvHeadersLabels := make(map[int]*fieldInfo, len(structInfo.Fields)) // Used to store the corresponding header <-> position in CSV
	headerCount := map[string]int{}
	for i, csvColumnHeader := range headers {
		csvHeaders[i] = csvColumnHeader
		curHeaderCount := headerCount[csvColumnHeader]
		if fieldInfo := getCSVFieldPosition(csvColumnHeader, structInfo, curHeaderCount); fieldInfo != nil {
			csvHeadersLabels[i] = fieldInfo
			if ShouldAlignDuplicateHeadersWithStructFieldOrder {
				curHeaderCount++
				headerCount[csvColumnHeader] = curHeaderCount
			}
		}
	}
	if err := maybeDoubleHeaderNames(headers); err != nil {
		return err
	}

	um.headerMap = csvHeaders
	um.fieldInfoMap = csvHeadersLabels
	um.MismatchedHeaders = mismatchHeaderFields(structInfo.Fields, headers)
	um.MismatchedStructFields = mismatchStructFields(structInfo.Fields, headers)
	return nil
}
1233423
func (reps *MonthDownloadCSV) ConvertToStructs() (*MonthDownloadStructs, error) {
	var theseReports MonthDownloadStructs

	if reps.PriceSheetReport != "" {
		err := theseReports.convertPriceSheet(&reps.PriceSheetReport)
		if err != nil {
			return nil, err
		}
	}

	if reps.DetailReport != "" {
		err := theseReports.convertDetailReport(&reps.DetailReport)
		if err != nil {
			return nil, err
		}
	}

	return &theseReports, nil
}
1230182
func (c *Client) StoreStruct(bucket, key string, in interface{}) (*RpbPutResp, error) {
	return c.storeStruct(nil, bucket, key, in)
}
214350
func TableFromStructs(structs Slice) *Table {
	s := reflectSlice(structs)
	st := s.Type()
	if st.Elem().Kind() != reflect.Struct {
		panic(&generic.TypeError{st, nil, "is not a slice of struct"})
	}

	var t Builder
	rows := s.Len()
	var rec func(reflect.Type, []int)
	rec = func(typ reflect.Type, index []int) {
		for fn := 0; fn < typ.NumField(); fn++ {
			field := typ.Field(fn)
			if field.PkgPath != "" {
				continue
			}
			oldIndexLen := len(index)
			index = append(index, field.Index...)
			if field.Anonymous {
				rec(field.Type, index)
			} else {
				col := reflect.MakeSlice(reflect.SliceOf(field.Type), rows, rows)
				for i := 0; i < rows; i++ {
					col.Index(i).Set(s.Index(i).FieldByIndex(index))
				}
				t.Add(field.Name, col.Interface())
			}
			index = index[:oldIndexLen]
		}
	}
	rec(st.Elem(), []int{})
	return t.Done()
}
1173939
func MustEncodeStruct(src interface{}) BSON {
	b, err := encodeStruct("", src)
	if err != nil {
		panic(err)
	}
	return b
}
455939
func (f paramFiller) paramsStructStruct(value map[string]interface{}, shape *Shape) string {
	out := "&" + f.typeName(shape)[1:] + "{\n"
	for _, n := range shape.MemberNames() {
		ref := shape.MemberRefs[n]
		name := findParamMember(value, n)

		if val := f.paramsStructAny(value[name], ref.Shape); val != "" {
			out += fmt.Sprintf("%s: %s,\n", n, val)
		}
	}
	out += "}"
	return out
}
442344
func convertFromStruct(p interface{}, tagName string) interface{} {
	result := make(map[string]interface{})
	return convertFromStructDeep(result, tagName, toType(p), toValue(p))
}
422044
func (s *StructInjector) fillStruct() {
	if !s.Has {
		return
	}
	// if field is Static then set it to the value that passed by the caller,
	// so will have the static bindings already and we can just use that value instead
	// of creating new instance.
	destElem := IndirectValue(s.initRef)
	for _, f := range s.fields {
		// if field is Static then set it to the value that passed by the caller,
		// so will have the static bindings already and we can just use that value instead
		// of creating new instance.
		if f.Object.BindType == Static {
			destElem.FieldByIndex(f.FieldIndex).Set(f.Object.Value)
		}
	}
}
1321709
func GetStructType(alias string) (structType reflect.Type) {
	structTypesLocker.RLock()
	structType = structTypes[alias]
	structTypesLocker.RUnlock()
	return structType
}
629995
func equalStruct(v1, v2 reflect.Value) bool {
	sprop := GetProperties(v1.Type())
	for i := 0; i < v1.NumField(); i++ {
		f := v1.Type().Field(i)
		if strings.HasPrefix(f.Name, "XXX_") {
			continue
		}
		f1, f2 := v1.Field(i), v2.Field(i)
		if f.Type.Kind() == reflect.Ptr {
			if n1, n2 := f1.IsNil(), f2.IsNil(); n1 && n2 {
				// both unset
				continue
			} else if n1 != n2 {
				// set/unset mismatch
				return false
			}
			f1, f2 = f1.Elem(), f2.Elem()
		}
		if !equalAny(f1, f2, sprop.Prop[i]) {
			return false
		}
	}

	if em1 := v1.FieldByName("XXX_InternalExtensions"); em1.IsValid() {
		em2 := v2.FieldByName("XXX_InternalExtensions")
		if !equalExtensions(v1.Type(), em1.Interface().(XXX_InternalExtensions), em2.Interface().(XXX_InternalExtensions)) {
			return false
		}
	}

	if em1 := v1.FieldByName("XXX_extensions"); em1.IsValid() {
		em2 := v2.FieldByName("XXX_extensions")
		if !equalExtMap(v1.Type(), em1.Interface().(map[int32]Extension), em2.Interface().(map[int32]Extension)) {
			return false
		}
	}

	uf := v1.FieldByName("XXX_unrecognized")
	if !uf.IsValid() {
		return true
	}

	u1 := uf.Bytes()
	u2 := v2.FieldByName("XXX_unrecognized").Bytes()
	return bytes.Equal(u1, u2)
}
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()
}
124413
func (s *Shape) GoStructType(name string, ref *ShapeRef) string {
	if (ref.Streaming || ref.Shape.Streaming) && s.Payload == name {
		rtype := "io.ReadSeeker"
		if strings.HasSuffix(s.ShapeName, "Output") {
			rtype = "io.ReadCloser"
		}

		s.API.imports["io"] = true
		return rtype
	}

	if ref.JSONValue {
		s.API.AddSDKImport("aws")
		return "aws.JSONValue"
	}

	for _, v := range s.Validations {
		// TODO move this to shape validation resolution
		if (v.Ref.Shape.Type == "map" || v.Ref.Shape.Type == "list") && v.Type == ShapeValidationNested {
			s.API.imports["fmt"] = true
		}
	}

	return ref.GoType()
}
117444
func (v *validate) validateStruct(ctx context.Context, parent reflect.Value, current reflect.Value, typ reflect.Type, ns []byte, structNs []byte, ct *cTag) {

	cs, ok := v.v.structCache.Get(typ)
	if !ok {
		cs = v.v.extractStructCache(current, typ.Name())
	}

	if len(ns) == 0 && len(cs.name) != 0 {

		ns = append(ns, cs.name...)
		ns = append(ns, '.')

		structNs = append(structNs, cs.name...)
		structNs = append(structNs, '.')
	}

	// ct is nil on top level struct, and structs as fields that have no tag info
	// so if nil or if not nil and the structonly tag isn't present
	if ct == nil || ct.typeof != typeStructOnly {

		var f *cField

		for i := 0; i < len(cs.fields); i++ {

			f = cs.fields[i]

			if v.isPartial {

				if v.ffn != nil {
					// used with StructFiltered
					if v.ffn(append(structNs, f.name...)) {
						continue
					}

				} else {
					// used with StructPartial & StructExcept
					_, ok = v.includeExclude[string(append(structNs, f.name...))]

					if (ok && v.hasExcludes) || (!ok && !v.hasExcludes) {
						continue
					}
				}
			}

			v.traverseField(ctx, parent, current.Field(f.idx), ns, structNs, f, f.cTags)
		}
	}

	// check if any struct level validations, after all field validations already checked.
	// first iteration will have no info about nostructlevel tag, and is checked prior to
	// calling the next iteration of validateStruct called from traverseField.
	if cs.fn != nil {

		v.slflParent = parent
		v.slCurrent = current
		v.ns = ns
		v.actualNs = structNs

		cs.fn(ctx, v)
	}
}
1002840
func (b *xmlBuilder) buildStruct(value reflect.Value, current *XMLNode, tag reflect.StructTag) error {
	if !value.IsValid() {
		return nil
	}

	// unwrap payloads
	if payload := tag.Get("payload"); payload != "" {
		field, _ := value.Type().FieldByName(payload)
		tag = field.Tag
		value = elemOf(value.FieldByName(payload))

		if !value.IsValid() {
			return nil
		}
	}

	child := NewXMLElement(xml.Name{Local: tag.Get("locationName")})

	// there is an xmlNamespace associated with this struct
	if prefix, uri := tag.Get("xmlPrefix"), tag.Get("xmlURI"); uri != "" {
		ns := xml.Attr{
			Name:  xml.Name{Local: "xmlns"},
			Value: uri,
		}
		if prefix != "" {
			b.namespaces[prefix] = uri // register the namespace
			ns.Name.Local = "xmlns:" + prefix
		}

		child.Attr = append(child.Attr, ns)
	}

	var payloadFields, nonPayloadFields int

	t := value.Type()
	for i := 0; i < value.NumField(); i++ {
		member := elemOf(value.Field(i))
		field := t.Field(i)

		if field.PkgPath != "" {
			continue // ignore unexported fields
		}
		if field.Tag.Get("ignore") != "" {
			continue
		}

		mTag := field.Tag
		if mTag.Get("location") != "" { // skip non-body members
			nonPayloadFields++
			continue
		}
		payloadFields++

		if protocol.CanSetIdempotencyToken(value.Field(i), field) {
			token := protocol.GetIdempotencyToken()
			member = reflect.ValueOf(token)
		}

		memberName := mTag.Get("locationName")
		if memberName == "" {
			memberName = field.Name
			mTag = reflect.StructTag(string(mTag) + ` locationName:"` + memberName + `"`)
		}
		if err := b.buildValue(member, child, mTag); err != nil {
			return err
		}
	}

	// Only case where the child shape is not added is if the shape only contains
	// non-payload fields, e.g headers/query.
	if !(payloadFields == 0 && nonPayloadFields > 0) {
		current.AddChild(child)
	}

	return nil
}
708029
func ValidateNode(node *api.Node) field.ErrorList {
	allErrs := ValidateObjectMeta(&node.ObjectMeta, false, ValidateNodeName, field.NewPath("metadata"))

	// Only validate spec. All status fields are optional and can be updated later.

	// external ID is required.
	if len(node.Spec.ExternalID) == 0 {
		allErrs = append(allErrs, field.Required(field.NewPath("spec", "externalID"), ""))
	}

	// TODO(rjnagal): Ignore PodCIDR till its completely implemented.
	return allErrs
}
408132
func (t *TypeInfo) StructType() (*StructTypeInfo, error) {
	structType, ok := interface{}(t.TypeSpec.Type).(*ast.StructType)
	if !ok {
		return nil, ErrNotStructType
	}

	return (*StructTypeInfo)(structType), nil
}