func castValToRef()

in internal/kernel/conversions.go [245:284]


func castValToRef(data reflect.Value) (ref api.ObjectRef, ok bool) {
	if data.Kind() == reflect.Map {
		for _, k := range data.MapKeys() {
			// Finding values type requires extracting from reflect.Value
			// otherwise .Kind() returns `interface{}`
			v := reflect.ValueOf(data.MapIndex(k).Interface())

			if k.Kind() != reflect.String {
				continue
			}

			switch k.String() {
			case "$jsii.byref":
				if v.Kind() != reflect.String {
					ok = false
					return
				}
				ref.InstanceID = v.String()
				ok = true
			case "$jsii.interfaces":
				if v.Kind() != reflect.Slice {
					continue
				}
				ifaces := make([]api.FQN, v.Len())
				for i := 0; i < v.Len(); i++ {
					e := reflect.ValueOf(v.Index(i).Interface())
					if e.Kind() != reflect.String {
						ok = false
						return
					}
					ifaces[i] = api.FQN(e.String())
				}
				ref.Interfaces = ifaces
			}

		}
	}

	return ref, ok
}