Skip to content

Commit 8694620

Browse files
Internal change
PiperOrigin-RevId: 759439360
1 parent acd71c7 commit 8694620

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/google/protobuf/compiler/cpp/field.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ std::vector<Sub> FieldVars(const FieldDescriptor* field, const Options& opts) {
5858
{"field_", FieldMemberName(field, split)},
5959
{"DeclaredType", DeclaredTypeMethodName(field->type())},
6060
{"DeclaredCppType", DeclaredCppTypeMethodName(field->cpp_type())},
61+
{"Utf8", IsStrictUtf8String(field, opts) ? "Utf8" : "Raw"},
6162
{"kTagBytes", WireFormat::TagSize(field->number(), field->type())},
6263
Sub("PrepareSplitMessageForWrite",
6364
split ? "PrepareSplitMessageForWrite();" : "")

src/google/protobuf/compiler/cpp/helpers.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,15 @@ void NamespaceOpener::ChangeTo(absl::string_view name,
14691469
name_stack_ = std::move(new_stack);
14701470
}
14711471

1472+
bool IsStrictUtf8String(const FieldDescriptor* field, const Options& options) {
1473+
if (field->type() != FieldDescriptor::TYPE_STRING) return false;
1474+
1475+
bool is_lite =
1476+
GetOptimizeFor(field->file(), options) == FileOptions::LITE_RUNTIME;
1477+
return internal::cpp::GetUtf8CheckMode(field, is_lite) ==
1478+
internal::cpp::Utf8CheckMode::kStrict;
1479+
}
1480+
14721481
static void GenerateUtf8CheckCode(io::Printer* p, const FieldDescriptor* field,
14731482
const Options& options, bool for_parse,
14741483
absl::string_view params,

src/google/protobuf/compiler/cpp/helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,8 @@ void GenerateUtf8CheckCodeForCord(io::Printer* p, const FieldDescriptor* field,
11441144
const Options& options, bool for_parse,
11451145
absl::string_view parameters);
11461146

1147+
bool IsStrictUtf8String(const FieldDescriptor* field, const Options& options);
1148+
11471149
inline bool ShouldGenerateExternSpecializations(const Options& options) {
11481150
// For OSS we omit the specializations to reduce codegen size.
11491151
// Some compilers can't handle that much input in a single translation unit.

0 commit comments

Comments
 (0)