dumpcs-dumper/ProtoGen/ProtoOutput.cpp
2026-01-05 23:50:53 +03:00

74 lines
No EOL
1.9 KiB
C++

#include "ProtoOutput.h"
using namespace proto;
std::ostream& proto::operator<<(std::ostream& os, const FieldComment& c) {
os << " // offset: " << c.offset << ", xor const: " << c.xor_const;
return os;
}
std::ostream& proto::operator<<(std::ostream& os, const Field& f) {
os << " " << f.kind << " " << f.name << " = " << f.number << ";";
if (f.comment) {
os << *(f.comment);
}
return os;
}
std::ostream& proto::operator<<(std::ostream& os, const Oneof& o) {
os << " oneof " << o.name << " {\n";
for (const auto& field : o.fields) {
os << " " << field << "\n";
}
os << " }";
return os;
}
std::ostream& proto::operator<<(std::ostream& os, const Enum& e) {
os << "enum " << e.name << " {\n";
for (const auto& [name, value] : e.variants) {
os << " " << name << " = " << value << ";\n";
}
os << "}\n";
return os;
}
std::ostream& proto::operator<<(std::ostream& os, const Message& m) {
os << "message " << m.name << " {";
if (m.cmd_id != 0) {
os << " // CmdID: " << m.cmd_id;
}
os << "\n";
for (const auto& field : m.fields) {
os << field << "\n";
}
for (const auto& oneof : m.oneofs) {
os << oneof << "\n";
}
os << "}\n\n";
return os;
}
std::ostream& proto::operator<<(std::ostream& os, const ProtoItem& item) {
if (std::holds_alternative<Message>(item)) {
os << std::get<Message>(item);
} else if (std::holds_alternative<Enum>(item)) {
os << std::get<Enum>(item);
}
return os;
}
std::ostream& proto::operator<<(std::ostream& os, const ProtoFile& pf) {
os << "syntax = \"" << pf.syntax << "\";\n";
for (const auto& import : pf.imports) {
os << "import \"" << import << "\";\n";
}
os << "\n";
for (const auto& item : pf.items) {
os << item;
}
return os;
}