first commit

This commit is contained in:
dasha 2026-01-05 23:50:53 +03:00
commit 7dd9dd689e
40 changed files with 4100 additions and 0 deletions

74
ProtoGen/ProtoOutput.cpp Normal file
View file

@ -0,0 +1,74 @@
#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;
}