Skip to content

Commit

Permalink
Update callers to use noncontiguous APIs
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 696922501
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Nov 15, 2024
1 parent 8f37e42 commit 32afcb9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 36 deletions.
17 changes: 0 additions & 17 deletions csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs

This file was deleted.

11 changes: 6 additions & 5 deletions upb/message/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "upb/message/copy.h"

#include <stdbool.h>
#include <stdint.h>
#include <string.h>

#include "upb/base/descriptor_constants.h"
Expand Down Expand Up @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions upb/message/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
18 changes: 9 additions & 9 deletions upb/wire/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 =
Expand Down
21 changes: 16 additions & 5 deletions upb/wire/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 32afcb9

Please sign in to comment.