update some more functions to match the accessor naming convention

upb_MiniTable_SetEnumProto2() -> upb_Message_SetEnumProto2()
upb_MiniTable_GetMessage() -> upb_Message_GetMessage()
upb_MiniTable_SetMessage() -> upb_Message_SetMessage()
upb_MiniTable_GetMutableMessage() -> upb_Message_GetOrCreateMutableMessage()

PiperOrigin-RevId: 500781434
pull/13171/head
Eric Salo 2 years ago committed by Copybara-Service
parent b5384af913
commit 87f9b868b8
  1. 4
      upb/message/accessors.c
  2. 16
      upb/message/accessors.h
  3. 14
      upb/message/accessors_test.cc

@ -195,7 +195,7 @@ upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
// Callers should check that message is not set first before calling // Callers should check that message is not set first before calling
// PromotoUnknownToMessage. // PromotoUnknownToMessage.
UPB_ASSERT(mini_table->subs[field->submsg_index].submsg == sub_mini_table); UPB_ASSERT(mini_table->subs[field->submsg_index].submsg == sub_mini_table);
UPB_ASSERT(upb_MiniTable_GetMessage(msg, field, NULL) == NULL); UPB_ASSERT(upb_Message_GetMessage(msg, field, NULL) == NULL);
upb_UnknownToMessageRet ret; upb_UnknownToMessageRet ret;
ret.status = kUpb_UnknownToMessage_Ok; ret.status = kUpb_UnknownToMessage_Ok;
do { do {
@ -223,7 +223,7 @@ upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
} }
} while (unknown.status == kUpb_FindUnknown_Ok); } while (unknown.status == kUpb_FindUnknown_Ok);
if (message) { if (message) {
upb_MiniTable_SetMessage(msg, mini_table, field, message); upb_Message_SetMessage(msg, mini_table, field, message);
ret.message = message; ret.message = message;
} }
return ret; return ret;

