From 3f4f7ab0792ff9dd3322805bb2c4b44472d08122 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 9 Aug 2022 16:17:03 -0700 Subject: [PATCH] properly format extension names in text_encode() extension message names are now enclosed within square brackets PiperOrigin-RevId: 466499355 --- upb/text_encode.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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: