@@ -1797,6 +1797,56 @@ void Reflection::SetString(Message* message, const FieldDescriptor* field,
17971797 }
17981798}
17991799
1800+ void Reflection::SetString (Message* message, const FieldDescriptor* field,
1801+ const absl::Cord& value) const {
1802+ USAGE_CHECK_ALL (SetString, SINGULAR, STRING);
1803+ if (field->is_extension ()) {
1804+ return absl::CopyCordToString (value,
1805+ MutableExtensionSet (message)->MutableString (
1806+ field->number (), field->type (), field));
1807+ } else {
1808+ switch (field->options ().ctype ()) {
1809+ case FieldOptions::CORD:
1810+ if (schema_.InRealOneof (field)) {
1811+ if (!HasOneofField (*message, field)) {
1812+ ClearOneof (message, field->containing_oneof ());
1813+ *MutableField<absl::Cord*>(message, field) =
1814+ Arena::Create<absl::Cord>(message->GetArenaForAllocation ());
1815+ }
1816+ *(*MutableField<absl::Cord*>(message, field)) = value;
1817+ } else {
1818+ *MutableField<absl::Cord>(message, field) = value;
1819+ }
1820+ break ;
1821+ default :
1822+ case FieldOptions::STRING: {
1823+ // Oneof string fields are never set as a default instance.
1824+ // We just need to pass some arbitrary default string to make it work.
1825+ // This allows us to not have the real default accessible from
1826+ // reflection.
1827+ if (schema_.InRealOneof (field) && !HasOneofField (*message, field)) {
1828+ ClearOneof (message, field->containing_oneof ());
1829+ MutableField<ArenaStringPtr>(message, field)->InitDefault ();
1830+ }
1831+ if (IsInlined (field)) {
1832+ auto * str = MutableField<InlinedStringField>(message, field);
1833+ const uint32_t index = schema_.InlinedStringIndex (field);
1834+ ABSL_DCHECK_GT (index, 0 );
1835+ uint32_t * states =
1836+ &MutableInlinedStringDonatedArray (message)[index / 32 ];
1837+ uint32_t mask = ~(static_cast <uint32_t >(1 ) << (index % 32 ));
1838+ str->Set (std::string (value), message->GetArenaForAllocation (),
1839+ IsInlinedStringDonated (*message, field), states, mask,
1840+ message);
1841+ } else {
1842+ auto * str = MutableField<ArenaStringPtr>(message, field);
1843+ str->Set (std::string (value), message->GetArenaForAllocation ());
1844+ }
1845+ break ;
1846+ }
1847+ }
1848+ }
1849+ }
18001850
18011851std::string Reflection::GetRepeatedString (const Message& message,
18021852 const FieldDescriptor* field,
0 commit comments