Update callers to use noncontiguous APIs

PiperOrigin-RevId: 696922501
pull/19241/head
Protobuf Team Bot 3 months ago committed by Copybara-Service
parent 8f37e42b14
commit 32afcb9cf8
  1. 17
      csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs
  2. 11
      upb/message/copy.c
  3. 1
      upb/message/test.cc
  4. 18
      upb/wire/decode.c
  5. 21
      upb/wire/encode.c

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

@ -8,6 +8,7 @@
#include "upb/message/copy.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "upb/base/descriptor_constants.h"
@ -280,12 +281,12 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
}
// Clone unknowns.
size_t unknown_size = 0;
const char* ptr = upb_Message_GetUnknown(src, &unknown_size);
if (unknown_size != 0) {
UPB_ASSERT(ptr);
uintptr_t iter = kUpb_Message_UnknownBegin;
upb_StringView unknowns;
while (upb_Message_NextUnknown(src, &unknowns, &iter)) {
// Make a copy into destination arena.
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, ptr, unknown_size, arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, unknowns.data, unknowns.size,
arena)) {
return NULL;
}
}

@ -501,6 +501,7 @@ TEST(MessageTest, MapField) {
// parse into second instance
upb_test_TestMapFieldExtra* test_msg_extra2 =
upb_test_TestMapFieldExtra_parse(serialized, size, arena.ptr());
ASSERT_NE(nullptr, test_msg_extra2);
ASSERT_TRUE(
upb_test_TestMapFieldExtra_map_field_get(test_msg_extra2, 0, nullptr));
}

@ -288,11 +288,14 @@ static upb_Message* _upb_Decoder_ReuseSubMessage(
upb_Message* existing =
UPB_PRIVATE(_upb_TaggedMessagePtr_GetEmptyMessage)(tagged);
upb_Message* promoted = _upb_Decoder_NewSubMessage(d, subs, field, target);
size_t size;
const char* unknown = upb_Message_GetUnknown(existing, &size);
upb_DecodeStatus status = upb_Decode(unknown, size, promoted, subl, d->extreg,
d->options, &d->arena);
if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status);
uintptr_t iter = kUpb_Message_UnknownBegin;
upb_StringView unknown;
while (upb_Message_NextUnknown(existing, &unknown, &iter)) {
upb_DecodeStatus status =
upb_Decode(unknown.data, unknown.size, promoted, subl, d->extreg,
d->options, &d->arena);
if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status);
}
return promoted;
}
@ -658,10 +661,7 @@ static const char* _upb_Decoder_DecodeToMap(
ptr = _upb_Decoder_DecodeSubMessage(d, ptr, &ent.message, subs, field,
val->size);
// check if ent had any unknown fields
size_t size;
upb_Message_GetUnknown(&ent.message, &size);
if (size != 0) {
if (upb_Message_HasUnknown(&ent.message)) {
char* buf;
size_t size;
uint32_t tag =

@ -565,11 +565,22 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
}
if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) {
size_t unknown_size;
const char* unknown = upb_Message_GetUnknown(msg, &unknown_size);
if (unknown) {
encode_bytes(e, unknown, unknown_size);
size_t unknown_size = 0;
uintptr_t iter = kUpb_Message_UnknownBegin;
upb_StringView unknown;
// Need to write in reverse order, but list is single-linked; scan to
// reserve capacity up front, then write in-order
while (upb_Message_NextUnknown(msg, &unknown, &iter)) {
unknown_size += unknown.size;
}
if (unknown_size != 0) {
encode_reserve(e, unknown_size);
char* ptr = e->ptr;
iter = kUpb_Message_UnknownBegin;
while (upb_Message_NextUnknown(msg, &unknown, &iter)) {
memcpy(ptr, unknown.data, unknown.size);
ptr += unknown.size;
}
}
}

Loading…
Cancel
Save