(argType reflect.Type, jsonArg any)
| 111 | } |
| 112 | |
| 113 | func convertSpecial(argType reflect.Type, jsonArg any) (any, error) { |
| 114 | jsonType := reflect.TypeOf(jsonArg) |
| 115 | if argType == orefRType { |
| 116 | if jsonType.Kind() != reflect.String { |
| 117 | return nil, fmt.Errorf("cannot convert %T to %s", jsonArg, argType) |
| 118 | } |
| 119 | oref, err := waveobj.ParseORef(jsonArg.(string)) |
| 120 | if err != nil { |
| 121 | return nil, fmt.Errorf("invalid oref string: %v", err) |
| 122 | } |
| 123 | return oref, nil |
| 124 | } else if argType == wsCommandRType { |
| 125 | return convertWSCommand(argType, jsonArg) |
| 126 | } else if argType == waveObjRType { |
| 127 | if jsonType.Kind() != reflect.Map { |
| 128 | return nil, fmt.Errorf("cannot convert %T to %s", jsonArg, argType) |
| 129 | } |
| 130 | return waveobj.FromJsonMap(jsonArg.(map[string]any)) |
| 131 | } else if argType == waveObjSliceRType { |
| 132 | if jsonType.Kind() != reflect.Slice { |
| 133 | return nil, fmt.Errorf("cannot convert %T to %s", jsonArg, argType) |
| 134 | } |
| 135 | sliceArg := jsonArg.([]any) |
| 136 | nativeSlice := make([]waveobj.WaveObj, len(sliceArg)) |
| 137 | for idx, elem := range sliceArg { |
| 138 | elemMap, ok := elem.(map[string]any) |
| 139 | if !ok { |
| 140 | return nil, fmt.Errorf("cannot convert %T to %s (idx %d is not a map, is %T)", jsonArg, waveObjSliceRType, idx, elem) |
| 141 | } |
| 142 | nativeObj, err := waveobj.FromJsonMap(elemMap) |
| 143 | if err != nil { |
| 144 | return nil, fmt.Errorf("cannot convert %T to %s (idx %d) error: %v", jsonArg, waveObjSliceRType, idx, err) |
| 145 | } |
| 146 | nativeSlice[idx] = nativeObj |
| 147 | } |
| 148 | return nativeSlice, nil |
| 149 | } else if argType == waveObjMapRType { |
| 150 | if jsonType.Kind() != reflect.Map { |
| 151 | return nil, fmt.Errorf("cannot convert %T to %s", jsonArg, argType) |
| 152 | } |
| 153 | mapArg := jsonArg.(map[string]any) |
| 154 | nativeMap := make(map[string]waveobj.WaveObj) |
| 155 | for key, elem := range mapArg { |
| 156 | elemMap, ok := elem.(map[string]any) |
| 157 | if !ok { |
| 158 | return nil, fmt.Errorf("cannot convert %T to %s (key %s is not a map, is %T)", jsonArg, waveObjMapRType, key, elem) |
| 159 | } |
| 160 | nativeObj, err := waveobj.FromJsonMap(elemMap) |
| 161 | if err != nil { |
| 162 | return nil, fmt.Errorf("cannot convert %T to %s (key %s) error: %v", jsonArg, waveObjMapRType, key, err) |
| 163 | } |
| 164 | nativeMap[key] = nativeObj |
| 165 | } |
| 166 | return nativeMap, nil |
| 167 | } else { |
| 168 | return nil, fmt.Errorf("invalid special wave argument type %s", argType) |
| 169 | } |
| 170 | } |
no test coverage detected