upb: fix SetInt32 accessor to also work on enum ctypes

Also rename upb_Message_SetEnumProto2() as upb_Message_SetClosedEnum()

PiperOrigin-RevId: 526742169
pull/13171/head
Eric Salo 2 years ago committed by Copybara-Service
parent 30af08f511
commit 48e3272a2a
  1. 2
      upb/base/descriptor_constants.h
  2. 5
      upb/message/accessors.h

@ -40,7 +40,7 @@ typedef enum {
kUpb_CType_Float = 2,
kUpb_CType_Int32 = 3,
kUpb_CType_UInt32 = 4,
kUpb_CType_Enum = 5, // Enum values are int32.
kUpb_CType_Enum = 5, // Enum values are int32. TODO(b/279178239): rename
kUpb_CType_Message = 6,
kUpb_CType_Double = 7,
kUpb_CType_Int64 = 8,

@ -108,7 +108,8 @@ UPB_API_INLINE int32_t upb_Message_GetInt32(const upb_Message* msg,
UPB_API_INLINE bool upb_Message_SetInt32(upb_Message* msg,
const upb_MiniTableField* field,
int32_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int32);
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(field) == kUpb_CType_Enum);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field));
return _upb_Message_SetField(msg, field, &value, a);
@ -134,7 +135,7 @@ UPB_API_INLINE bool upb_Message_SetUInt32(upb_Message* msg,
return _upb_Message_SetField(msg, field, &value, a);
}
UPB_API_INLINE void upb_Message_SetEnumProto2(
UPB_API_INLINE void upb_Message_SetClosedEnum(
upb_Message* msg, const upb_MiniTable* msg_mini_table,
const upb_MiniTableField* field, int32_t value) {
UPB_ASSERT(upb_MiniTableField_IsClosedEnum(field));

Loading…
Cancel
Save