| 289 | |
| 290 | private: |
| 291 | Any DecodeNode(int64_t node_index, const json::Object& node) { |
| 292 | String type_key = node["type"].cast<String>(); |
| 293 | TVMFFIByteArray type_key_arr{type_key.data(), type_key.length()}; |
| 294 | int32_t type_index; |
| 295 | TVM_FFI_CHECK_SAFE_CALL(TVMFFITypeKeyToIndex(&type_key_arr, &type_index)); |
| 296 | |
| 297 | switch (type_index) { |
| 298 | case TypeIndex::kTVMFFINone: { |
| 299 | return nullptr; |
| 300 | } |
| 301 | case TypeIndex::kTVMFFIBool: { |
| 302 | return node["data"].cast<bool>(); |
| 303 | } |
| 304 | case TypeIndex::kTVMFFIInt: { |
| 305 | return node["data"].cast<int64_t>(); |
| 306 | } |
| 307 | case TypeIndex::kTVMFFIFloat: { |
| 308 | return node["data"].cast<double>(); |
| 309 | } |
| 310 | case TypeIndex::kTVMFFIDataType: { |
| 311 | return StringToDLDataType(node["data"].cast<String>()); |
| 312 | } |
| 313 | case TypeIndex::kTVMFFIDevice: { |
| 314 | Array<int32_t> data = node["data"].cast<Array<int32_t>>(); |
| 315 | return DLDevice{static_cast<DLDeviceType>(data[0]), data[1]}; |
| 316 | } |
| 317 | case TypeIndex::kTVMFFIStr: { |
| 318 | return node["data"].cast<String>(); |
| 319 | } |
| 320 | case TypeIndex::kTVMFFIBytes: { |
| 321 | return Base64Decode(node["data"].cast<String>()); |
| 322 | } |
| 323 | case TypeIndex::kTVMFFIMap: { |
| 324 | return DecodeMapLikeData<Map<Any, Any>>(node["data"].cast<json::Array>()); |
| 325 | } |
| 326 | case TypeIndex::kTVMFFIDict: { |
| 327 | return DecodeMapLikeData<Dict<Any, Any>>(node["data"].cast<json::Array>()); |
| 328 | } |
| 329 | case TypeIndex::kTVMFFIArray: { |
| 330 | return DecodeSequenceData<Array<Any>>(node["data"].cast<json::Array>()); |
| 331 | } |
| 332 | case TypeIndex::kTVMFFIList: { |
| 333 | return DecodeSequenceData<List<Any>>(node["data"].cast<json::Array>()); |
| 334 | } |
| 335 | case TypeIndex::kTVMFFIShape: { |
| 336 | Array<int64_t> data = node["data"].cast<Array<int64_t>>(); |
| 337 | return ffi::Shape(data); |
| 338 | } |
| 339 | default: { |
| 340 | return DecodeObjectData(type_index, node["data"]); |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | template <typename SeqType> |
| 346 | SeqType DecodeSequenceData(const json::Array& data) { |
nothing calls this directly
no test coverage detected