// SetValue sets an addressable value to the data passed to this function.
// In contrast to golangs reflect package this will also work with private
// variables. Please note that this function may not support all types, yet.
193187
func SetValue(member reflect.Value, data interface{}) {
	if member.CanSet() {
		member.Set(reflect.ValueOf(data).Convert(member.Type()))
		return // ### return, easy way ###
	}

	if !member.CanAddr() {
		panic("SetValue requires addressable member type")
	}

	ptrToMember := unsafe.Pointer(member.UnsafeAddr())
	dataValue := reflect.ValueOf(data)

	switch member.Kind() {
	case reflect.Bool:
		*(*bool)(ptrToMember) = dataValue.Bool()

	case reflect.Uint:
		*(*uint)(ptrToMember) = uint(dataValue.Uint())

	case reflect.Uint8:
		*(*uint8)(ptrToMember) = uint8(dataValue.Uint())

	case reflect.Uint16:
		*(*uint16)(ptrToMember) = uint16(dataValue.Uint())

	case reflect.Uint32:
		*(*uint32)(ptrToMember) = uint32(dataValue.Uint())

	case reflect.Uint64:
		*(*uint64)(ptrToMember) = dataValue.Uint()

	case reflect.Int:
		*(*int)(ptrToMember) = int(dataValue.Int())

	case reflect.Int8:
		*(*int8)(ptrToMember) = int8(dataValue.Int())

	case reflect.Int16:
		*(*int16)(ptrToMember) = int16(dataValue.Int())

	case reflect.Int32:
		*(*int32)(ptrToMember) = int32(dataValue.Int())

	case reflect.Int64:
		*(*int64)(ptrToMember) = dataValue.Int()

	case reflect.Float32:
		*(*float32)(ptrToMember) = float32(dataValue.Float())

	case reflect.Float64:
		*(*float64)(ptrToMember) = dataValue.Float()

	case reflect.Complex64:
		*(*complex64)(ptrToMember) = complex64(dataValue.Complex())

	case reflect.Complex128:
		*(*complex128)(ptrToMember) = dataValue.Complex()

	case reflect.String:
		*(*string)(ptrToMember) = dataValue.String()

	case reflect.Map, reflect.Chan:
		// Exploit the fact that "map" is actually "*runtime.hmap" and force
		// overwrite that pointer in the passed struct.
		// Same foes for "chan" which is actually "*runtime.hchan".

		// Note: Assigning a map or channel to another variable does NOT copy
		// the contents so copying the pointer follows go's standard behavior.
		dataAsPtr := unsafe.Pointer(dataValue.Pointer())
		*(**uintptr)(ptrToMember) = (*uintptr)(dataAsPtr)

	case reflect.Interface:
		// Interfaces are basically two pointers, see runtime.iface.
		// We want to modify exactly that data, which is returned by
		// the InterfaceData() method.

		if dataValue.Kind() != reflect.Interface {
			// A type reference was passed. In order to overwrite the memory
			// Representation of an interface we need to generate it first.
			// Reflect does not allow us to do that unless we use the
			// InterfaceData method which exposes the internal representation
			// of an interface.
			interfaceData := reflect.ValueOf(&data).Elem().InterfaceData()
			dataValue = reflect.ValueOf(interfaceData)
		}
		fallthrough

	default:
		// Complex types are assigned memcpy style.
		// Note: This should not break the garbage collector although we cannot
		// be 100% sure on this.
		UnsafeCopyValue(member.Addr(), dataValue)
	}
}
355474
func (s *ParameterValue) SetValue(v string) *ParameterValue {
	s.Value = &v
	return s
}
656680
func (s *MappingRule) SetValue(v string) *MappingRule {
	s.Value = &v
	return s
}
1046783
func (s *DeviceEvent) SetValue(v string) *DeviceEvent {
	s.Value = &v
	return s
}
886411
func (s *Setting) SetValue(v string) *Setting {
	s.Value = &v
	return s
}
644922
func (s *ThreatIntelIndicator) SetValue(v string) *ThreatIntelIndicator {
	s.Value = &v
	return s
}
452143
func (s *ResourceRequirement) SetValue(v string) *ResourceRequirement {
	s.Value = &v
	return s
}
686599
func (s *RecordTag) SetValue(v string) *RecordTag {
	s.Value = &v
	return s
}
358565
func (s *MapFilter) SetValue(v string) *MapFilter {
	s.Value = &v
	return s
}
317056
func (s *Filter) SetValue(v string) *Filter {
	s.Value = &v
	return s
}
894200
func (s *UpdateParam) SetValue(v string) *UpdateParam {
	s.Value = &v
	return s
}
918389
func (s *UsageInstruction) SetValue(v string) *UsageInstruction {
	s.Value = &v
	return s
}
985531
func (s *PatchOperation) SetValue(v string) *PatchOperation {
	s.Value = &v
	return s
}
993821
func (s *Text) SetValue(v string) *Text {
	s.Value = &v
	return s
}
1277956
func (s *MetricData) SetValue(v float64) *MetricData {
	s.Value = &v
	return s
}
1217331
func (s *ProvisioningParameter) SetValue(v string) *ProvisioningParameter {
	s.Value = &v
	return s
}
486568
func (s *PublicKey) SetValue(v []byte) *PublicKey {
	s.Value = v
	return s
}