upb: publish and start using the new non-universal setters out in the wild

PiperOrigin-RevId: 632663127
pull/16779/head
Eric Salo 10 months ago committed by Copybara-Service
parent be99767a69
commit f93565c20c
  1. 96
      upb/message/accessors.h
  2. 22
      upb/message/accessors_test.cc
  3. 11
      upb/message/internal/accessors.h

@ -51,14 +51,6 @@ UPB_API_INLINE bool upb_Message_HasBaseField(const upb_Message* msg,
UPB_API_INLINE bool upb_Message_HasExtension(const upb_Message* msg,
const upb_MiniTableExtension* e);
UPB_API_INLINE void upb_Message_SetBaseField(upb_Message* msg,
const upb_MiniTableField* f,
const void* val);
UPB_API_INLINE bool upb_Message_SetExtension(upb_Message* msg,
const upb_MiniTableExtension* e,
const void* val, upb_Arena* a);
UPB_API_INLINE upb_MessageValue
upb_Message_GetField(const upb_Message* msg, const upb_MiniTableField* f,
upb_MessageValue default_val);
@ -128,14 +120,92 @@ UPB_API_INLINE uint64_t upb_Message_GetUInt64(const upb_Message* msg,
const upb_MiniTableField* f,
uint64_t default_val);
UPB_API_INLINE bool upb_Message_SetBool(upb_Message* msg,
const upb_MiniTableField* f, bool value,
upb_Arena* a);
UPB_API_INLINE void upb_Message_SetClosedEnum(
upb_Message* msg, const upb_MiniTable* msg_mini_table,
const upb_MiniTableField* f, int32_t value);
// BaseField Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE void upb_Message_SetBaseField(upb_Message* msg,
const upb_MiniTableField* f,
const void* val);
UPB_API_INLINE void upb_Message_SetBaseFieldBool(struct upb_Message* msg,
const upb_MiniTableField* f,
bool value);
UPB_API_INLINE void upb_Message_SetBaseFieldDouble(struct upb_Message* msg,
const upb_MiniTableField* f,
double value);
UPB_API_INLINE void upb_Message_SetBaseFieldFloat(struct upb_Message* msg,
const upb_MiniTableField* f,
float value);
UPB_API_INLINE void upb_Message_SetBaseFieldInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
int32_t value);
UPB_API_INLINE void upb_Message_SetBaseFieldInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
int64_t value);
UPB_API_INLINE void upb_Message_SetBaseFieldString(struct upb_Message* msg,
const upb_MiniTableField* f,
upb_StringView value);
UPB_API_INLINE void upb_Message_SetBaseFieldUInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
uint32_t value);
UPB_API_INLINE void upb_Message_SetBaseFieldUInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
uint64_t value);
// Extension Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE bool upb_Message_SetExtension(upb_Message* msg,
const upb_MiniTableExtension* e,
const void* value, upb_Arena* a);
UPB_API_INLINE bool upb_Message_SetExtensionBool(
struct upb_Message* msg, const upb_MiniTableExtension* e, bool value,
upb_Arena* a);
UPB_API_INLINE bool upb_Message_SetExtensionDouble(
struct upb_Message* msg, const upb_MiniTableExtension* e, double value,
upb_Arena* a);
UPB_API_INLINE bool upb_Message_SetExtensionFloat(
struct upb_Message* msg, const upb_MiniTableExtension* e, float value,
upb_Arena* a);
UPB_API_INLINE bool upb_Message_SetExtensionInt32(
struct upb_Message* msg, const upb_MiniTableExtension* e, int32_t value,
upb_Arena* a);
UPB_API_INLINE bool upb_Message_SetExtensionInt64(
struct upb_Message* msg, const upb_MiniTableExtension* e, int64_t value,
upb_Arena* a);
UPB_API_INLINE bool upb_Message_SetExtensionString(
struct upb_Message* msg, const upb_MiniTableExtension* e,
upb_StringView value, upb_Arena* a);
UPB_API_INLINE bool upb_Message_SetExtensionUInt32(
struct upb_Message* msg, const upb_MiniTableExtension* e, uint32_t value,
upb_Arena* a);
UPB_API_INLINE bool upb_Message_SetExtensionUInt64(
struct upb_Message* msg, const upb_MiniTableExtension* e, uint64_t value,
upb_Arena* a);
// Universal Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE bool upb_Message_SetBool(upb_Message* msg,
const upb_MiniTableField* f, bool value,
upb_Arena* a);
UPB_API_INLINE bool upb_Message_SetDouble(upb_Message* msg,
const upb_MiniTableField* f,
double value, upb_Arena* a);
@ -168,6 +238,8 @@ UPB_API_INLINE bool upb_Message_SetUInt64(upb_Message* msg,
const upb_MiniTableField* f,
uint64_t value, upb_Arena* a);
////////////////////////////////////////////////////////////////////////////////
UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized(
upb_Message* msg, const upb_MiniTableField* f, size_t size,
upb_Arena* arena);

