Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
c344fe8c
Commit
c344fe8c
authored
May 30, 2017
by
Paul Yang
Committed by
Bo Yang
Jun 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Oneof field should be serialized even it's equal to default. (#3153)
parent
dba8928f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
1 deletion
+17
-1
encode_decode.c
php/ext/google/protobuf/encode_decode.c
+3
-1
Message.php
php/src/Google/Protobuf/Internal/Message.php
+7
-0
encode_decode_test.php
php/tests/encode_decode_test.php
+7
-0
No files found.
php/ext/google/protobuf/encode_decode.c
View file @
c344fe8c
...
@@ -1167,6 +1167,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
...
@@ -1167,6 +1167,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
upb_msg_field_next
(
&
i
))
{
upb_msg_field_next
(
&
i
))
{
upb_fielddef
*
f
=
upb_msg_iter_field
(
&
i
);
upb_fielddef
*
f
=
upb_msg_iter_field
(
&
i
);
uint32_t
offset
=
desc
->
layout
->
fields
[
upb_fielddef_index
(
f
)].
offset
;
uint32_t
offset
=
desc
->
layout
->
fields
[
upb_fielddef_index
(
f
)].
offset
;
bool
containing_oneof
=
false
;
if
(
upb_fielddef_containingoneof
(
f
))
{
if
(
upb_fielddef_containingoneof
(
f
))
{
uint32_t
oneof_case_offset
=
uint32_t
oneof_case_offset
=
...
@@ -1179,6 +1180,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
...
@@ -1179,6 +1180,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
}
}
// Otherwise, fall through to the appropriate singular-field handler
// Otherwise, fall through to the appropriate singular-field handler
// below.
// below.
containing_oneof
=
true
;
}
}
if
(
is_map_field
(
f
))
{
if
(
is_map_field
(
f
))
{
...
@@ -1209,7 +1211,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
...
@@ -1209,7 +1211,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
#define T(upbtypeconst, upbtype, ctype, default_value) \
#define T(upbtypeconst, upbtype, ctype, default_value) \
case upbtypeconst: { \
case upbtypeconst: { \
ctype value = DEREF(message_data(msg), offset, ctype); \
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); \
upb_sink_put##upbtype(sink, sel, value); \
} \
} \
} break;
} break;
...
...
php/src/Google/Protobuf/Internal/Message.php
View file @
c344fe8c
...
@@ -739,6 +739,13 @@ class Message
...
@@ -739,6 +739,13 @@ class Message
*/
*/
private
function
existField
(
$field
)
private
function
existField
(
$field
)
{
{
$oneof_index
=
$field
->
getOneofIndex
();
if
(
$oneof_index
!==
-
1
)
{
$oneof
=
$this
->
desc
->
getOneofDecl
()[
$oneof_index
];
$oneof_name
=
$oneof
->
getName
();
return
$this
->
$oneof_name
->
getNumber
()
===
$field
->
getNumber
();
}
$getter
=
$field
->
getGetter
();
$getter
=
$field
->
getGetter
();
$value
=
$this
->
$getter
();
$value
=
$this
->
$getter
();
return
$value
!==
$this
->
defaultValue
(
$field
);
return
$value
!==
$this
->
defaultValue
(
$field
);
...
...
php/tests/encode_decode_test.php
View file @
c344fe8c
...
@@ -88,6 +88,13 @@ class EncodeDecodeTest extends TestBase
...
@@ -88,6 +88,13 @@ class EncodeDecodeTest extends TestBase
$n
=
new
TestMessage
();
$n
=
new
TestMessage
();
$n
->
mergeFromString
(
$data
);
$n
->
mergeFromString
(
$data
);
$this
->
assertSame
(
1
,
$n
->
getOneofMessage
()
->
getA
());
$this
->
assertSame
(
1
,
$n
->
getOneofMessage
()
->
getA
());
// Encode default value
$m
->
setOneofEnum
(
TestEnum
::
ZERO
);
$data
=
$m
->
serializeToString
();
$n
=
new
TestMessage
();
$n
->
mergeFromString
(
$data
);
$this
->
assertSame
(
"oneof_enum"
,
$n
->
getMyOneof
());
}
}
public
function
testPackedEncode
()
public
function
testPackedEncode
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment