comparison vamp-json/VampJson.h @ 221:9aca3267809c

Various fixes to JSON writing for static output data
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 09 Jun 2017 13:06:11 +0100
parents 02de5df3a884
children d96981c06e62
comparison
equal deleted inserted replaced
220:02de5df3a884 221:9aca3267809c
601 for (auto &o: vouts) outinfo.push_back(fromBasicDescriptor(o)); 601 for (auto &o: vouts) outinfo.push_back(fromBasicDescriptor(o));
602 jo["basicOutputInfo"] = outinfo; 602 jo["basicOutputInfo"] = outinfo;
603 603
604 json11::Json::object statinfo; 604 json11::Json::object statinfo;
605 auto souts = d.staticOutputInfo; 605 auto souts = d.staticOutputInfo;
606 for (auto &s: souts) jo[s.first] = fromStaticOutputDescriptor(s.second); 606 for (auto &s: souts) {
607 607 statinfo[s.first] = fromStaticOutputDescriptor(s.second);
608 return json11::Json(jo); 608 }
609 } 609 jo["staticOutputInfo"] = statinfo;
610 610
611 return json11::Json(jo);
612 }
613
614 static StaticOutputInfo
615 toStaticOutputInfo(json11::Json j, std::string &err) {
616
617 if (j == json11::Json()) return {};
618
619 if (!j.is_object()) {
620 err = "object expected for static output info";
621 return {};
622 }
623
624 StaticOutputInfo sinfo;
625 auto items = j.object_items();
626 for (auto i: items) {
627 sinfo[i.first] = toStaticOutputDescriptor(i.second, err);
628 if (failed(err)) return {};
629 }
630 return sinfo;
631 }
632
611 static PluginStaticData 633 static PluginStaticData
612 toPluginStaticData(json11::Json j, std::string &err) { 634 toPluginStaticData(json11::Json j, std::string &err) {
613 635
614 if (!j.has_shape({ 636 if (!j.has_shape({
615 { "key", json11::Json::STRING }, 637 { "key", json11::Json::STRING },
656 } else if (!j["basicOutputInfo"].is_null() && 678 } else if (!j["basicOutputInfo"].is_null() &&
657 !j["basicOutputInfo"].is_array()) { 679 !j["basicOutputInfo"].is_array()) {
658 680
659 err = "array expected for basicOutputInfo"; 681 err = "array expected for basicOutputInfo";
660 682
683 } else if (!j["staticOutputInfo"].is_null() &&
684 !j["staticOutputInfo"].is_object()) {
685
686 err = "object expected for staticOutputInfo";
687
661 } else { 688 } else {
662 689
663 PluginStaticData psd; 690 PluginStaticData psd;
664 691
665 psd.pluginKey = j["key"].string_value(); 692 psd.pluginKey = j["key"].string_value();
703 PluginStaticData::Basic b; 730 PluginStaticData::Basic b;
704 toBasicDescriptor(bo, b, err); 731 toBasicDescriptor(bo, b, err);
705 if (failed(err)) return {}; 732 if (failed(err)) return {};
706 psd.basicOutputInfo.push_back(b); 733 psd.basicOutputInfo.push_back(b);
707 } 734 }
708 735
736 StaticOutputInfo sinfo =
737 toStaticOutputInfo(j["staticOutputInfo"], err);
738 if (failed(err)) return {};
739 psd.staticOutputInfo = sinfo;
740
709 return psd; 741 return psd;
710 } 742 }
711 743
712 // fallthrough error case 744 // fallthrough error case
713 return {}; 745 return {};