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
f5691a61
Commit
f5691a61
authored
Oct 02, 2014
by
Feng Xiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix descriptor validation logic for packed enum fields.
parent
61477681
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
7 deletions
+34
-7
Descriptors.java
java/src/main/java/com/google/protobuf/Descriptors.java
+7
-7
DescriptorsTest.java
java/src/test/java/com/google/protobuf/DescriptorsTest.java
+27
-0
No files found.
java/src/main/java/com/google/protobuf/Descriptors.java
View file @
f5691a61
...
...
@@ -1103,13 +1103,6 @@ public final class Descriptors {
"Field numbers must be positive integers."
);
}
// Only repeated primitive fields may be packed.
if
(
proto
.
getOptions
().
getPacked
()
&&
!
isPackable
())
{
throw
new
DescriptorValidationException
(
this
,
"[packed = true] can only be specified for repeated primitive "
+
"fields."
);
}
if
(
isExtension
)
{
if
(!
proto
.
hasExtendee
())
{
throw
new
DescriptorValidationException
(
this
,
...
...
@@ -1218,6 +1211,13 @@ public final class Descriptors {
}
}
// Only repeated primitive fields may be packed.
if
(
proto
.
getOptions
().
getPacked
()
&&
!
isPackable
())
{
throw
new
DescriptorValidationException
(
this
,
"[packed = true] can only be specified for repeated primitive "
+
"fields."
);
}
// We don't attempt to parse the default value until here because for
// enums we need the enum type's descriptor.
if
(
proto
.
hasDefaultValue
())
{
...
...
java/src/test/java/com/google/protobuf/DescriptorsTest.java
View file @
f5691a61
...
...
@@ -705,4 +705,31 @@ public class DescriptorsTest extends TestCase {
assertFalse
(
TestMultipleExtensionRanges
.
getDescriptor
().
isExtensionNumber
(
4142
));
assertTrue
(
TestMultipleExtensionRanges
.
getDescriptor
().
isExtensionNumber
(
4143
));
}
public
void
testPackedEnumField
()
throws
Exception
{
FileDescriptorProto
fileDescriptorProto
=
FileDescriptorProto
.
newBuilder
()
.
setName
(
"foo.proto"
)
.
addEnumType
(
EnumDescriptorProto
.
newBuilder
()
.
setName
(
"Enum"
)
.
addValue
(
EnumValueDescriptorProto
.
newBuilder
()
.
setName
(
"FOO"
)
.
setNumber
(
1
)
.
build
())
.
build
())
.
addMessageType
(
DescriptorProto
.
newBuilder
()
.
setName
(
"Message"
)
.
addField
(
FieldDescriptorProto
.
newBuilder
()
.
setName
(
"foo"
)
.
setTypeName
(
"Enum"
)
.
setNumber
(
1
)
.
setLabel
(
FieldDescriptorProto
.
Label
.
LABEL_REPEATED
)
.
setOptions
(
DescriptorProtos
.
FieldOptions
.
newBuilder
()
.
setPacked
(
true
)
.
build
())
.
build
())
.
build
())
.
build
();
Descriptors
.
FileDescriptor
.
buildFrom
(
fileDescriptorProto
,
new
FileDescriptor
[
0
]);
}
}
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