| 216 | } |
| 217 | |
| 218 | Rcpp::List BulkDataResponseToDF(Event& event, std::string& requested_field, std::string response_type, bool verbose) { |
| 219 | MessageIterator msgIter(event); |
| 220 | if(!msgIter.next()) { |
| 221 | throw std::logic_error("Not a valid MessageIterator."); |
| 222 | } |
| 223 | |
| 224 | Message msg = msgIter.message(); |
| 225 | Element response = msg.asElement(); |
| 226 | if (verbose) response.print(Rcpp::Rcout); |
| 227 | if(std::strcmp(response.name().string(),response_type.c_str())) { |
| 228 | throw std::logic_error("Not a valid " + response_type + "."); |
| 229 | } |
| 230 | Element securityData = response.getElement("securityData"); |
| 231 | |
| 232 | Rcpp::List ans(securityData.numValues()); |
| 233 | std::vector<std::string> ans_names(securityData.numValues()); |
| 234 | |
| 235 | for(size_t i = 0; i < securityData.numValues(); ++i) { |
| 236 | Element this_security = securityData.getValueAsElement(i); |
| 237 | ans_names[i] = this_security.getElementAsString("security"); |
| 238 | Element fieldData = this_security.getElement("fieldData"); |
| 239 | if(!fieldData.hasElement(requested_field.c_str())) { |
| 240 | ans[i] = R_NilValue; |
| 241 | } else { |
| 242 | Element e = fieldData.getElement(requested_field.c_str()); |
| 243 | ans[i] = bulkArrayToDf(e); |
| 244 | } |
| 245 | } |
| 246 | ans.attr("names") = ans_names; |
| 247 | return ans; |
| 248 | } |
| 249 | |
| 250 | // only allow one field for bds in contrast to bdp |
| 251 | // [[Rcpp::export]] |
no test coverage detected