|
|
|
@ -113,7 +113,7 @@ std::string TypeName(const FieldDescriptor* field) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string StringifySyntax(FileDescriptor::Syntax syntax) { |
|
|
|
|
std::string StringifySyntax(FileDescriptor::Syntax syntax) { |
|
|
|
|
switch (syntax) { |
|
|
|
|
case FileDescriptor::SYNTAX_PROTO2: |
|
|
|
|
return "proto2"; |
|
|
|
@ -147,7 +147,7 @@ std::string DefaultValueForField(const FieldDescriptor* field) { |
|
|
|
|
return NumberToString(field->default_value_enum()->number()); |
|
|
|
|
case FieldDescriptor::CPPTYPE_STRING: { |
|
|
|
|
std::ostringstream os; |
|
|
|
|
string default_str = field->default_value_string(); |
|
|
|
|
std::string default_str = field->default_value_string(); |
|
|
|
|
|
|
|
|
|
if (field->type() == FieldDescriptor::TYPE_STRING) { |
|
|
|
|
os << "\"" << default_str << "\""; |
|
|
|
@ -426,14 +426,14 @@ int GeneratePackageModules(const FileDescriptor* file, io::Printer* printer) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Use the appropriate delimiter
|
|
|
|
|
string delimiter = need_change_to_module ? "." : "::"; |
|
|
|
|
std::string delimiter = need_change_to_module ? "." : "::"; |
|
|
|
|
int delimiter_size = need_change_to_module ? 1 : 2; |
|
|
|
|
|
|
|
|
|
// Extract each module name and indent
|
|
|
|
|
while (!package_name.empty()) { |
|
|
|
|
size_t dot_index = package_name.find(delimiter); |
|
|
|
|
string component; |
|
|
|
|
if (dot_index == string::npos) { |
|
|
|
|
std::string component; |
|
|
|
|
if (dot_index == std::string::npos) { |
|
|
|
|
component = package_name; |
|
|
|
|
package_name = ""; |
|
|
|
|
} else { |
|
|
|
@ -462,7 +462,7 @@ void EndPackageModules(int levels, io::Printer* printer) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool UsesTypeFromFile(const Descriptor* message, const FileDescriptor* file, |
|
|
|
|
string* error) { |
|
|
|
|
std::string* error) { |
|
|
|
|
for (int i = 0; i < message->field_count(); i++) { |
|
|
|
|
const FieldDescriptor* field = message->field(i); |
|
|
|
|
if ((field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && |
|
|
|
@ -499,7 +499,7 @@ bool UsesTypeFromFile(const Descriptor* message, const FileDescriptor* file, |
|
|
|
|
bool MaybeEmitDependency(const FileDescriptor* import, |
|
|
|
|
const FileDescriptor* from, |
|
|
|
|
io::Printer* printer, |
|
|
|
|
string* error) { |
|
|
|
|
std::string* error) { |
|
|
|
|
if (from->syntax() == FileDescriptor::SYNTAX_PROTO3 && |
|
|
|
|
import->syntax() == FileDescriptor::SYNTAX_PROTO2) { |
|
|
|
|
for (int i = 0; i < from->message_type_count(); i++) { |
|
|
|
@ -524,7 +524,7 @@ bool MaybeEmitDependency(const FileDescriptor* import, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool GenerateFile(const FileDescriptor* file, io::Printer* printer, |
|
|
|
|
string* error) { |
|
|
|
|
std::string* error) { |
|
|
|
|
printer->Print( |
|
|
|
|
"# Generated by the protocol buffer compiler. DO NOT EDIT!\n" |
|
|
|
|
"# source: $filename$\n" |
|
|
|
@ -580,9 +580,9 @@ bool GenerateFile(const FileDescriptor* file, io::Printer* printer, |
|
|
|
|
|
|
|
|
|
bool Generator::Generate( |
|
|
|
|
const FileDescriptor* file, |
|
|
|
|
const string& parameter, |
|
|
|
|
const std::string& parameter, |
|
|
|
|
GeneratorContext* generator_context, |
|
|
|
|
string* error) const { |
|
|
|
|
std::string* error) const { |
|
|
|
|
|
|
|
|
|
if (file->syntax() != FileDescriptor::SYNTAX_PROTO3 && |
|
|
|
|
file->syntax() != FileDescriptor::SYNTAX_PROTO2) { |
|
|
|
|