Loading system/gd/packet/parser/gen_rust.cc +53 −0 Original line number Diff line number Diff line Loading @@ -136,6 +136,59 @@ bool generate_rust_source_one_file( } } if (opcode_index != nullptr && opcode != nullptr) { opcode_index->try_from_enum_ = opcode; } } else if (input_filename == "nci_packets") { out_file << "type EventPacket = NciPacket;" << "pub trait CommandExpectations { " << "type ResponseType;" << "fn _to_response_type(pkt: EventPacket) -> Self::ResponseType;" << "}"; for (const auto& packet_def : decls.packet_defs_queue_) { auto packet = packet_def.second; if (!packet->HasAncestorNamed("Command")) { continue; } auto constraint = packet->parent_constraints_.find("op"); if (constraint == packet->parent_constraints_.end()) { continue; } auto opcode = std::get<std::string>(constraint->second); for (const auto& other_packet_def : decls.packet_defs_queue_) { auto other_packet = other_packet_def.second; bool command_response = other_packet->HasAncestorNamed("Response"); bool command_notification = other_packet->HasAncestorNamed("Notification"); if (!command_response && !command_notification) { continue; } auto other_constraint = other_packet->parent_constraints_.find("cmd_op"); if (other_constraint == other_packet->parent_constraints_.end()) { continue; } auto other_opcode = std::get<std::string>(other_constraint->second); if (opcode == other_opcode) { packet->complement_ = other_packet; break; } } } EnumDef* opcode = nullptr; EnumDef* opcode_index = nullptr; for (const auto& e : decls.type_defs_queue_) { if (e.second->GetDefinitionType() == TypeDef::Type::ENUM) { auto* enum_def = static_cast<EnumDef*>(e.second); if (enum_def->name_ == "Opcode") { opcode = enum_def; } else if (enum_def->name_ == "OpCodeIndex") { opcode_index = enum_def; } } } if (opcode_index != nullptr && opcode != nullptr) { opcode_index->try_from_enum_ = opcode; } Loading Loading
system/gd/packet/parser/gen_rust.cc +53 −0 Original line number Diff line number Diff line Loading @@ -136,6 +136,59 @@ bool generate_rust_source_one_file( } } if (opcode_index != nullptr && opcode != nullptr) { opcode_index->try_from_enum_ = opcode; } } else if (input_filename == "nci_packets") { out_file << "type EventPacket = NciPacket;" << "pub trait CommandExpectations { " << "type ResponseType;" << "fn _to_response_type(pkt: EventPacket) -> Self::ResponseType;" << "}"; for (const auto& packet_def : decls.packet_defs_queue_) { auto packet = packet_def.second; if (!packet->HasAncestorNamed("Command")) { continue; } auto constraint = packet->parent_constraints_.find("op"); if (constraint == packet->parent_constraints_.end()) { continue; } auto opcode = std::get<std::string>(constraint->second); for (const auto& other_packet_def : decls.packet_defs_queue_) { auto other_packet = other_packet_def.second; bool command_response = other_packet->HasAncestorNamed("Response"); bool command_notification = other_packet->HasAncestorNamed("Notification"); if (!command_response && !command_notification) { continue; } auto other_constraint = other_packet->parent_constraints_.find("cmd_op"); if (other_constraint == other_packet->parent_constraints_.end()) { continue; } auto other_opcode = std::get<std::string>(other_constraint->second); if (opcode == other_opcode) { packet->complement_ = other_packet; break; } } } EnumDef* opcode = nullptr; EnumDef* opcode_index = nullptr; for (const auto& e : decls.type_defs_queue_) { if (e.second->GetDefinitionType() == TypeDef::Type::ENUM) { auto* enum_def = static_cast<EnumDef*>(e.second); if (enum_def->name_ == "Opcode") { opcode = enum_def; } else if (enum_def->name_ == "OpCodeIndex") { opcode_index = enum_def; } } } if (opcode_index != nullptr && opcode != nullptr) { opcode_index->try_from_enum_ = opcode; } Loading