Merge GetEnum into GetInt32. Rename SetEnum to SetEnumProto2 to be clear that upb only treats Proto2 enum as enum. Proto3 enums should use SetInt32.

PiperOrigin-RevId: 467000685
pull/13171/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 63a4a7d74b
commit 0c6531378d
  1. 5
      upb/mini_table.h
  2. 19
      upb/mini_table_accessors.h

@ -45,6 +45,11 @@ UPB_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable(
return mini_table->subs[field->submsg_index].submsg;
}
UPB_INLINE const upb_MiniTable_Enum* upb_MiniTable_GetSubEnumTable(
const upb_MiniTable* mini_table, const upb_MiniTable_Field* field) {
return mini_table->subs[field->submsg_index].subenum;
}
// Validates enum value against range defined by enum mini table.
UPB_INLINE bool upb_MiniTable_Enum_CheckValue(const upb_MiniTable_Enum* e,
int32_t val) {

@ -30,6 +30,7 @@
#include "upb/array.h"
#include "upb/internal/mini_table_accessors.h"
#include "upb/mini_table.h"
#include "upb/msg_internal.h"
// Must be last.
@ -63,7 +64,8 @@ UPB_INLINE int32_t upb_MiniTable_GetInt32(const upb_Message* msg,
const upb_MiniTable_Field* field) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Int32 ||
field->descriptortype == kUpb_FieldType_SInt32 ||
field->descriptortype == kUpb_FieldType_SFixed32);
field->descriptortype == kUpb_FieldType_SFixed32 ||
field->descriptortype == kUpb_FieldType_Enum);
return *UPB_PTR_AT(msg, field->offset, int32_t);
}
@ -93,16 +95,13 @@ UPB_INLINE void upb_MiniTable_SetUInt32(upb_Message* msg,
*UPB_PTR_AT(msg, field->offset, uint32_t) = value;
}
UPB_INLINE int32_t upb_MiniTable_GetEnum(const upb_Message* msg,
const upb_MiniTable_Field* field) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Enum);
return *UPB_PTR_AT(msg, field->offset, int32_t);
}
UPB_INLINE void upb_MiniTable_SetEnum(upb_Message* msg,
const upb_MiniTable_Field* field,
int32_t value) {
UPB_INLINE void upb_MiniTable_SetEnumProto2(upb_Message* msg,
const upb_MiniTable* msg_mini_table,
const upb_MiniTable_Field* field,
int32_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Enum);
UPB_ASSERT(upb_MiniTable_Enum_CheckValue(
upb_MiniTable_GetSubEnumTable(msg_mini_table, field), value));
_upb_MiniTable_SetPresence(msg, field);
*UPB_PTR_AT(msg, field->offset, int32_t) = value;
}

Loading…
Cancel
Save