MCPcopy Create free account
hub / github.com/chigraph/chigraph / jsonToGraphStruct

Function jsonToGraphStruct

libchigraph/src/JsonDeserializer.cpp:448–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446}
447
448Result jsonToGraphStruct(GraphModule& mod, boost::string_view name, const nlohmann::json& input,
449 GraphStruct** toFill) {
450 Result res;
451
452 if (!input.is_array()) {
453 res.addEntry("EUKN", "Graph Struct json has to be an array", {{"Given JSON", input}});
454 return res;
455 }
456
457 auto createdStruct = mod.getOrCreateStruct(name.to_string());
458 if (toFill != nullptr) { *toFill = createdStruct; }
459
460 for (const auto& str : input) {
461 if (!str.is_object()) {
462 res.addEntry("EUKN", "Graph Struct entry must be an object", {{"Given JSON", str}});
463 continue;
464 }
465
466 if (str.size() != 1) {
467 res.addEntry("EUKN", "Graph Struct entry must have size of 1", {{"Size", str.size()}});
468 continue;
469 }
470
471 std::string docstring, qualifiedType;
472 std::tie(docstring, qualifiedType) = parseObjectPair(str);
473
474 // parse the type
475 std::string typeModuleName, typeName;
476 std::tie(typeModuleName, typeName) = parseColonPair(qualifiedType);
477
478 DataType ty;
479 res += mod.context().typeFromModule(typeModuleName, typeName, &ty);
480
481 if (!res) { continue; }
482
483 createdStruct->addType(ty, docstring, createdStruct->types().size());
484 }
485
486 return res;
487}
488
489std::pair<std::string, std::string> parseObjectPair(const nlohmann::json& object) {
490 if (!object.is_object()) { return {}; }

Callers 1

jsonToGraphModuleFunction · 0.85

Calls 9

parseObjectPairFunction · 0.85
parseColonPairFunction · 0.85
is_arrayMethod · 0.80
addEntryMethod · 0.80
getOrCreateStructMethod · 0.80
to_stringMethod · 0.80
is_objectMethod · 0.80
typeFromModuleMethod · 0.80
addTypeMethod · 0.80

Tested by

no test coverage detected