Go to the documentation of this file.
49 template <
class numeric_type>
63 template<
class numeric_type>
65 std::ostringstream os;
71 int lastindex = proto_file.find_last_of(
".");
72 return proto_file.substr(0, lastindex) +
"_pb";
80 switch (
field->label()) {
84 default: assert(
false);
return "";
89 switch (
field->type()) {
108 default: assert(
false);
return "";
120 GOOGLE_LOG(
FATAL) <<
"Unsupported syntax; this generator only supports "
121 "proto2 and proto3 syntax.";
127 switch(
field->cpp_type()) {
141 return field->default_value_bool() ?
"true" :
"false";
145 std::ostringstream os;
146 string default_str =
field->default_value_string();
149 os <<
"\"" << default_str <<
"\"";
154 for (
int i = 0;
i < default_str.length(); ++
i) {
156 os <<
"\\x" << std::hex << std::setw(2)
157 << ((
uint16)((
unsigned char)default_str.at(
i)));
159 os <<
"\".force_encoding(\"ASCII-8BIT\")";
164 default: assert(
false);
return "";
169 if (
field->is_map()) {
171 field->message_type()->FindFieldByNumber(1);
173 field->message_type()->FindFieldByNumber(2);
176 "map :$name$, :$key_type$, :$value_type$, $number$",
177 "name",
field->name(),
179 "value_type",
TypeName(value_field),
191 printer->
Print(
"\n");
198 "name",
field->name());
207 "subtype",
field->message_type()->full_name());
211 "subtype",
field->enum_type()->full_name());
214 if (
field->has_default_value()) {
215 printer->
Print(
", default: $default$",
"default",
219 printer->
Print(
"\n");
225 "oneof :$name$ do\n",
226 "name", oneof->
name());
235 printer->
Print(
"end\n");
240 if (
message->extension_range_count() > 0 ||
message->extension_count() > 0) {
241 *
error =
"Extensions are not yet supported for proto2 .proto files.";
247 if (
message->options().map_entry()) {
252 "add_message \"$name$\" do\n",
256 for (
int i = 0;
i <
message->field_count();
i++) {
258 if (!
field->containing_oneof()) {
263 for (
int i = 0;
i <
message->oneof_decl_count();
i++) {
269 printer->
Print(
"end\n");
271 for (
int i = 0;
i <
message->nested_type_count();
i++) {
276 for (
int i = 0;
i <
message->enum_type_count();
i++) {
285 "add_enum \"$name$\" do\n",
292 "value :$name$, $number$\n",
293 "name",
value->name(),
317 bool next_upper =
true;
319 result.reserve(
name.size());
321 for (
int i = 0;
i <
name.size();
i++) {
322 if (
name[
i] ==
'_') {
328 result.push_back(
name[
i]);
365 if (
message->options().map_entry()) {
374 "Google::Protobuf::DescriptorPool.generated_pool."
375 "lookup(\"$full_name$\").msgclass\n",
376 "full_name",
message->full_name());
379 for (
int i = 0;
i <
message->nested_type_count();
i++) {
382 for (
int i = 0;
i <
message->enum_type_count();
i++) {
394 "Google::Protobuf::DescriptorPool.generated_pool."
395 "lookup(\"$full_name$\").enummodule\n",
401 bool need_change_to_module =
true;
407 if (file->
options().has_ruby_package()) {
414 if (package_name.find(
"::") != std::string::npos) {
415 need_change_to_module =
false;
418 <<
" 'A::B::C' and not 'A.B.C'";
421 package_name = file->
package();
425 string delimiter = need_change_to_module ?
"." :
"::";
426 int delimiter_size = need_change_to_module ? 1 : 2;
429 while (!package_name.empty()) {
430 size_t dot_index = package_name.find(delimiter);
432 if (dot_index == string::npos) {
433 component = package_name;
436 component = package_name.substr(0, dot_index);
437 package_name = package_name.substr(dot_index + delimiter_size);
439 if (need_change_to_module) {
462 for (
int i = 0;
i <
message->field_count();
i++) {
465 field->message_type()->file() == file) ||
467 field->enum_type()->file() == file)) {
468 *
error =
"proto3 message field " +
field->full_name() +
" in file " +
469 file->
name() +
" has a dependency on a type from proto2 file " +
471 ". Ruby doesn't support proto2 yet, so we must fail.";
476 for (
int i = 0;
i <
message->nested_type_count();
i++) {
510 <<
"' from proto3 output file '"
512 <<
"' because we don't support proto2 and no proto2 "
513 "types from that file are being used.";
525 "# Generated by the protocol buffer compiler. DO NOT EDIT!\n"
526 "# source: $filename$\n"
528 "filename", file->
name());
531 "require 'google/protobuf'\n\n");
541 *
error =
"Extensions are not yet supported for proto2 .proto files.";
545 printer->
Print(
"Google::Protobuf::DescriptorPool.generated_pool.build do\n");
547 printer->
Print(
"add_file(\"$filename$\", :syntax => :$syntax$) do\n",
548 "filename", file->
name(),
"syntax",
560 printer->
Print(
"end\n");
578 const string& parameter,
580 string*
error)
const {
584 *
error =
"Invalid or unsupported proto syntax";
588 std::unique_ptr<io::ZeroCopyOutputStream>
output(
const std::string & full_name() const
void Print(const std::map< std::string, std::string > &variables, const char *text)
bool GenerateMessage(const Descriptor *message, io::Printer *printer, std::string *error)
void GenerateEnumAssignment(const std::string &prefix, const EnumDescriptor *en, io::Printer *printer)
GLuint const GLchar * name
const EnumDescriptor * enum_type() const
const Descriptor::ReservedRange value
std::string LabelForField(FieldDescriptor *field)
const EnumDescriptor * enum_type(int index) const
void GenerateEnum(const EnumDescriptor *en, io::Printer *printer)
virtual io::ZeroCopyOutputStream * Open(const std::string &filename)=0
bool UsesTypeFromFile(const Descriptor *message, const FileDescriptor *file, string *error)
GLsizei const GLchar *const * string
void GenerateField(const FieldDescriptor *field, io::Printer *printer)
const std::string & name() const
std::string RubifyConstant(const std::string &name)
const FieldDescriptor * field(int index) const
bool GenerateFile(const FileDescriptor *file, io::Printer *printer, string *error)
int enum_type_count() const
virtual bool Generate(const FileDescriptor *file, const string ¶meter, GeneratorContext *generator_context, string *error) const
const std::string & package() const
const std::string & name() const
std::string DefaultValueForField(const FieldDescriptor *field)
static const char prefix[]
const EnumValueDescriptor * value(int index) const
#define GOOGLE_LOG(LEVEL)
static const LogLevel WARNING
const FileOptions & options() const
std::string GetRequireName(const std::string &proto_file)
const FieldDescriptor * field
const std::string & name() const
void GenerateMessageAssignment(const std::string &prefix, const Descriptor *message, io::Printer *printer)
const Descriptor * message_type(int index) const
std::string NumberToString(numeric_type value)
const std::string & full_name() const
bool MaybeEmitDependency(const FileDescriptor *import, const FileDescriptor *from, io::Printer *printer, string *error)
const FileDescriptor * dependency(int index) const
const std::string & ruby_package() const
std::string PackageToModule(const std::string &name)
const Descriptor * message_type() const
void EndPackageModules(int levels, io::Printer *printer)
void GenerateOneof(const OneofDescriptor *oneof, io::Printer *printer)
int GeneratePackageModules(const FileDescriptor *file, io::Printer *printer)
std::string TypeName(FieldDescriptor *field)
string StringifySyntax(FileDescriptor::Syntax syntax)
GLsizei const GLfloat * value
const upb_json_parsermethod const upb_symtab upb_sink * output
int message_type_count() const
GLenum GLuint GLenum GLsizei const GLchar * message
int extension_count() const
std::string GetOutputFilename(const std::string &proto_file)
int dependency_count() const
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:58