diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2017-05-29 22:04:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-29 22:04:20 -0700 |
commit | 1e86ef4e9f0b9c9e8bd8d62a61e141f139366920 (patch) | |
tree | 9f71f15fab7555ea8cf4ec943165f4b1a19318f9 /php/ext/google | |
parent | 282fb9e68ec101b7b7616a45279427944afc3e6b (diff) | |
download | protobuf-1e86ef4e9f0b9c9e8bd8d62a61e141f139366920.tar.gz protobuf-1e86ef4e9f0b9c9e8bd8d62a61e141f139366920.tar.bz2 protobuf-1e86ef4e9f0b9c9e8bd8d62a61e141f139366920.zip |
Oneof field should be serialized even it's equal to default. (#3153)
Diffstat (limited to 'php/ext/google')
-rw-r--r-- | php/ext/google/protobuf/encode_decode.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index 28bf18f4..6e3c606b 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -1167,6 +1167,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc, upb_msg_field_next(&i)) { upb_fielddef* f = upb_msg_iter_field(&i); uint32_t offset = desc->layout->fields[upb_fielddef_index(f)].offset; + bool containing_oneof = false; if (upb_fielddef_containingoneof(f)) { uint32_t oneof_case_offset = @@ -1179,6 +1180,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc, } // Otherwise, fall through to the appropriate singular-field handler // below. + containing_oneof = true; } if (is_map_field(f)) { @@ -1209,7 +1211,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc, #define T(upbtypeconst, upbtype, ctype, default_value) \ case upbtypeconst: { \ ctype value = DEREF(message_data(msg), offset, ctype); \ - if (value != default_value) { \ + if (containing_oneof || value != default_value) { \ upb_sink_put##upbtype(sink, sel, value); \ } \ } break; |