372 {
373 coral::AttributeList attr(*pSpec,true);
374 unsigned int s=attr.size();
375
376 json::const_iterator
it = j.begin();
377 for (
unsigned int i(0);
i!=
s;++
i){
378
379
380 auto & att =
const_cast<coral::Attribute&
>(attr[
i]);
381 if (it == j.end()){
382 continue;
383 }
384 const auto thisVal =
it.value();
386
387 try{
388 if (thisVal.is_null()){
389 att.setNull();
390 continue;
391 }
392 cool::StorageType::TypeId typespec=cool::StorageType::Bool;
393 for(auto &p : tSpec){
394 if(
p.first.compare(att.specification().name())==0){
397 throw std::runtime_error("CoralCrestManager::createAttributeList: name not found.");
398 }
399 std::string str_spec = pElement ->second;
402 throw std::runtime_error("CoralCrestManager::createAttributeList: typespec not found.");
403 }
404 typespec=pTypespec->second;
405 break;
406 }
407 }
409 if(strVal.size()>2&& strVal[0]=='"'&& strVal[strVal.size()-1]=='"')
410 strVal=strVal.substr(1,strVal.size()-2);
411
412 if((strVal.compare("NULL")==0||strVal.compare("null")==0)&&
413 (typespec==cool::StorageType::Bool || typespec==cool::StorageType::Int16 || typespec==cool::StorageType::UInt16
414 || typespec==cool::StorageType::Int32 || typespec==cool::StorageType::UInt32
415 || typespec==cool::StorageType::Int64 || typespec==cool::StorageType::UInt63
416 || typespec==cool::StorageType::Float || typespec==cool::StorageType::Double)){
417 att.setNull();
418 continue;
419 }
420 switch (typespec) {
421 case cool::StorageType::Bool:
422 {
423 const bool newVal=(strVal == "true");
424 att.setValue<bool>(newVal);
425 break;
426 }
427 case cool::StorageType::UChar:
428 {
429 const unsigned char newVal=std::stoul(strVal);
430 att.setValue<unsigned char>(newVal);
431 break;
432 }
433 case cool::StorageType::Int16:
434 {
435 const short newVal=std::stol(strVal);
436 att.setValue<short>(newVal);
437 break;
438 }
439 case cool::StorageType::UInt16:
440 {
441 const unsigned short newVal=std::stoul(strVal);
442 att.setValue<unsigned short>(newVal);
443 break;
444 }
445 case cool::StorageType::Int32:
446 {
447 const int newVal=std::stoi(strVal);
448 att.setValue<int>(newVal);
449 break;
450 }
451 case cool::StorageType::UInt32:
452 {
453 const unsigned int newVal=std::stoull(strVal);
454 att.setValue<unsigned int>(newVal);
455 break;
456 }
457 case cool::StorageType::UInt63:
458 {
459 const unsigned long long newVal=std::stoull(strVal);
460 att.setValue<unsigned long long>(newVal);
461 break;
462 }
463 case cool::StorageType::Int64:
464 {
465 const long long newVal=std::stoll(strVal);
466 att.setValue< long long>(newVal);
467 break;
468 }
469 case cool::StorageType::Float:
470 {
471 const float newVal=std::stof(strVal);
472 att.setValue<float>(newVal);
473 break;
474 }
475 case cool::StorageType::Double:
476 {
477 const double newVal=std::stod(strVal);
478 att.setValue<double>(newVal);
479 break;
480 }
481 case cool::StorageType::String255:
482 case cool::StorageType::String4k:
483 case cool::StorageType::String64k:
484 case cool::StorageType::String16M:
485 case cool::StorageType::String128M:
486 {
487 att.setValue<std::string>(thisVal.get<std::string>());
488 break;
489 }
490 case cool::StorageType::Blob128M:
491 case cool::StorageType::Blob16M:
492 case cool::StorageType::Blob64k:
493 {
495 coral::Blob
blob(charVec.size());
496 memcpy(
blob.startingAddress(), charVec.data(), charVec.size());
497 att.setValue<coral::Blob>(
blob);
498 break;
499 }
500 default:
501 {
502 std::string errorMessage("UNTREATED TYPE! " + std::to_string(typespec));
504 gLog << MSG::ERROR <<
"LoadPayloadForHash:" <<errorMessage<<
endmsg;
505 throw std::runtime_error(errorMessage);
506 }
507 }
508 }
509 catch (json::exception& e){
511 gLog << MSG::ERROR <<
"Error CoralCrestManager::createAttributeList: "<<
e.what()<<
endmsg;
512 throw std::runtime_error(
e.what());
513 }
514 }
515 return attr;
516 }
const std::map< std::string, cool::StorageType::TypeId > typeCorrespondance
IMessageSvc * getMessageSvc(bool quiet=false)
static const std::map< TypeId, std::string > s_typeToString
std::vector< unsigned char > base64_decode(const std::string &)