Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(16000)

Issue 157169: Fix for Protobuf issue 136: memoized serialized size of packed fields was invalid

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 4 months ago by jasonh
Modified:
14 years, 4 months ago
Reviewers:
kenton
CC:
protobuf_googlegroups.com
Base URL:
http://protobuf.googlecode.com/svn/trunk/
Visibility:
Public.

Description

Fix Issue 136: the memoized serialized size for packed fields may not be properly set. writeTo() may be invoked without a call to getSerializedSize(), so the generated serialization methods would write a length of 0 for non-empty packed fields. Just call getSerializedSize() at the beginning of writeTo(): although this means that we may compute the byte size needlessly when there are no packed fields, in practice, getSerializedSize() will already have been called - all of the writeTo() wrappers in AbstractMessageLite invoke it. Tested: new unittest case in WireFormatTest.java now passes

Patch Set 1 #

Patch Set 2 : Remove FileOutputStream import #

Patch Set 3 : Send review mail #

Patch Set 4 : Initialize the memoized size of packed fields to -1 instead of 0 #

Patch Set 5 : May as well generate less code and just call getSerializedSize() once at the beginning of writeTo() #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+31 lines, -1 line) Patch
M java/src/test/java/com/google/protobuf/WireFormatTest.java View 1 2 3 4 1 chunk +22 lines, -0 lines 0 comments Download
M src/google/protobuf/compiler/java/java_message.cc View 1 chunk +8 lines, -0 lines 1 comment Download
M src/google/protobuf/compiler/java/java_primitive_field.cc View 1 2 3 4 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 7
jasonh
14 years, 4 months ago (2009-11-25 03:04:10 UTC) #1
kenton
I guess it's technically the case that a packed field always has non-zero size, but ...
14 years, 4 months ago (2009-11-25 03:41:18 UTC) #2
kenton
On Tue, Nov 24, 2009 at 7:40 PM, Kenton Varda <kenton@google.com> wrote: > I guess ...
14 years, 4 months ago (2009-11-25 03:42:18 UTC) #3
jasonh
Done. But it occurs to me that this isn't all that much nicer a solution ...
14 years, 4 months ago (2009-11-25 17:08:37 UTC) #4
kenton
You're right, we might as well always call it. On Wed, Nov 25, 2009 at ...
14 years, 4 months ago (2009-11-25 20:51:52 UTC) #5
jasonh
Done. I kept the change to initialize the memoized size of packed fields to -1, ...
14 years, 4 months ago (2009-11-25 23:24:30 UTC) #6
kenton
14 years, 4 months ago (2009-11-25 23:54:47 UTC) #7
LGTM, just a minor nitpick:

http://codereview.appspot.com/157169/diff/2007/1012
File src/google/protobuf/compiler/java/java_message.cc (right):

http://codereview.appspot.com/157169/diff/2007/1012#newcode404
src/google/protobuf/compiler/java/java_message.cc:404: "getSerializedSize();");
Missing \n.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b