Use noncontiguous unknown fields API in upb text debug_string.c and encode.c

PiperOrigin-RevId: 695473850
pull/19203/head
Protobuf Team Bot 4 months ago committed by Copybara-Service
parent e77099f34b
commit e43ee0732d
  1. 17
      csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs
  2. 1
      upb/text/BUILD
  3. 16
      upb/text/debug_string.c
  4. 14
      upb/text/encode.c
  5. 19
      upb/text/internal/encode.c
  6. 4
      upb/text/internal/encode.h

@ -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";
}

@ -47,7 +47,6 @@ cc_library(
deps = [
":internal",
"//upb:base",
"//upb:eps_copy_input_stream",
"//upb:message",
"//upb:mini_table",
"//upb:port",

@ -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 @@ 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,

@ -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,

@ -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) {

@ -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,

Loading…
Cancel
Save