upb: use upb_MessageValue in upb_Extension

PiperOrigin-RevId: 602785269
pull/15614/head
Eric Salo 10 months ago committed by Copybara-Service
parent 44ec9d9e86
commit f212cc23d7
  1. 1
      upb/message/BUILD
  2. 4
      upb/message/copy.c
  3. 11
      upb/message/internal/extension.h
  4. 2
      upb/message/promote.c
  5. 1
      upb/message/promote.h
  6. 2
      upb/wire/encode.c

@ -56,6 +56,7 @@ cc_library(
srcs = [
"internal/extension.c",
"internal/message.c",
"value.h",
],
hdrs = [
"internal/accessors.h",

@ -265,7 +265,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
return NULL;
}
} else {
upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr;
upb_Array* msg_array = (upb_Array*)msg_ext->data.array_val;
UPB_ASSERT(msg_array);
upb_Array* cloned_array = upb_Array_DeepClone(
msg_array, upb_MiniTableField_CType(field),
@ -273,7 +273,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
if (!cloned_array) {
return NULL;
}
dst_ext->data.ptr = (void*)cloned_array;
dst_ext->data.array_val = cloned_array;
}
}

@ -8,9 +8,10 @@
#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_
#define UPB_MESSAGE_INTERNAL_EXTENSION_H_
#include "upb/base/string_view.h"
#include <stddef.h>
#include "upb/mem/arena.h"
#include "upb/message/internal/message.h"
#include "upb/message/value.h"
#include "upb/mini_table/extension.h"
// Must be last.
@ -26,11 +27,7 @@
// the most common extension type.
typedef struct {
const upb_MiniTableExtension* ext;
union {
upb_StringView str;
void* ptr;
char scalar_data[8];
} data;
upb_MessageValue data;
} upb_Extension;
#ifdef __cplusplus

@ -106,7 +106,7 @@ upb_GetExtension_Status upb_Message_GetOrPromoteExtension(
if (!ext) {
return kUpb_GetExtension_OutOfMemory;
}
ext->data.ptr = extension_msg;
ext->data.msg_val = extension_msg;
value->msg_val = extension_msg;
const char* delete_ptr = upb_Message_GetUnknown(msg, &len) + ofs;
upb_Message_DeleteUnknown(msg, delete_ptr, result.len);

@ -10,6 +10,7 @@
#include "upb/message/array.h"
#include "upb/message/map.h"
#include "upb/message/value.h"
#include "upb/wire/decode.h"
// Must be last.

@ -525,7 +525,7 @@ static void encode_field(upb_encstate* e, const upb_Message* msg,
static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) {
size_t size;
encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup);
encode_message(e, ext->data.ptr,
encode_message(e, ext->data.msg_val,
upb_MiniTableExtension_GetSubMessage(ext->ext), &size);
encode_varint(e, size);
encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited);

Loading…
Cancel
Save