|
|
|
@ -68,7 +68,7 @@ void FieldGeneratorBase::SetCommonFieldVariables( |
|
|
|
|
io::CodedOutputStream::WriteTagToArray(tag, tag_array); |
|
|
|
|
std::string tag_bytes = absl::StrCat(tag_array[0]); |
|
|
|
|
for (int i = 1; i < part_tag_size; i++) { |
|
|
|
|
tag_bytes += ", " + absl::StrCat(tag_array[i]); |
|
|
|
|
absl::StrAppend(&tag_bytes, ", ", tag_array[i]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
(*variables)["tag"] = absl::StrCat(tag); |
|
|
|
@ -82,7 +82,7 @@ void FieldGeneratorBase::SetCommonFieldVariables( |
|
|
|
|
io::CodedOutputStream::WriteTagToArray(tag, tag_array); |
|
|
|
|
tag_bytes = absl::StrCat(tag_array[0]); |
|
|
|
|
for (int i = 1; i < part_tag_size; i++) { |
|
|
|
|
tag_bytes += ", " + absl::StrCat(tag_array[i]); |
|
|
|
|
absl::StrAppend(&tag_bytes, ", ", tag_array[i]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
variables_["end_tag"] = absl::StrCat(tag); |
|
|
|
@ -142,11 +142,11 @@ void FieldGeneratorBase::SetCommonOneofFieldVariables( |
|
|
|
|
absl::flat_hash_map<absl::string_view, std::string>* variables) { |
|
|
|
|
(*variables)["oneof_name"] = oneof_name(); |
|
|
|
|
if (SupportsPresenceApi(descriptor_)) { |
|
|
|
|
(*variables)["has_property_check"] = "Has" + property_name(); |
|
|
|
|
(*variables)["has_property_check"] = absl::StrCat("Has", property_name()); |
|
|
|
|
} else { |
|
|
|
|
(*variables)["has_property_check"] = |
|
|
|
|
oneof_name() + "Case_ == " + oneof_property_name() + |
|
|
|
|
"OneofCase." + oneof_case_name(); |
|
|
|
|
absl::StrCat(oneof_name(), "Case_ == ", oneof_property_name(), |
|
|
|
|
"OneofCase.", oneof_case_name()); |
|
|
|
|
} |
|
|
|
|
(*variables)["oneof_case_name"] = oneof_case_name(); |
|
|
|
|
(*variables)["oneof_property_name"] = oneof_property_name(); |
|
|
|
@ -244,7 +244,7 @@ std::string FieldGeneratorBase::type_name(const FieldDescriptor* descriptor) { |
|
|
|
|
wrapped_field->type() == FieldDescriptor::TYPE_BYTES) { |
|
|
|
|
return wrapped_field_type_name; |
|
|
|
|
} else { |
|
|
|
|
return wrapped_field_type_name + "?"; |
|
|
|
|
return absl::StrCat(wrapped_field_type_name, "?"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return GetClassName(descriptor->message_type()); |
|
|
|
@ -326,7 +326,7 @@ bool FieldGeneratorBase::has_default_value() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool AllPrintableAscii(const std::string& text) { |
|
|
|
|
bool AllPrintableAscii(absl::string_view text) { |
|
|
|
|
for(int i = 0; i < text.size(); i++) { |
|
|
|
|
if (text[i] < 0x20 || text[i] > 0x7e) { |
|
|
|
|
return false; |
|
|
|
@ -338,17 +338,19 @@ bool AllPrintableAscii(const std::string& text) { |
|
|
|
|
std::string FieldGeneratorBase::GetStringDefaultValueInternal(const FieldDescriptor* descriptor) { |
|
|
|
|
if (descriptor->default_value_string().empty()) |
|
|
|
|
return "\"\""; |
|
|
|
|
else |
|
|
|
|
return "global::System.Text.Encoding.UTF8.GetString(global::System." |
|
|
|
|
"Convert.FromBase64String(\"" + |
|
|
|
|
StringToBase64(descriptor->default_value_string()) + "\"), 0, " + absl::StrCat(descriptor->default_value_string().length()) + ")"; |
|
|
|
|
return absl::StrCat( |
|
|
|
|
"global::System.Text.Encoding.UTF8.GetString(global::System." |
|
|
|
|
"Convert.FromBase64String(\"", |
|
|
|
|
StringToBase64(descriptor->default_value_string()), "\"), 0, ", |
|
|
|
|
descriptor->default_value_string().length(), ")"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string FieldGeneratorBase::GetBytesDefaultValueInternal(const FieldDescriptor* descriptor) { |
|
|
|
|
if (descriptor->default_value_string().empty()) |
|
|
|
|
return "pb::ByteString.Empty"; |
|
|
|
|
else |
|
|
|
|
return "pb::ByteString.FromBase64(\"" + StringToBase64(descriptor->default_value_string()) + "\")"; |
|
|
|
|
return absl::StrCat("pb::ByteString.FromBase64(\"", |
|
|
|
|
StringToBase64(descriptor->default_value_string()), |
|
|
|
|
"\")"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string FieldGeneratorBase::default_value() { |
|
|
|
@ -358,8 +360,10 @@ std::string FieldGeneratorBase::default_value() { |
|
|
|
|
std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) { |
|
|
|
|
switch (descriptor->type()) { |
|
|
|
|
case FieldDescriptor::TYPE_ENUM: |
|
|
|
|
return GetClassName(descriptor->default_value_enum()->type()) + "." + |
|
|
|
|
GetEnumValueName(descriptor->default_value_enum()->type()->name(), descriptor->default_value_enum()->name()); |
|
|
|
|
return absl::StrCat( |
|
|
|
|
GetClassName(descriptor->default_value_enum()->type()), ".", |
|
|
|
|
GetEnumValueName(descriptor->default_value_enum()->type()->name(), |
|
|
|
|
descriptor->default_value_enum()->name())); |
|
|
|
|
case FieldDescriptor::TYPE_MESSAGE: |
|
|
|
|
case FieldDescriptor::TYPE_GROUP: |
|
|
|
|
if (IsWrapperType(descriptor)) { |
|
|
|
@ -377,7 +381,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) |
|
|
|
|
} else if (std::isnan(value)) { |
|
|
|
|
return "double.NaN"; |
|
|
|
|
} |
|
|
|
|
return absl::StrCat(value) + "D"; |
|
|
|
|
return absl::StrCat(value, "D"); |
|
|
|
|
} |
|
|
|
|
case FieldDescriptor::TYPE_FLOAT: { |
|
|
|
|
float value = descriptor->default_value_float(); |
|
|
|
@ -388,16 +392,16 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) |
|
|
|
|
} else if (std::isnan(value)) { |
|
|
|
|
return "float.NaN"; |
|
|
|
|
} |
|
|
|
|
return absl::StrCat(value) + "F"; |
|
|
|
|
return absl::StrCat(value, "F"); |
|
|
|
|
} |
|
|
|
|
case FieldDescriptor::TYPE_INT64: |
|
|
|
|
return absl::StrCat(descriptor->default_value_int64()) + "L"; |
|
|
|
|
return absl::StrCat(descriptor->default_value_int64(), "L"); |
|
|
|
|
case FieldDescriptor::TYPE_UINT64: |
|
|
|
|
return absl::StrCat(descriptor->default_value_uint64()) + "UL"; |
|
|
|
|
return absl::StrCat(descriptor->default_value_uint64(), "UL"); |
|
|
|
|
case FieldDescriptor::TYPE_INT32: |
|
|
|
|
return absl::StrCat(descriptor->default_value_int32()); |
|
|
|
|
case FieldDescriptor::TYPE_FIXED64: |
|
|
|
|
return absl::StrCat(descriptor->default_value_uint64()) + "UL"; |
|
|
|
|
return absl::StrCat(descriptor->default_value_uint64(), "UL"); |
|
|
|
|
case FieldDescriptor::TYPE_FIXED32: |
|
|
|
|
return absl::StrCat(descriptor->default_value_uint32()); |
|
|
|
|
case FieldDescriptor::TYPE_BOOL: |
|
|
|
@ -415,11 +419,11 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) |
|
|
|
|
case FieldDescriptor::TYPE_SFIXED32: |
|
|
|
|
return absl::StrCat(descriptor->default_value_int32()); |
|
|
|
|
case FieldDescriptor::TYPE_SFIXED64: |
|
|
|
|
return absl::StrCat(descriptor->default_value_int64()) + "L"; |
|
|
|
|
return absl::StrCat(descriptor->default_value_int64(), "L"); |
|
|
|
|
case FieldDescriptor::TYPE_SINT32: |
|
|
|
|
return absl::StrCat(descriptor->default_value_int32()); |
|
|
|
|
case FieldDescriptor::TYPE_SINT64: |
|
|
|
|
return absl::StrCat(descriptor->default_value_int64()) + "L"; |
|
|
|
|
return absl::StrCat(descriptor->default_value_int64(), "L"); |
|
|
|
|
default: |
|
|
|
|
GOOGLE_ABSL_LOG(FATAL) << "Unknown field type."; |
|
|
|
|
return ""; |
|
|
|
|