Use noncontiguous unknown fields API in upb text debug_string.c and encode.c
PiperOrigin-RevId: 695473850
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 208ce1f..0000000
--- 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 793c9a1..055621e 100644
--- a/upb/text/BUILD
+++ b/upb/text/BUILD
@@ -47,7 +47,6 @@
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 731cd1c..eebf79e 100644
--- a/upb/text/debug_string.c
+++ b/upb/text/debug_string.c
@@ -10,6 +10,7 @@
#include <inttypes.h>
#include <stdarg.h>
#include <stddef.h>
+#include <stdint.h>
#include <stdio.h>
#include <string.h>
@@ -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 @@
}
}
- 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 5938a16..7aa94a1 100644
--- a/upb/text/encode.c
+++ b/upb/text/encode.c
@@ -176,19 +176,7 @@
}
}
- 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 403da03..dab01b0 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 @@
#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 598b2a0..6220398 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 @@
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,