Fixed oneof case accessor to cast to enum for C++.

pull/13171/head
Joshua Haberman 6 years ago
parent cf35baa1ad
commit 151ebc8a29
  1. 1
      BUILD
  2. 5
      tests/json/test.proto
  3. BIN
      tests/json/test.proto.pb
  4. 1
      tests/json/test_json.cc
  5. 2
      upbc/generator.cc

@ -326,6 +326,7 @@ cc_test(
],
deps = [
":test_json_upbprotoreflection",
":test_json_upbproto",
":upb_json",
":upb_test",
],

@ -29,6 +29,11 @@ message TestMessage {
map<string, int32> map_string_int32 = 23;
map<string, bool> map_string_bool = 24;
map<string, SubMessage> map_string_msg = 25;
oneof o {
int32 oneof_int32 = 26;
int64 oneof_int64 = 27;
}
}
message SubMessage {

Binary file not shown.

@ -4,6 +4,7 @@
*/
#include "tests/json/test.upbdefs.h"
#include "tests/json/test.upb.h" // Test that it compiles for C++.
#include "tests/test_util.h"
#include "tests/upb_test.h"
#include "upb/handlers.h"

@ -362,7 +362,7 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output
fullname);
output(
"UPB_INLINE $0_oneofcases $1_$2_case(const $1* msg) { "
"return UPB_FIELD_AT(msg, int, $3); }\n"
"return ($0_oneofcases)UPB_FIELD_AT(msg, int32_t, $3); }\n"
"\n",
fullname, msgname, oneof->name(),
GetSizeInit(layout.GetOneofCaseOffset(oneof)));

Loading…
Cancel
Save