| 1542 | } // anonymous namespace |
| 1543 | |
| 1544 | string FileDescriptor::DebugString() const { |
| 1545 | string contents = "syntax = \"proto2\";\n\n"; |
| 1546 | |
| 1547 | for (int i = 0; i < dependency_count(); i++) { |
| 1548 | strings::SubstituteAndAppend(&contents, "import \"$0\";\n", |
| 1549 | dependency(i)->name()); |
| 1550 | } |
| 1551 | |
| 1552 | if (!package().empty()) { |
| 1553 | strings::SubstituteAndAppend(&contents, "package $0;\n\n", package()); |
| 1554 | } |
| 1555 | |
| 1556 | if (FormatLineOptions(0, options(), &contents)) { |
| 1557 | contents.append("\n"); // add some space if we had options |
| 1558 | } |
| 1559 | |
| 1560 | for (int i = 0; i < enum_type_count(); i++) { |
| 1561 | enum_type(i)->DebugString(0, &contents); |
| 1562 | contents.append("\n"); |
| 1563 | } |
| 1564 | |
| 1565 | // Find all the 'group' type extensions; we will not output their nested |
| 1566 | // definitions (those will be done with their group field descriptor). |
| 1567 | set<const Descriptor*> groups; |
| 1568 | for (int i = 0; i < extension_count(); i++) { |
| 1569 | if (extension(i)->type() == FieldDescriptor::TYPE_GROUP) { |
| 1570 | groups.insert(extension(i)->message_type()); |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | for (int i = 0; i < message_type_count(); i++) { |
| 1575 | if (groups.count(message_type(i)) == 0) { |
| 1576 | strings::SubstituteAndAppend(&contents, "message $0", |
| 1577 | message_type(i)->name()); |
| 1578 | message_type(i)->DebugString(0, &contents); |
| 1579 | contents.append("\n"); |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | for (int i = 0; i < service_count(); i++) { |
| 1584 | service(i)->DebugString(&contents); |
| 1585 | contents.append("\n"); |
| 1586 | } |
| 1587 | |
| 1588 | const Descriptor* containing_type = NULL; |
| 1589 | for (int i = 0; i < extension_count(); i++) { |
| 1590 | if (extension(i)->containing_type() != containing_type) { |
| 1591 | if (i > 0) contents.append("}\n\n"); |
| 1592 | containing_type = extension(i)->containing_type(); |
| 1593 | strings::SubstituteAndAppend(&contents, "extend .$0 {\n", |
| 1594 | containing_type->full_name()); |
| 1595 | } |
| 1596 | extension(i)->DebugString(1, &contents); |
| 1597 | } |
| 1598 | if (extension_count() > 0) contents.append("}\n\n"); |
| 1599 | |
| 1600 | return contents; |
| 1601 | } |