// convertStructContainerReservation is used to convert between a struct and
// proto ContainerReservation
194013
func convertStructContainerReservation(in *ContainerReservation) *proto.ContainerReservation {
	if in == nil {
		return nil
	}

	return &proto.ContainerReservation{
		Envs:    in.Envs,
		Mounts:  convertStructMounts(in.Mounts),
		Devices: convertStructDeviceSpecs(in.Devices),
	}
}
155386
func convertStructDeviceGroupsStats(in []*DeviceGroupStats) []*proto.DeviceGroupStats {
	if in == nil {
		return nil
	}

	out := make([]*proto.DeviceGroupStats, len(in))
	for i, m := range in {
		out[i] = convertStructDeviceGroupStats(m)
	}

	return out
}
720597
func ConvertPortBindings(portBindings []types.PortBinding) ([]json.RawMessage, error) {
	var pbs []json.RawMessage

	// Enumerate through the port bindings specified by the user and convert
	// them into the internal structure matching the JSON blob that can be
	// understood by the HCS.
	for _, elem := range portBindings {
		proto := strings.ToUpper(elem.Proto.String())
		if proto != "TCP" && proto != "UDP" {
			return nil, fmt.Errorf("invalid protocol %s", elem.Proto.String())
		}

		if elem.HostPort != elem.HostPortEnd {
			return nil, fmt.Errorf("Windows does not support more than one host port in NAT settings")
		}

		if len(elem.HostIP) != 0 {
			return nil, fmt.Errorf("Windows does not support host IP addresses in NAT settings")
		}

		encodedPolicy, err := json.Marshal(hcsshim.NatPolicy{
			Type:         "NAT",
			ExternalPort: elem.HostPort,
			InternalPort: elem.Port,
			Protocol:     elem.Proto.String(),
		})

		if err != nil {
			return nil, err
		}
		pbs = append(pbs, encodedPolicy)
	}
	return pbs, nil
}
1097996
func (c *ContainerServer) ContainerStateToDisk(ctr *oci.Container) error {
	// ignore errors, this is a best effort to have up-to-date info about
	// a given container before its state gets stored
	c.Runtime().UpdateContainerStatus(ctr)

	jsonSource, err := ioutils.NewAtomicFileWriter(ctr.StatePath(), 0644)
	if err != nil {
		return err
	}
	defer jsonSource.Close()
	enc := json.NewEncoder(jsonSource)
	return enc.Encode(ctr.State())
}
167748
func (pp *primitiveParser) visitStruct(reachable map[string]*data, k string, visible bool) {
	if _, ok := reachable[k]; ok { // already included
		return
	}

	s := pp.structmap[k]

	d := data{
		Name: k,
		Byte: pp.typedecls[pp.fset.Position(s.Pos()).Line],
	}
	d.Immutable, d.Version, d.Fields = pp.gatherFields(reachable, s, visible)
	d.Visible = visible || d.Immutable

	sort.Sort(sortFields(d.Fields))
	reachable[k] = &d
}
874581
func deserializeStruct(dst interface{}, b []byte) error {
	if len(b) == 0 {
		return fmt.Errorf("goon: Expected some data to deserialize, got none.")
	}
	if k := reflect.Indirect(reflect.ValueOf(dst)).Type().Kind(); k != reflect.Struct {
		return fmt.Errorf("goon: Expected struct, got instead: %v", k)
	}

	// Deserialize the header
	header := binary.LittleEndian.Uint32(b[:4])
	propCount, flags := deserializeEntityHeader(header)
	if flags&entityExists == 0 {
		return datastore.ErrNoSuchEntity
	}

	// Deserialize the properties
	buf := bytes.NewBuffer(b[4:])
	props := make([]datastore.Property, propCount)
	for i := 0; i < propCount; i++ {
		if err := deserializeProperty(buf, &props[i]); err != nil {
			return err
		}
	}

	return deserializeProperties(dst, props)
}
742705
func Convert_build_DockerBuildStrategy_To_v1_DockerBuildStrategy(in *build.DockerBuildStrategy, out *v1.DockerBuildStrategy, s conversion.Scope) error {
	return autoConvert_build_DockerBuildStrategy_To_v1_DockerBuildStrategy(in, out, s)
}
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
}
1222660
func (pp *primitiveParser) loadStructs() {
	pp.structmap = make(map[string]*ast.StructType)

	for k, o := range pp.p.Scope.Objects {
		// We only care about types
		if o.Kind != ast.Typ {
			continue
		}
		ts, ok := o.Decl.(*ast.TypeSpec)
		if !ok {
			continue
		}

		// and to be more exact, only struct types
		s, ok := ts.Type.(*ast.StructType)
		if !ok {
			continue
		}

		// Empty struct? We don't need to generate and json for it. skip.
		if len(s.Fields.List) == 0 {
			continue
		}

		pp.structmap[k] = s
	}
}
1081
func convertStructDevices(in []*Device) []*proto.DetectedDevice {
	if in == nil {
		return nil
	}

	out := make([]*proto.DetectedDevice, len(in))
	for i, d := range in {
		out[i] = convertStructDevice(d)
	}

	return out
}
923675
func (cMgr *ConfigurationManager) handleStruct(rValue reflect.Value, tagName string) error {
	structType := rValue.Type()
	numOfField := structType.NumField()

	for i := 0; i < numOfField; i++ {
		structField := structType.Field(i)
		fieldValue := rValue.Field(i)
		keyName := cMgr.getKeyName(structField.Name, structField.Tag)
		if keyName == ignoreField {
			return nil
		}

		switch structField.Type.Kind() {
		case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
			reflect.Float32, reflect.Float64, reflect.Uint, reflect.Uint8, reflect.Uint16,
			reflect.Uint32, reflect.Uint64, reflect.Bool, reflect.Interface, reflect.Array,
			reflect.Slice:
			if fieldValue.CanSet() {
				err := cMgr.setValue(fieldValue, getTagKey(tagName, keyName))
				if err != nil {
					return err
				}
			}
		case reflect.Ptr:
			err := cMgr.handlePtr(fieldValue, getTagKey(tagName, keyName))
			if err != nil {
				return err
			}
		case reflect.Struct:
			err := cMgr.handleStruct(fieldValue, getTagKey(tagName, keyName))
			if err != nil {
				return err
			}
		case reflect.Map:
			err := cMgr.handleMap(rValue, fieldValue, getTagKey(tagName, keyName))
			if err != nil {
				return err
			}
		case reflect.Uintptr, reflect.Complex64, reflect.Complex128, reflect.Chan, reflect.Func,
			reflect.UnsafePointer:
			// ignore
		}
	}

	return nil
}
114548
func Convert_core_ContainerStateWaiting_To_v1_ContainerStateWaiting(in *core.ContainerStateWaiting, out *v1.ContainerStateWaiting, s conversion.Scope) error {
	return autoConvert_core_ContainerStateWaiting_To_v1_ContainerStateWaiting(in, out, s)
}
184295
func Convert_core_ContainerStatus_To_v1_ContainerStatus(in *core.ContainerStatus, out *v1.ContainerStatus, s conversion.Scope) error {
	return autoConvert_core_ContainerStatus_To_v1_ContainerStatus(in, out, s)
}
793239
func (r *Reflector) reflectStruct(definitions Definitions, t reflect.Type) *Type {
	st := &Type{
		Type:                 "object",
		Properties:           map[string]*Type{},
		AdditionalProperties: []byte("false"),
	}
	if r.AllowAdditionalProperties {
		st.AdditionalProperties = []byte("true")
	}
	definitions[t.Name()] = st
	r.reflectStructFields(st, definitions, t)

	return &Type{
		Version: Version,
		Ref:     "#/definitions/" + t.Name(),
	}
}
545550
func ParseContainerType(ctype string) (ContainerType, error) {
	for _, supportedType := range ContainerTypes {
		if ContainerType(ctype) == supportedType {
			return supportedType, nil
		}
	}
	return "", fmt.Errorf("invalid container type %q", ctype)
}
1364390
func Convert(obj interface{}) (url.Values, error) {
	result := url.Values{}
	if obj == nil {
		return result, nil
	}
	var sv reflect.Value
	switch reflect.TypeOf(obj).Kind() {
	case reflect.Ptr, reflect.Interface:
		sv = reflect.ValueOf(obj).Elem()
	default:
		return nil, fmt.Errorf("expecting a pointer or interface")
	}
	st := sv.Type()
	if !isStructKind(st.Kind()) {
		return nil, fmt.Errorf("expecting a pointer to a struct")
	}

	// Check all object fields
	convertStruct(result, st, sv)

	return result, nil
}
106348
func (e *Encoder) encodeStruct(valueField reflect.Value, typeField reflect.StructField, key string) error {
	e.currentRecursion++
	if e.currentRecursion > e.maxRecursion {
		return nil
	}

	e.parentKey += key
	err := e.encode(valueField)
	if err != nil {
		return err
	}

	// Do not reset the key if we are dealing with an embedded struct
	// as recursion level increases by one compared to normal cases
	if !typeField.Anonymous {
		e.parentKey = ""
	}

	e.currentRecursion--
	return nil
}