| 3 | #include "NetworkResourceRawTO.h" |
| 4 | |
| 5 | std::vector<NetworkResourceRawTO> NetworkResourceParserService::decodeRemoteSimulationData(boost::property_tree::ptree const& tree) |
| 6 | { |
| 7 | std::vector<NetworkResourceRawTO> result; |
| 8 | for (auto const& [key, subTree] : tree) { |
| 9 | auto entry = std::make_shared<_NetworkResourceRawTO>(); |
| 10 | entry->id = subTree.get<std::string>("id"); |
| 11 | entry->userName = subTree.get<std::string>("userName"); |
| 12 | entry->resourceName = subTree.get<std::string>("simulationName"); |
| 13 | entry->description= subTree.get<std::string>("description"); |
| 14 | entry->width = subTree.get<int>("width"); |
| 15 | entry->height = subTree.get<int>("height"); |
| 16 | entry->particles = subTree.get<int>("particles"); |
| 17 | entry->version = subTree.get<std::string>("version"); |
| 18 | entry->timestamp = subTree.get<std::string>("timestamp"); |
| 19 | entry->contentSize = std::stoll(subTree.get<std::string>("contentSize")); |
| 20 | |
| 21 | bool isArray = false; |
| 22 | int counter = 0; |
| 23 | for (auto const& [likeTypeString, numLikesString] : subTree.get_child("likesByType")) { |
| 24 | auto likes = std::stoi(numLikesString.data()); |
| 25 | if (likeTypeString.empty()) { |
| 26 | isArray = true; |
| 27 | } |
| 28 | auto likeType = isArray ? counter : std::stoi(likeTypeString); |
| 29 | entry->numLikesByEmojiType[likeType] = likes; |
| 30 | ++counter; |
| 31 | } |
| 32 | entry->numDownloads = subTree.get<int>("numDownloads"); |
| 33 | entry->workspaceType = subTree.get<int>("fromRelease"); |
| 34 | entry->resourceType = subTree.get<NetworkResourceType>("type"); |
| 35 | result.emplace_back(entry); |
| 36 | } |
| 37 | return result; |
| 38 | } |
| 39 | |
| 40 | std::vector<UserTO> NetworkResourceParserService::decodeUserData(boost::property_tree::ptree const& tree) |
| 41 | { |