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
eab9b5d4
Commit
eab9b5d4
authored
Feb 18, 2011
by
jasonh@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue 256: compute the correct size for negative enum values, which need to be sign extended.
parent
17d57dbb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
1 deletion
+16
-1
CodedOutputStream.java
.../src/main/java/com/google/protobuf/CodedOutputStream.java
+1
-1
CodedOutputStreamTest.java
.../test/java/com/google/protobuf/CodedOutputStreamTest.java
+15
-0
No files found.
java/src/main/java/com/google/protobuf/CodedOutputStream.java
View file @
eab9b5d4
...
...
@@ -751,7 +751,7 @@ public final class CodedOutputStream {
* Caller is responsible for converting the enum value to its numeric value.
*/
public
static
int
computeEnumSizeNoTag
(
final
int
value
)
{
return
compute
RawVarint32Size
(
value
);
return
compute
Int32SizeNoTag
(
value
);
}
/**
...
...
java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java
View file @
eab9b5d4
...
...
@@ -300,4 +300,19 @@ public class CodedOutputStreamTest extends TestCase {
assertEqualBytes
(
TestUtil
.
getGoldenPackedFieldsMessage
().
toByteArray
(),
rawBytes
);
}
/** Test writing a message containing a negative enum value. This used to
* fail because the size was not properly computed as a sign-extended varint. */
public
void
testWriteMessageWithNegativeEnumValue
()
throws
Exception
{
protobuf_unittest
.
UnittestProto
.
SparseEnumMessage
message
=
protobuf_unittest
.
UnittestProto
.
SparseEnumMessage
.
newBuilder
()
.
setSparseEnum
(
protobuf_unittest
.
UnittestProto
.
TestSparseEnum
.
SPARSE_E
)
.
build
();
assertTrue
(
message
.
getSparseEnum
().
getNumber
()
<
0
);
byte
[]
rawBytes
=
message
.
toByteArray
();
protobuf_unittest
.
UnittestProto
.
SparseEnumMessage
message2
=
protobuf_unittest
.
UnittestProto
.
SparseEnumMessage
.
parseFrom
(
rawBytes
);
assertEquals
(
protobuf_unittest
.
UnittestProto
.
TestSparseEnum
.
SPARSE_E
,
message2
.
getSparseEnum
());
}
}
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