From e43ee0732d59b0837d3cae71812f4884fa61d851 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 11 Nov 2024 14:00:50 -0800 Subject: [PATCH] Use noncontiguous unknown fields API in upb text debug_string.c and encode.c PiperOrigin-RevId: 695473850 --- .../Reflection/FeatureSetDescriptor.g.cs | 17 ----------------- upb/text/BUILD | 1 - upb/text/debug_string.c | 16 ++-------------- upb/text/encode.c | 14 +------------- upb/text/internal/encode.c | 19 +++++++++++++++++++ upb/text/internal/encode.h | 4 ++++ 6 files changed, 26 insertions(+), 45 deletions(-) delete mode 100644 csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs diff --git a/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs b/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs deleted file mode 100644 index 208ce1fcb6..0000000000 --- a/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs +++ /dev/null @@ -1,17 +0,0 @@ -#region Copyright notice and license -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd -#endregion - -namespace Google.Protobuf.Reflection; - -internal sealed partial class FeatureSetDescriptor -{ - // Canonical serialized form of the edition defaults, generated by embed_edition_defaults. - private const string DefaultsBase64 = - "ChMYhAciACoMCAEQAhgCIAMoATACChMY5wciACoMCAIQARgBIAIoATABChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH"; -} diff --git a/upb/text/BUILD b/upb/text/BUILD index 793c9a1278..055621e296 100644 --- a/upb/text/BUILD +++ b/upb/text/BUILD @@ -47,7 +47,6 @@ cc_library( deps = [ ":internal", "//upb:base", - "//upb:eps_copy_input_stream", "//upb:message", "//upb:mini_table", "//upb:port", diff --git a/upb/text/debug_string.c b/upb/text/debug_string.c index 731cd1cfe0..eebf79ec48 100644 --- a/upb/text/debug_string.c +++ b/upb/text/debug_string.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -27,7 +28,6 @@ #include "upb/mini_table/internal/message.h" #include "upb/mini_table/message.h" #include "upb/text/internal/encode.h" -#include "upb/wire/eps_copy_input_stream.h" // Must be last. #include "upb/port/def.inc" @@ -201,19 +201,7 @@ static void _upb_MessageDebugString(txtenc* e, const upb_Message* msg, } } - if ((e->options & UPB_TXTENC_SKIPUNKNOWN) == 0) { - size_t size; - const char* ptr = upb_Message_GetUnknown(msg, &size); - if (size != 0) { - char* start = e->ptr; - upb_EpsCopyInputStream stream; - upb_EpsCopyInputStream_Init(&stream, &ptr, size, true); - if (!UPB_PRIVATE(_upb_TextEncode_Unknown)(e, ptr, &stream, -1)) { - /* Unknown failed to parse, back up and don't print it at all. */ - e->ptr = start; - } - } - } + UPB_PRIVATE(_upb_TextEncode_ParseUnknown)(e, msg); } size_t upb_DebugString(const upb_Message* msg, const upb_MiniTable* mt, diff --git a/upb/text/encode.c b/upb/text/encode.c index 5938a16377..7aa94a125f 100644 --- a/upb/text/encode.c +++ b/upb/text/encode.c @@ -176,19 +176,7 @@ static void _upb_TextEncode_Msg(txtenc* e, const upb_Message* msg, } } - if ((e->options & UPB_TXTENC_SKIPUNKNOWN) == 0) { - size_t size; - const char* ptr = upb_Message_GetUnknown(msg, &size); - if (size != 0) { - char* start = e->ptr; - upb_EpsCopyInputStream stream; - upb_EpsCopyInputStream_Init(&stream, &ptr, size, true); - if (!UPB_PRIVATE(_upb_TextEncode_Unknown)(e, ptr, &stream, -1)) { - /* Unknown failed to parse, back up and don't print it at all. */ - e->ptr = start; - } - } - } + UPB_PRIVATE(_upb_TextEncode_ParseUnknown)(e, msg); } size_t upb_TextEncode(const upb_Message* msg, const upb_MessageDef* m, diff --git a/upb/text/internal/encode.c b/upb/text/internal/encode.c index 403da037e4..dab01b01a4 100644 --- a/upb/text/internal/encode.c +++ b/upb/text/internal/encode.c @@ -15,6 +15,8 @@ #include "upb/base/string_view.h" #include "upb/lex/round_trip.h" #include "upb/message/array.h" +#include "upb/message/message.h" +#include "upb/text/options.h" #include "upb/wire/eps_copy_input_stream.h" #include "upb/wire/reader.h" #include "upb/wire/types.h" @@ -134,6 +136,23 @@ const char* UPB_PRIVATE(_upb_TextEncode_Unknown)(txtenc* e, const char* ptr, #undef CHK +void UPB_PRIVATE(_upb_TextEncode_ParseUnknown)(txtenc* e, + const upb_Message* msg) { + if ((e->options & UPB_TXTENC_SKIPUNKNOWN) != 0) return; + + uintptr_t iter = kUpb_Message_UnknownBegin; + upb_StringView view; + while (upb_Message_NextUnknown(msg, &view, &iter)) { + char* start = e->ptr; + upb_EpsCopyInputStream stream; + upb_EpsCopyInputStream_Init(&stream, &view.data, view.size, true); + if (!UPB_PRIVATE(_upb_TextEncode_Unknown)(e, view.data, &stream, -1)) { + /* Unknown failed to parse, back up and don't print it at all. */ + e->ptr = start; + } + } +} + void UPB_PRIVATE(_upb_TextEncode_Scalar)(txtenc* e, upb_MessageValue val, upb_CType ctype) { switch (ctype) { diff --git a/upb/text/internal/encode.h b/upb/text/internal/encode.h index 598b2a0c45..6220398997 100644 --- a/upb/text/internal/encode.h +++ b/upb/text/internal/encode.h @@ -15,6 +15,7 @@ #include "upb/base/string_view.h" #include "upb/message/array.h" #include "upb/message/internal/map_sorter.h" +#include "upb/message/message.h" #include "upb/port/vsnprintf_compat.h" #include "upb/text/options.h" #include "upb/wire/eps_copy_input_stream.h" @@ -230,6 +231,9 @@ const char* UPB_PRIVATE(_upb_TextEncode_Unknown)(txtenc* e, const char* ptr, upb_EpsCopyInputStream* stream, int groupnum); +void UPB_PRIVATE(_upb_TextEncode_ParseUnknown)(txtenc* e, + const upb_Message* msg); + // Must not be called for ctype = kUpb_CType_Enum, as they require different // handling depending on whether or not we're doing reflection-based encoding. void UPB_PRIVATE(_upb_TextEncode_Scalar)(txtenc* e, upb_MessageValue val,