Skip to content

Commit

Permalink
Set FileDescriptor for generated Ruby protos
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Anker committed Sep 25, 2017
1 parent bbb6e86 commit af38326
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/google/protobuf/compiler/ruby/ruby_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ std::string TypeName(const google::protobuf::FieldDescriptor* field) {
}
}

string StringifySyntax(FileDescriptor::Syntax syntax) {
switch (syntax) {
case FileDescriptor::SYNTAX_PROTO2:
return "proto2";
case FileDescriptor::SYNTAX_PROTO3:
return "proto3";
case FileDescriptor::SYNTAX_UNKNOWN:
default:
GOOGLE_LOG(FATAL) << "Unsupported syntax; this generator only supports proto2 "
"and proto3 syntax.";
return "";
}
}


void GenerateField(const google::protobuf::FieldDescriptor* field,
google::protobuf::io::Printer* printer) {

Expand Down Expand Up @@ -451,8 +466,18 @@ bool GenerateFile(const FileDescriptor* file, io::Printer* printer,
}
}

printer->Print("Google::Protobuf::DescriptorPool.generated_pool.build(\n");
printer->Indent();
printer->Print("Google::Protobuf::FileDescriptor.new.tap do |f|\n");
printer->Indent();
printer->Print(
"Google::Protobuf::DescriptorPool.generated_pool.build do\n");
"f.syntax = :$syntax$\n",
"syntax", StringifySyntax(file->syntax()));
printer->Outdent();
printer->Print("end\n");
printer->Outdent();
printer->Print(") do\n");

printer->Indent();
for (int i = 0; i < file->message_type_count(); i++) {
GenerateMessage(file->message_type(i), printer);
Expand Down

0 comments on commit af38326

Please sign in to comment.