diff --git a/upb/text_encode.c b/upb/text_encode.c index fe5f458cdf..f3a63e91fd 100644 --- a/upb/text_encode.c +++ b/upb/text_encode.c @@ -158,11 +158,17 @@ static void txtenc_string(txtenc* e, upb_StringView str, bool bytes) { static void txtenc_field(txtenc* e, upb_MessageValue val, const upb_FieldDef* f) { txtenc_indent(e); - upb_CType type = upb_FieldDef_CType(f); + const upb_CType type = upb_FieldDef_CType(f); + const bool is_ext = upb_FieldDef_IsExtension(f); + const char* full = upb_FieldDef_FullName(f); const char* name = upb_FieldDef_Name(f); if (type == kUpb_CType_Message) { - txtenc_printf(e, "%s {", name); + if (is_ext) { + txtenc_printf(e, "[%s] {", full); + } else { + txtenc_printf(e, "%s {", name); + } txtenc_endfield(e); e->indent_depth++; txtenc_msg(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); @@ -173,7 +179,11 @@ static void txtenc_field(txtenc* e, upb_MessageValue val, return; } - txtenc_printf(e, "%s: ", name); + if (is_ext) { + txtenc_printf(e, "[%s]: ", full); + } else { + txtenc_printf(e, "%s: ", name); + } switch (type) { case kUpb_CType_Bool: