Skip to content

Commit

Permalink
Addressed PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
haberman committed Aug 2, 2021
1 parent d339e17 commit b7ab625
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions ruby/lib/google/protobuf/descriptor_dsl.rb
Expand Up @@ -79,7 +79,7 @@ def infer_package(names)
last_common_dot = nil
min.size.times { |i|
if min[i] != max[i] then break end
if min[i] == ?. then last_common_dot = i end
if min[i] == "." then last_common_dot = i end
}
if last_common_dot
return min.slice(0, last_common_dot)
Expand All @@ -97,11 +97,11 @@ def rewrite_enum_default(field)
value = field.default_value
type_name = field.type_name

if value.empty? or value[0].ord < ?0.ord or value[0].ord > ?9.ord
if value.empty? or value[0].ord < "0".ord or value[0].ord > "9".ord
return
end

if type_name.empty? || type_name[0] != ?.
if type_name.empty? || type_name[0] != "."
return
end

Expand Down Expand Up @@ -193,14 +193,13 @@ def rewrite_enum_defaults
# above descriptor. We need to infer that "foo" is the package name, and not
# a message itself. */

def get_parent_name(msg_or_enum)
def split_parent_name(msg_or_enum)
name = msg_or_enum.name
idx = name.rindex(?.)
if idx
msg_or_enum.name = name[idx+1..-1]
return name[0...idx]
return name[0...idx], name[idx+1..-1]
else
return nil
return nil, name
end
end

Expand Down Expand Up @@ -229,7 +228,7 @@ def fix_nesting
# Note: We don't iterate over msgs_by_name.values because we want to
# preserve order as listed in the DSL.
@file_proto.message_type.each { |msg|
parent_name = get_parent_name(msg)
parent_name, msg.name = split_parent_name(msg)
if parent_name == package
final_msgs << msg
else
Expand All @@ -238,7 +237,7 @@ def fix_nesting
}

@file_proto.enum_type.each { |enum|
parent_name = get_parent_name(enum)
parent_name, enum.name = split_parent_name(enum)
if parent_name == package
final_enums << enum
else
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/ruby/ruby_generator.cc
Expand Up @@ -527,7 +527,7 @@ bool MaybeEmitDependency(const FileDescriptor* import,
}
}

bool GenerateDSLDescriptor(const FileDescriptor* file, io::Printer* printer,
bool GenerateDslDescriptor(const FileDescriptor* file, io::Printer* printer,
std::string* error) {
printer->Print(
"require 'google/protobuf'\n\n");
Expand Down Expand Up @@ -588,7 +588,7 @@ bool GenerateFile(const FileDescriptor* file, io::Printer* printer,
if (use_raw_descriptor) {
GenerateBinaryDescriptor(file, printer, error);
} else {
GenerateDSLDescriptor(file, printer, error);
GenerateDslDescriptor(file, printer, error);
}

int levels = GeneratePackageModules(file, printer);
Expand Down

0 comments on commit b7ab625

Please sign in to comment.