Result VertexInfo::Dump()

in cpp/src/graphar/graph_info.cc [459:502]


Result<std::string> VertexInfo::Dump() const noexcept {
  if (!IsValidated()) {
    return Status::Invalid("The vertex info is not validated");
  }
  std::string dump_string;
  ::Yaml::Node node;
  try {
    node["type"] = impl_->type_;
    node["chunk_size"] = std::to_string(impl_->chunk_size_);
    node["prefix"] = impl_->prefix_;
    if (impl_->labels_.size() > 0) {
      node["labels"];
      for (const auto& label : impl_->labels_) {
        node["labels"].PushBack();
        node["labels"][node["labels"].Size() - 1] = label;
      }
    }
    for (const auto& pg : impl_->property_groups_) {
      ::Yaml::Node pg_node;
      if (!pg->GetPrefix().empty()) {
        pg_node["prefix"] = pg->GetPrefix();
      }
      pg_node["file_type"] = FileTypeToString(pg->GetFileType());
      for (const auto& p : pg->GetProperties()) {
        ::Yaml::Node p_node;
        p_node["name"] = p.name;
        p_node["data_type"] = p.type->ToTypeName();
        p_node["is_primary"] = p.is_primary ? "true" : "false";
        p_node["is_nullable"] = p.is_nullable ? "true" : "false";
        pg_node["properties"].PushBack();
        pg_node["properties"][pg_node["properties"].Size() - 1] = p_node;
      }
      node["property_groups"].PushBack();
      node["property_groups"][node["property_groups"].Size() - 1] = pg_node;
    }
    if (impl_->version_ != nullptr) {
      node["version"] = impl_->version_->ToString();
    }
    ::Yaml::Serialize(node, dump_string);
  } catch (const std::exception& e) {
    return Status::Invalid("Failed to dump vertex info: ", e.what());
  }
  return dump_string;
}