@ -179,8 +179,8 @@ TEST(GeneratedCode, ScalarsProto2) {
0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg));
EXPECT_EQ(0, upb_Message_GetInt32(UPB_UPCAST(msg), optional_int32_field, 0));
upb_Message_SetInt32(UPB_UPCAST(msg), optional_int32_field, kTestInt32,
nullptr);
upb_Message_SetBaseFieldInt32(UPB_UPCAST(msg), optional_int32_field,
kTestInt32);
EXPECT_EQ(true,
upb_Message_HasBaseField(UPB_UPCAST(msg), optional_int32_field));
EXPECT_EQ(kTestInt32,
@ -196,8 +196,8 @@ TEST(GeneratedCode, ScalarsProto2) {
0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg));
EXPECT_EQ(0,
upb_Message_GetUInt32(UPB_UPCAST(msg), optional_uint32_field, 0));
upb_Message_SetUInt32(UPB_UPCAST(msg), optional_uint32_field, kTestUInt32,
nullptr);
upb_Message_SetBaseFieldUInt32(UPB_UPCAST(msg), optional_uint32_field,
kTestUInt32);
EXPECT_EQ(kTestUInt32,
upb_Message_GetUInt32(UPB_UPCAST(msg), optional_uint32_field, 0));
EXPECT_EQ(
@ -219,15 +219,15 @@ TEST(GeneratedCode, ScalarProto3) {
EXPECT_EQ(
0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64(msg));
upb_Message_SetInt64(UPB_UPCAST(msg), optional_int64_field, -1, nullptr);
upb_Message_SetBaseFieldInt64(UPB_UPCAST(msg), optional_int64_field, -1);
EXPECT_EQ(
-1, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64(msg));
EXPECT_EQ(-1, upb_Message_GetInt64(UPB_UPCAST(msg), optional_int64_field, 0));
EXPECT_EQ(
0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg));
upb_Message_SetUInt64(UPB_UPCAST(msg), optional_uint64_field, kTestUInt64,
nullptr);
upb_Message_SetBaseFieldUInt64(UPB_UPCAST(msg), optional_uint64_field,
kTestUInt64);
EXPECT_EQ(
kTestUInt64,
protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg));
@ -265,8 +265,8 @@ TEST(GeneratedCode, Strings) {
false,
protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string(
msg));
upb_Message_SetString(UPB_UPCAST(msg), optional_string_field,
upb_StringView_FromString(kTestStr2), nullptr);
upb_Message_SetBaseFieldString(UPB_UPCAST(msg), optional_string_field,
upb_StringView_FromString(kTestStr2));
EXPECT_EQ(true,
upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field));
EXPECT_EQ(
@ -327,8 +327,8 @@ TEST(GeneratedCode, SubMessage) {
upb_Message* new_nested_message = UPB_UPCAST(
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new(
arena));
upb_Message_SetInt32(new_nested_message, nested_message_a_field, 123,
nullptr);
upb_Message_SetBaseFieldInt32(new_nested_message, nested_message_a_field,
123);
upb_Message_SetMessage(UPB_UPCAST(msg), optional_message_field,
new_nested_message);

@ -657,13 +657,14 @@ UPB_API_INLINE void upb_Message_SetBaseFieldUInt64(struct upb_Message* msg,
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetClosedEnum(
struct upb_Message* msg, const upb_MiniTable* msg_mini_table,
const upb_MiniTableField* f, int32_t value) {
UPB_API_INLINE void upb_Message_SetClosedEnum(struct upb_Message* msg,
const upb_MiniTable* m,
const upb_MiniTableField* f,
int32_t value) {
UPB_ASSERT(upb_MiniTableField_IsClosedEnum(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSERT(upb_MiniTableEnum_CheckValue(
upb_MiniTable_GetSubEnumTable(msg_mini_table, f), value));
UPB_ASSERT(
upb_MiniTableEnum_CheckValue(upb_MiniTable_GetSubEnumTable(m, f), value));
upb_Message_SetBaseField(msg, f, &value);
}

Loading…
Cancel
Save