Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit 3f4f7ab

Browse files
ericsalocopybara-github
authored andcommitted
properly format extension names in text_encode()
extension message names are now enclosed within square brackets PiperOrigin-RevId: 466499355
1 parent fcb666d commit 3f4f7ab

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

upb/text_encode.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,17 @@ static void txtenc_string(txtenc* e, upb_StringView str, bool bytes) {
158158
static void txtenc_field(txtenc* e, upb_MessageValue val,
159159
const upb_FieldDef* f) {
160160
txtenc_indent(e);
161-
upb_CType type = upb_FieldDef_CType(f);
161+
const upb_CType type = upb_FieldDef_CType(f);
162+
const bool is_ext = upb_FieldDef_IsExtension(f);
163+
const char* full = upb_FieldDef_FullName(f);
162164
const char* name = upb_FieldDef_Name(f);
163165

164166
if (type == kUpb_CType_Message) {
165-
txtenc_printf(e, "%s {", name);
167+
if (is_ext) {
168+
txtenc_printf(e, "[%s] {", full);
169+
} else {
170+
txtenc_printf(e, "%s {", name);
171+
}
166172
txtenc_endfield(e);
167173
e->indent_depth++;
168174
txtenc_msg(e, val.msg_val, upb_FieldDef_MessageSubDef(f));
@@ -173,7 +179,11 @@ static void txtenc_field(txtenc* e, upb_MessageValue val,
173179
return;
174180
}
175181

176-
txtenc_printf(e, "%s: ", name);
182+
if (is_ext) {
183+
txtenc_printf(e, "[%s]: ", full);
184+
} else {
185+
txtenc_printf(e, "%s: ", name);
186+
}
177187

178188
switch (type) {
179189
case kUpb_CType_Bool:

0 commit comments

Comments
 (0)