@ -405,7 +405,7 @@ UPB_API_INLINE bool upb_Message_SetUInt32(upb_Message* msg,
return _upb_Message_SetField(msg, field, &value, a); return _upb_Message_SetField(msg, field, &value, a);
} }
UPB_API_INLINE void upb_MiniTable_SetEnumProto2( UPB_API_INLINE void upb_Message_SetEnumProto2(
upb_Message* msg, const upb_MiniTable* msg_mini_table, upb_Message* msg, const upb_MiniTable* msg_mini_table,
const upb_MiniTableField* field, int32_t value) { const upb_MiniTableField* field, int32_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Enum); UPB_ASSERT(field->descriptortype == kUpb_FieldType_Enum);
@ -524,7 +524,7 @@ UPB_API_INLINE bool upb_Message_SetString(upb_Message* msg,
return _upb_Message_SetField(msg, field, &value, a); return _upb_Message_SetField(msg, field, &value, a);
} }
UPB_API_INLINE const upb_Message* upb_MiniTable_GetMessage( UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
const upb_Message* msg, const upb_MiniTableField* field, const upb_Message* msg, const upb_MiniTableField* field,
upb_Message* default_val) { upb_Message* default_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message || UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message ||
@ -537,10 +537,10 @@ UPB_API_INLINE const upb_Message* upb_MiniTable_GetMessage(
return ret; return ret;
} }
UPB_API_INLINE void upb_MiniTable_SetMessage(upb_Message* msg, UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
const upb_MiniTable* mini_table, const upb_MiniTable* mini_table,
const upb_MiniTableField* field, const upb_MiniTableField* field,
upb_Message* sub_message) { upb_Message* sub_message) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message || UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message ||
field->descriptortype == kUpb_FieldType_Group); field->descriptortype == kUpb_FieldType_Group);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_IsRepeatedOrMap(field));
@ -550,7 +550,7 @@ UPB_API_INLINE void upb_MiniTable_SetMessage(upb_Message* msg,
_upb_Message_SetNonExtensionField(msg, field, &sub_message); _upb_Message_SetNonExtensionField(msg, field, &sub_message);
} }
UPB_API_INLINE upb_Message* upb_MiniTable_GetMutableMessage( UPB_API_INLINE upb_Message* upb_Message_GetOrCreateMutableMessage(
upb_Message* msg, const upb_MiniTable* mini_table, upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTableField* field, upb_Arena* arena) { const upb_MiniTableField* field, upb_Arena* arena) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message || UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message ||
@ -719,7 +719,7 @@ typedef struct {
// Promotes unknown data inside message to a upb_Message parsing the unknown. // Promotes unknown data inside message to a upb_Message parsing the unknown.
// //
// The unknown data is removed from message after field value is set // The unknown data is removed from message after field value is set
// using upb_MiniTable_SetMessage. // using upb_Message_SetMessage.
upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage( upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
upb_Message* msg, const upb_MiniTable* mini_table, upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTableField* field, const upb_MiniTable* sub_mini_table, const upb_MiniTableField* field, const upb_MiniTable* sub_mini_table,

@ -261,7 +261,7 @@ TEST(GeneratedCode, SubMessage) {
find_proto2_field(kFieldOptionalNestedMessage); find_proto2_field(kFieldOptionalNestedMessage);
const upb_Message* test_message = const upb_Message* test_message =
upb_MiniTable_GetMessage(msg, optional_message_field, NULL); upb_Message_GetMessage(msg, optional_message_field, NULL);
EXPECT_EQ(NULL, test_message); EXPECT_EQ(NULL, test_message);
EXPECT_EQ(false, upb_Message_HasField(msg, optional_message_field)); EXPECT_EQ(false, upb_Message_HasField(msg, optional_message_field));
@ -277,7 +277,7 @@ TEST(GeneratedCode, SubMessage) {
// Read back using mini table API. // Read back using mini table API.
const upb_Message* sub_message = const upb_Message* sub_message =
upb_MiniTable_GetMessage(msg, optional_message_field, NULL); upb_Message_GetMessage(msg, optional_message_field, NULL);
EXPECT_EQ(true, sub_message != NULL); EXPECT_EQ(true, sub_message != NULL);
const upb_MiniTableField* nested_message_a_field = const upb_MiniTableField* nested_message_a_field =
@ -296,11 +296,11 @@ TEST(GeneratedCode, SubMessage) {
upb_Message* new_nested_message = upb_Message* new_nested_message =
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new(arena); protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new(arena);
upb_Message_SetInt32(new_nested_message, nested_message_a_field, 123, NULL); upb_Message_SetInt32(new_nested_message, nested_message_a_field, 123, NULL);
upb_MiniTable_SetMessage( upb_Message_SetMessage(
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init, msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
optional_message_field, new_nested_message); optional_message_field, new_nested_message);
upb_Message* mutable_message = upb_MiniTable_GetMutableMessage( upb_Message* mutable_message = upb_Message_GetOrCreateMutableMessage(
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init, msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
optional_message_field, arena); optional_message_field, arena);
EXPECT_EQ( EXPECT_EQ(
@ -373,10 +373,10 @@ TEST(GeneratedCode, GetMutableMessage) {
// Message. // Message.
const upb_MiniTableField* optional_message_field = const upb_MiniTableField* optional_message_field =
find_proto2_field(kFieldOptionalNestedMessage); find_proto2_field(kFieldOptionalNestedMessage);
upb_Message* msg1 = upb_MiniTable_GetMutableMessage( upb_Message* msg1 = upb_Message_GetOrCreateMutableMessage(
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init, msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
optional_message_field, arena); optional_message_field, arena);
upb_Message* msg2 = upb_MiniTable_GetMutableMessage( upb_Message* msg2 = upb_Message_GetOrCreateMutableMessage(
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init, msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
optional_message_field, arena); optional_message_field, arena);
// Verify that newly constructed sub message is stored in msg. // Verify that newly constructed sub message is stored in msg.
@ -653,7 +653,7 @@ TEST(GeneratedCode, PromoteUnknownMessage) {
&upb_test_ModelWithExtensions_msg_init, decode_options, arena); &upb_test_ModelWithExtensions_msg_init, decode_options, arena);
EXPECT_EQ(promote_result.status, kUpb_UnknownToMessage_Ok); EXPECT_EQ(promote_result.status, kUpb_UnknownToMessage_Ok);
const upb_Message* promoted_message = const upb_Message* promoted_message =
upb_MiniTable_GetMessage(msg, &mini_table->fields[1], NULL); upb_Message_GetMessage(msg, &mini_table->fields[1], NULL);
EXPECT_EQ(upb_test_ModelWithExtensions_random_int32( EXPECT_EQ(upb_test_ModelWithExtensions_random_int32(
(upb_test_ModelWithExtensions*)promoted_message), (upb_test_ModelWithExtensions*)promoted_message),
12); 12);

Loading…
Cancel
Save