|
|
|
@ -6104,7 +6104,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, |
|
|
|
|
upb_Arena* arena) { |
|
|
|
|
upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); |
|
|
|
|
// Only copy message area skipping upb_Message_Internal.
|
|
|
|
|
memcpy(dst, src, mini_table->size); |
|
|
|
|
memcpy(dst, src, mini_table->UPB_PRIVATE(size)); |
|
|
|
|
for (size_t i = 0; i < mini_table->UPB_PRIVATE(field_count); ++i) { |
|
|
|
|
const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i]; |
|
|
|
|
if (upb_MiniTableField_IsScalar(field)) { |
|
|
|
@ -6213,11 +6213,25 @@ bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, |
|
|
|
|
// Deep clones a message using the provided target arena.
|
|
|
|
|
//
|
|
|
|
|
// Returns NULL on failure.
|
|
|
|
|
upb_Message* upb_Message_DeepClone(const upb_Message* message, |
|
|
|
|
const upb_MiniTable* mini_table, |
|
|
|
|
upb_Message* upb_Message_DeepClone(const upb_Message* msg, |
|
|
|
|
const upb_MiniTable* m, upb_Arena* arena) { |
|
|
|
|
upb_Message* clone = upb_Message_New(m, arena); |
|
|
|
|
return _upb_Message_Copy(clone, msg, m, arena); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Performs a shallow copy. TODO: Extend to handle unknown fields.
|
|
|
|
|
void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, |
|
|
|
|
const upb_MiniTable* m) { |
|
|
|
|
memcpy(dst, src, m->UPB_PRIVATE(size)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Performs a shallow clone. Ignores unknown fields.
|
|
|
|
|
upb_Message* upb_Message_ShallowClone(const upb_Message* msg, |
|
|
|
|
const upb_MiniTable* m, |
|
|
|
|
upb_Arena* arena) { |
|
|
|
|
upb_Message* clone = upb_Message_New(mini_table, arena); |
|
|
|
|
return _upb_Message_Copy(clone, message, mini_table, arena); |
|
|
|
|
upb_Message* clone = upb_Message_New(m, arena); |
|
|
|
|
upb_Message_ShallowCopy(clone, msg, m); |
|
|
|
|
return clone; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -7405,20 +7419,21 @@ static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ret->size = last_hasbit ? upb_MiniTable_DivideRoundUp(last_hasbit + 1, 8) : 0; |
|
|
|
|
ret->UPB_PRIVATE(size) = |
|
|
|
|
last_hasbit ? upb_MiniTable_DivideRoundUp(last_hasbit + 1, 8) : 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
size_t upb_MtDecoder_Place(upb_MtDecoder* d, upb_FieldRep rep) { |
|
|
|
|
size_t size = upb_MtDecoder_SizeOfRep(rep, d->platform); |
|
|
|
|
size_t align = upb_MtDecoder_AlignOfRep(rep, d->platform); |
|
|
|
|
size_t ret = UPB_ALIGN_UP(d->table->size, align); |
|
|
|
|
size_t ret = UPB_ALIGN_UP(d->table->UPB_PRIVATE(size), align); |
|
|
|
|
static const size_t max = UINT16_MAX; |
|
|
|
|
size_t new_size = ret + size; |
|
|
|
|
if (new_size > max) { |
|
|
|
|
upb_MdDecoder_ErrorJmp( |
|
|
|
|
&d->base, "Message size exceeded maximum size of %zu bytes", max); |
|
|
|
|
} |
|
|
|
|
d->table->size = new_size; |
|
|
|
|
d->table->UPB_PRIVATE(size) = new_size; |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -7468,7 +7483,7 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { |
|
|
|
|
//
|
|
|
|
|
// On 32-bit we could potentially make this smaller, but there is no
|
|
|
|
|
// compelling reason to optimize this right now.
|
|
|
|
|
d->table->size = UPB_ALIGN_UP(d->table->size, 8); |
|
|
|
|
d->table->UPB_PRIVATE(size) = UPB_ALIGN_UP(d->table->UPB_PRIVATE(size), 8); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void upb_MtDecoder_ValidateEntryField(upb_MtDecoder* d, |
|
|
|
@ -7529,7 +7544,8 @@ static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, |
|
|
|
|
const size_t hasbit_size = 8; |
|
|
|
|
d->fields[0].offset = hasbit_size; |
|
|
|
|
d->fields[1].offset = hasbit_size + kv_size; |
|
|
|
|
d->table->size = UPB_ALIGN_UP(hasbit_size + kv_size + kv_size, 8); |
|
|
|
|
d->table->UPB_PRIVATE(size) = |
|
|
|
|
UPB_ALIGN_UP(hasbit_size + kv_size + kv_size, 8); |
|
|
|
|
|
|
|
|
|
// Map entries have a special bit set to signal it's a map entry, used in
|
|
|
|
|
// upb_MiniTable_SetSubMessage() below.
|
|
|
|
@ -7544,7 +7560,7 @@ static void upb_MtDecoder_ParseMessageSet(upb_MtDecoder* d, const char* data, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
upb_MiniTable* ret = d->table; |
|
|
|
|
ret->size = 0; |
|
|
|
|
ret->UPB_PRIVATE(size) = 0; |
|
|
|
|
ret->UPB_PRIVATE(field_count) = 0; |
|
|
|
|
ret->UPB_PRIVATE(ext) = kUpb_ExtMode_IsMessageSet; |
|
|
|
|
ret->UPB_PRIVATE(dense_below) = 0; |
|
|
|
@ -7557,7 +7573,7 @@ static upb_MiniTable* upb_MtDecoder_DoBuildMiniTableWithBuf( |
|
|
|
|
size_t* buf_size) { |
|
|
|
|
upb_MdDecoder_CheckOutOfMemory(&decoder->base, decoder->table); |
|
|
|
|
|
|
|
|
|
decoder->table->size = 0; |
|
|
|
|
decoder->table->UPB_PRIVATE(size) = 0; |
|
|
|
|
decoder->table->UPB_PRIVATE(field_count) = 0; |
|
|
|
|
decoder->table->UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable; |
|
|
|
|
decoder->table->UPB_PRIVATE(dense_below) = 0; |
|
|
|
@ -8319,7 +8335,7 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, |
|
|
|
|
const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { |
|
|
|
|
.UPB_PRIVATE(subs) = NULL, |
|
|
|
|
.UPB_PRIVATE(fields) = NULL, |
|
|
|
|
.size = 0, |
|
|
|
|
.UPB_PRIVATE(size) = 0, |
|
|
|
|
.UPB_PRIVATE(field_count) = 0, |
|
|
|
|
.UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, |
|
|
|
|
.UPB_PRIVATE(dense_below) = 0, |
|
|
|
@ -14816,9 +14832,9 @@ TAGBYTES(r) |
|
|
|
|
/* message fields *************************************************************/ |
|
|
|
|
|
|
|
|
|
UPB_INLINE |
|
|
|
|
upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* l, |
|
|
|
|
upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, |
|
|
|
|
int msg_ceil_bytes) { |
|
|
|
|
size_t size = l->size + sizeof(upb_Message_Internal); |
|
|
|
|
size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); |
|
|
|
|
char* msg_data; |
|
|
|
|
if (UPB_LIKELY(msg_ceil_bytes > 0 && |
|
|
|
|
_upb_ArenaHas(&d->arena) >= msg_ceil_bytes)) { |
|
|
|
|