|
|
|
@ -522,7 +522,7 @@ UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { |
|
|
|
|
return a.size == b.size && memcmp(a.data, b.data, a.size) == 0; |
|
|
|
|
return (a.size == b.size) && (!a.size || !memcmp(a.data, b.data, a.size)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LINT.ThenChange(
|
|
|
|
@ -1626,8 +1626,7 @@ extern "C" { |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// Creates a new message with the given mini_table on the given arena.
|
|
|
|
|
UPB_API upb_Message* upb_Message_New(const upb_MiniTable* mini_table, |
|
|
|
|
upb_Arena* arena); |
|
|
|
|
UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena); |
|
|
|
|
|
|
|
|
|
// Returns a reference to the message's unknown data.
|
|
|
|
|
const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); |
|
|
|
@ -2424,8 +2423,8 @@ void _upb_Message_DiscardUnknown_shallow(upb_Message* msg); |
|
|
|
|
|
|
|
|
|
// Adds unknown data (serialized protobuf data) to the given message.
|
|
|
|
|
// The data is copied into the message instance.
|
|
|
|
|
bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, |
|
|
|
|
upb_Arena* arena); |
|
|
|
|
bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, |
|
|
|
|
size_t len, upb_Arena* arena); |
|
|
|
|
|
|
|
|
|
bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, |
|
|
|
|
upb_Arena* arena); |
|
|
|
@ -2527,26 +2526,32 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE bool _upb_MiniTable_ValueIsNonZero(const void* default_val, |
|
|
|
|
const upb_MiniTableField* field) { |
|
|
|
|
char zero[16] = {0}; |
|
|
|
|
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataEquals)( |
|
|
|
|
const upb_MiniTableField* field, const void* a, const void* b) { |
|
|
|
|
switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { |
|
|
|
|
case kUpb_FieldRep_1Byte: |
|
|
|
|
return memcmp(&zero, default_val, 1) != 0; |
|
|
|
|
return memcmp(a, b, 1) == 0; |
|
|
|
|
case kUpb_FieldRep_4Byte: |
|
|
|
|
return memcmp(&zero, default_val, 4) != 0; |
|
|
|
|
return memcmp(a, b, 4) == 0; |
|
|
|
|
case kUpb_FieldRep_8Byte: |
|
|
|
|
return memcmp(&zero, default_val, 8) != 0; |
|
|
|
|
return memcmp(a, b, 8) == 0; |
|
|
|
|
case kUpb_FieldRep_StringView: { |
|
|
|
|
const upb_StringView* sv = (const upb_StringView*)default_val; |
|
|
|
|
return sv->size != 0; |
|
|
|
|
const upb_StringView sa = *(const upb_StringView*)a; |
|
|
|
|
const upb_StringView sb = *(const upb_StringView*)b; |
|
|
|
|
return upb_StringView_IsEqual(sa, sb); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
UPB_UNREACHABLE(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE void _upb_MiniTable_CopyFieldData(void* to, const void* from, |
|
|
|
|
const upb_MiniTableField* field) { |
|
|
|
|
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)( |
|
|
|
|
const upb_MiniTableField* field, const void* val) { |
|
|
|
|
const char zero[16] = {0}; |
|
|
|
|
return UPB_PRIVATE(_upb_MiniTableField_DataEquals)(field, val, zero); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)( |
|
|
|
|
const upb_MiniTableField* field, void* to, const void* from) { |
|
|
|
|
switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { |
|
|
|
|
case kUpb_FieldRep_1Byte: |
|
|
|
|
memcpy(to, from, 1); |
|
|
|
@ -2621,24 +2626,26 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( |
|
|
|
|
const void* default_val, void* val) { |
|
|
|
|
UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); |
|
|
|
|
if ((upb_MiniTableField_IsInOneof(field) || |
|
|
|
|
_upb_MiniTable_ValueIsNonZero(default_val, field)) && |
|
|
|
|
!UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, default_val)) && |
|
|
|
|
!_upb_Message_HasNonExtensionField(msg, field)) { |
|
|
|
|
_upb_MiniTable_CopyFieldData(val, default_val, field); |
|
|
|
|
UPB_PRIVATE(_upb_MiniTableField_DataCopy)(field, val, default_val); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
_upb_MiniTable_CopyFieldData(val, _upb_MiniTableField_GetConstPtr(msg, field), |
|
|
|
|
field); |
|
|
|
|
UPB_PRIVATE(_upb_MiniTableField_DataCopy) |
|
|
|
|
(field, val, _upb_MiniTableField_GetConstPtr(msg, field)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE void _upb_Message_GetExtensionField( |
|
|
|
|
const upb_Message* msg, const upb_MiniTableExtension* mt_ext, |
|
|
|
|
const void* default_val, void* val) { |
|
|
|
|
UPB_ASSUME(upb_MiniTableField_IsExtension(&mt_ext->UPB_PRIVATE(field))); |
|
|
|
|
const upb_Message_Extension* ext = _upb_Message_Getext(msg, mt_ext); |
|
|
|
|
const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); |
|
|
|
|
UPB_ASSUME(upb_MiniTableField_IsExtension(f)); |
|
|
|
|
|
|
|
|
|
if (ext) { |
|
|
|
|
_upb_MiniTable_CopyFieldData(val, &ext->data, &mt_ext->UPB_PRIVATE(field)); |
|
|
|
|
UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, &ext->data); |
|
|
|
|
} else { |
|
|
|
|
_upb_MiniTable_CopyFieldData(val, default_val, &mt_ext->UPB_PRIVATE(field)); |
|
|
|
|
UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, default_val); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2673,8 +2680,8 @@ UPB_INLINE void _upb_Message_SetNonExtensionField( |
|
|
|
|
upb_Message* msg, const upb_MiniTableField* field, const void* val) { |
|
|
|
|
UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); |
|
|
|
|
UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); |
|
|
|
|
_upb_MiniTable_CopyFieldData(_upb_MiniTableField_GetPtr(msg, field), val, |
|
|
|
|
field); |
|
|
|
|
UPB_PRIVATE(_upb_MiniTableField_DataCopy) |
|
|
|
|
(field, _upb_MiniTableField_GetPtr(msg, field), val); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE bool _upb_Message_SetExtensionField( |
|
|
|
@ -2684,7 +2691,8 @@ UPB_INLINE bool _upb_Message_SetExtensionField( |
|
|
|
|
upb_Message_Extension* ext = |
|
|
|
|
_upb_Message_GetOrCreateExtension(msg, mt_ext, a); |
|
|
|
|
if (!ext) return false; |
|
|
|
|
_upb_MiniTable_CopyFieldData(&ext->data, val, &mt_ext->UPB_PRIVATE(field)); |
|
|
|
|
UPB_PRIVATE(_upb_MiniTableField_DataCopy) |
|
|
|
|
(&mt_ext->UPB_PRIVATE(field), &ext->data, val); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2712,8 +2720,8 @@ UPB_INLINE void _upb_Message_ClearNonExtensionField( |
|
|
|
|
*ptr = 0; |
|
|
|
|
} |
|
|
|
|
const char zeros[16] = {0}; |
|
|
|
|
_upb_MiniTable_CopyFieldData(_upb_MiniTableField_GetPtr(msg, field), zeros, |
|
|
|
|
field); |
|
|
|
|
UPB_PRIVATE(_upb_MiniTableField_DataCopy) |
|
|
|
|
(field, _upb_MiniTableField_GetPtr(msg, field), zeros); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE void _upb_Message_AssertMapIsUntagged( |
|
|
|
@ -2861,7 +2869,6 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, |
|
|
|
|
|
|
|
|
|
// LINT.ThenChange(
|
|
|
|
|
// GoogleInternalName1,
|
|
|
|
|
// //depot/google3/third_party/upb/bits/typescript/array.ts
|
|
|
|
|
//)
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
@ -12531,7 +12538,7 @@ UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { |
|
|
|
|
if (s->entries) free(s->entries); |
|
|
|
|
if (s->entries) upb_gfree(s->entries); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, |
|
|
|
@ -13551,8 +13558,8 @@ UPB_INLINE const char* _upb_Decoder_BufferFlipCallback( |
|
|
|
|
if (!old_end) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); |
|
|
|
|
|
|
|
|
|
if (d->unknown) { |
|
|
|
|
if (!_upb_Message_AddUnknown(d->unknown_msg, d->unknown, |
|
|
|
|
old_end - d->unknown, &d->arena)) { |
|
|
|
|
if (!UPB_PRIVATE(_upb_Message_AddUnknown)( |
|
|
|
|
d->unknown_msg, d->unknown, old_end - d->unknown, &d->arena)) { |
|
|
|
|
_upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); |
|
|
|
|
} |
|
|
|
|
d->unknown = new_start; |
|
|
|
|