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 208ce1fcb6319..0000000000000 --- 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/message/copy.c b/upb/message/copy.c index 94f41056355e5..e9c5f6121aceb 100644 --- a/upb/message/copy.c +++ b/upb/message/copy.c @@ -8,6 +8,7 @@ #include "upb/message/copy.h" #include +#include #include #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; } } diff --git a/upb/message/test.cc b/upb/message/test.cc index 446da19dfa622..a96a7789fd11a 100644 --- a/upb/message/test.cc +++ b/upb/message/test.cc @@ -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)); } diff --git a/upb/wire/decode.c b/upb/wire/decode.c index a3e3612d2e1d2..e195d9ff7f9ff 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -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 = diff --git a/upb/wire/encode.c b/upb/wire/encode.c index 5764199e44fa1..85764e3eb01ae 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -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; + } } }