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
1b1735ce
Commit
1b1735ce
authored
Jan 10, 2014
by
Max Cai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't serialize required fields whose 'has' flags are unset.
Change-Id: Ibbe944fff83e44a8f2206e18ee9ec6f10661297a
parent
0c0f8c7e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
6 deletions
+15
-6
NanoTest.java
java/src/test/java/com/google/protobuf/NanoTest.java
+6
-1
javanano_enum_field.cc
src/google/protobuf/compiler/javanano/javanano_enum_field.cc
+3
-2
javanano_primitive_field.cc
...le/protobuf/compiler/javanano/javanano_primitive_field.cc
+4
-3
unittest_has_nano.proto
src/google/protobuf/unittest_has_nano.proto
+2
-0
No files found.
java/src/test/java/com/google/protobuf/NanoTest.java
View file @
1b1735ce
...
...
@@ -2202,6 +2202,7 @@ public class NanoTest extends TestCase {
assertFalse
(
msg
.
hasDefaultFloatNan
);
assertFalse
(
msg
.
hasDefaultNestedEnum
);
assertFalse
(
msg
.
hasId
);
assertFalse
(
msg
.
hasRequiredEnum
);
msg
.
optionalInt32
=
123
;
msg
.
optionalNestedMessage
=
new
TestAllTypesNanoHas
.
NestedMessage
();
msg
.
optionalNestedMessage
.
bb
=
2
;
...
...
@@ -2211,7 +2212,7 @@ public class NanoTest extends TestCase {
byte
[]
result
=
MessageNano
.
toByteArray
(
msg
);
int
msgSerializedSize
=
msg
.
getSerializedSize
();
//System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
assertTrue
(
msgSerializedSize
==
1
3
);
assertTrue
(
msgSerializedSize
==
1
0
);
assertEquals
(
result
.
length
,
msgSerializedSize
);
// Has fields true upon parse.
...
...
@@ -2237,6 +2238,8 @@ public class NanoTest extends TestCase {
msg
.
hasDefaultBytes
=
true
;
msg
.
hasDefaultFloatNan
=
true
;
msg
.
hasDefaultNestedEnum
=
true
;
msg
.
hasId
=
true
;
msg
.
hasRequiredEnum
=
true
;
byte
[]
result
=
MessageNano
.
toByteArray
(
msg
);
int
msgSerializedSize
=
msg
.
getSerializedSize
();
...
...
@@ -2255,6 +2258,7 @@ public class NanoTest extends TestCase {
assertTrue
(
newMsg
.
hasDefaultFloatNan
);
assertTrue
(
newMsg
.
hasDefaultNestedEnum
);
assertTrue
(
newMsg
.
hasId
);
assertTrue
(
newMsg
.
hasRequiredEnum
);
assertEquals
(
0
,
newMsg
.
optionalInt32
);
assertEquals
(
0
,
newMsg
.
optionalString
.
length
());
assertEquals
(
0
,
newMsg
.
optionalBytes
.
length
);
...
...
@@ -2266,6 +2270,7 @@ public class NanoTest extends TestCase {
assertEquals
(
TestAllTypesNanoHas
.
BAR
,
newMsg
.
defaultNestedEnum
);
assertEquals
(
Float
.
NaN
,
newMsg
.
defaultFloatNan
);
assertEquals
(
0
,
newMsg
.
id
);
assertEquals
(
TestAllTypesNanoHas
.
FOO
,
newMsg
.
requiredEnum
);
}
public
void
testNanoWithAccessorsBasic
()
throws
Exception
{
...
...
src/google/protobuf/compiler/javanano/javanano_enum_field.cc
View file @
1b1735ce
...
...
@@ -121,7 +121,8 @@ GenerateMergingCode(io::Printer* printer) const {
void
EnumFieldGenerator
::
GenerateSerializationCode
(
io
::
Printer
*
printer
)
const
{
if
(
descriptor_
->
is_required
())
{
if
(
descriptor_
->
is_required
()
&&
!
params_
.
generate_has
())
{
// Always serialize a required field if we don't have the 'has' signal.
printer
->
Print
(
variables_
,
"output.writeInt32($number$, this.$name$);
\n
"
);
}
else
{
...
...
@@ -140,7 +141,7 @@ GenerateSerializationCode(io::Printer* printer) const {
void
EnumFieldGenerator
::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
const
{
if
(
descriptor_
->
is_required
())
{
if
(
descriptor_
->
is_required
()
&&
!
params_
.
generate_has
()
)
{
printer
->
Print
(
variables_
,
"size += com.google.protobuf.nano.CodedOutputByteBufferNano
\n
"
" .computeInt32Size($number$, this.$name$);
\n
"
);
...
...
src/google/protobuf/compiler/javanano/javanano_primitive_field.cc
View file @
1b1735ce
...
...
@@ -342,7 +342,7 @@ GenerateMembers(io::Printer* printer, bool lazy_init) const {
if
(
params_
.
generate_has
())
{
printer
->
Print
(
variables_
,
"public boolean has$capitalized_name$
= false
;
\n
"
);
"public boolean has$capitalized_name$;
\n
"
);
}
}
...
...
@@ -401,7 +401,8 @@ GenerateSerializationConditional(io::Printer* printer) const {
void
PrimitiveFieldGenerator
::
GenerateSerializationCode
(
io
::
Printer
*
printer
)
const
{
if
(
descriptor_
->
is_required
())
{
if
(
descriptor_
->
is_required
()
&&
!
params_
.
generate_has
())
{
// Always serialize a required field if we don't have the 'has' signal.
printer
->
Print
(
variables_
,
"output.write$capitalized_type$($number$, this.$name$);
\n
"
);
}
else
{
...
...
@@ -414,7 +415,7 @@ GenerateSerializationCode(io::Printer* printer) const {
void
PrimitiveFieldGenerator
::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
const
{
if
(
descriptor_
->
is_required
())
{
if
(
descriptor_
->
is_required
()
&&
!
params_
.
generate_has
()
)
{
printer
->
Print
(
variables_
,
"size += com.google.protobuf.nano.CodedOutputByteBufferNano
\n
"
" .compute$capitalized_type$Size($number$, this.$name$);
\n
"
);
...
...
src/google/protobuf/unittest_has_nano.proto
View file @
1b1735ce
...
...
@@ -75,4 +75,6 @@ message TestAllTypesNanoHas {
optional
NestedEnum
default_nested_enum
=
81
[
default
=
BAR
];
required
int32
id
=
86
;
required
NestedEnum
required_enum
=
87
;
}
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