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
e7336cdd
Commit
e7336cdd
authored
Oct 04, 2013
by
Ulas Kirazci
Committed by
Gerrit Code Review
Oct 04, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge "Fix roundtrip failure with groups when unknown fields are enabled."
parents
4b7983cb
b3c24e0e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
2 deletions
+30
-2
WireFormatNano.java
...rc/main/java/com/google/protobuf/nano/WireFormatNano.java
+7
-2
NanoTest.java
java/src/test/java/com/google/protobuf/NanoTest.java
+17
-0
unittest_extension_nano.proto
src/google/protobuf/unittest_extension_nano.proto
+6
-0
No files found.
java/src/main/java/com/google/protobuf/nano/WireFormatNano.java
View file @
e7336cdd
...
...
@@ -119,6 +119,9 @@ public final class WireFormatNano {
* <p>Generated messages will call this for unknown fields if the store_unknown_fields
* option is on.
*
* <p>Note that the tag might be a end-group tag (rather than the start of an unknown field) in
* which case we do not want to add an unknown field entry.
*
* @param data a Collection in which to store the data.
* @param input the input buffer.
* @param tag the tag of the field.
...
...
@@ -130,11 +133,13 @@ public final class WireFormatNano {
final
CodedInputByteBufferNano
input
,
final
int
tag
)
throws
IOException
{
int
startPos
=
input
.
getPosition
();
boolean
skip
=
input
.
skipField
(
tag
);
if
(!
input
.
skipField
(
tag
))
{
return
false
;
// This wasn't an unknown field, it's an end-group tag.
}
int
endPos
=
input
.
getPosition
();
byte
[]
bytes
=
input
.
getData
(
startPos
,
endPos
-
startPos
);
data
.
add
(
new
UnknownFieldData
(
tag
,
bytes
));
return
skip
;
return
true
;
}
/**
...
...
java/src/test/java/com/google/protobuf/NanoTest.java
View file @
e7336cdd
...
...
@@ -35,6 +35,7 @@ import com.google.protobuf.nano.EnumClassNanoMultiple;
import
com.google.protobuf.nano.EnumClassNanos
;
import
com.google.protobuf.nano.Extensions
;
import
com.google.protobuf.nano.Extensions.AnotherMessage
;
import
com.google.protobuf.nano.Extensions.MessageWithGroup
;
import
com.google.protobuf.nano.FileScopeEnumMultiple
;
import
com.google.protobuf.nano.FileScopeEnumRefNano
;
import
com.google.protobuf.nano.InternalNano
;
...
...
@@ -505,6 +506,22 @@ public class NanoTest extends TestCase {
assertEquals
(
1
,
newMsg
.
optionalGroup
.
a
);
}
public
void
testNanoOptionalGroupWithUnknownFieldsEnabled
()
throws
Exception
{
MessageWithGroup
msg
=
new
MessageWithGroup
();
MessageWithGroup
.
Group
grp
=
new
MessageWithGroup
.
Group
();
grp
.
a
=
1
;
msg
.
group
=
grp
;
byte
[]
serialized
=
MessageNano
.
toByteArray
(
msg
);
MessageWithGroup
parsed
=
MessageWithGroup
.
parseFrom
(
serialized
);
assertTrue
(
msg
.
group
!=
null
);
assertEquals
(
1
,
msg
.
group
.
a
);
byte
[]
serialized2
=
MessageNano
.
toByteArray
(
parsed
);
assertEquals
(
serialized2
.
length
,
serialized
.
length
);
MessageWithGroup
parsed2
=
MessageWithGroup
.
parseFrom
(
serialized2
);
}
public
void
testNanoOptionalNestedMessage
()
throws
Exception
{
TestAllTypesNano
msg
=
new
TestAllTypesNano
();
TestAllTypesNano
.
NestedMessage
nestedMsg
=
new
TestAllTypesNano
.
NestedMessage
();
...
...
src/google/protobuf/unittest_extension_nano.proto
View file @
e7336cdd
...
...
@@ -42,3 +42,9 @@ message ContainerMessage {
optional
bool
another_thing
=
100
;
}
}
message
MessageWithGroup
{
optional
group
Group
=
1
{
optional
int32
a
=
2
;
}
}
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