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
cebd784d
Commit
cebd784d
authored
Jul 31, 2013
by
Ulas Kirazci
Committed by
Gerrit Code Review
Jul 31, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge "Fixed packed repeated serialization."
parents
064b60c6
1c277f9c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
28 deletions
+46
-28
NanoTest.java
java/src/test/java/com/google/protobuf/NanoTest.java
+19
-0
javanano_primitive_field.cc
...le/protobuf/compiler/javanano/javanano_primitive_field.cc
+25
-28
javanano_primitive_field.h
...gle/protobuf/compiler/javanano/javanano_primitive_field.h
+2
-0
No files found.
java/src/test/java/com/google/protobuf/NanoTest.java
View file @
cebd784d
...
@@ -47,6 +47,7 @@ import com.google.protobuf.nano.UnittestImportNano;
...
@@ -47,6 +47,7 @@ import com.google.protobuf.nano.UnittestImportNano;
import
junit.framework.TestCase
;
import
junit.framework.TestCase
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -1956,6 +1957,24 @@ public class NanoTest extends TestCase {
...
@@ -1956,6 +1957,24 @@ public class NanoTest extends TestCase {
assertEquals
(
TestAllTypesNano
.
BAR
,
msg
.
repeatedPackedNestedEnum
[
1
]);
assertEquals
(
TestAllTypesNano
.
BAR
,
msg
.
repeatedPackedNestedEnum
[
1
]);
}
}
public
void
testNanoRepeatedPackedSerializedSize
()
throws
Exception
{
TestAllTypesNano
msg
=
new
TestAllTypesNano
();
msg
.
repeatedPackedInt32
=
new
int
[]
{
123
,
789
,
456
};
int
msgSerializedSize
=
msg
.
getSerializedSize
();
byte
[]
result
=
MessageNano
.
toByteArray
(
msg
);
//System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
assertTrue
(
msgSerializedSize
==
11
);
assertEquals
(
result
.
length
,
msgSerializedSize
);
TestAllTypesNano
msg2
=
new
TestAllTypesNano
();
msg2
.
repeatedPackedInt32
=
new
int
[]
{
123
,
789
,
456
};
byte
[]
result2
=
new
byte
[
msgSerializedSize
];
MessageNano
.
toByteArray
(
msg2
,
result2
,
0
,
msgSerializedSize
);
// Check equal size and content.
assertEquals
(
msgSerializedSize
,
msg2
.
getSerializedSize
());
assertTrue
(
Arrays
.
equals
(
result
,
result2
));
}
public
void
testNanoRepeatedInt32ReMerge
()
throws
Exception
{
public
void
testNanoRepeatedInt32ReMerge
()
throws
Exception
{
TestAllTypesNano
msg
=
new
TestAllTypesNano
();
TestAllTypesNano
msg
=
new
TestAllTypesNano
();
msg
.
repeatedInt32
=
new
int
[]
{
234
};
msg
.
repeatedInt32
=
new
int
[]
{
234
};
...
...
src/google/protobuf/compiler/javanano/javanano_primitive_field.cc
View file @
cebd784d
...
@@ -409,10 +409,6 @@ void RepeatedPrimitiveFieldGenerator::
...
@@ -409,10 +409,6 @@ void RepeatedPrimitiveFieldGenerator::
GenerateMembers
(
io
::
Printer
*
printer
)
const
{
GenerateMembers
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"public $type$[] $name$ = $default$;
\n
"
);
"public $type$[] $name$ = $default$;
\n
"
);
if
(
descriptor_
->
options
().
packed
())
{
printer
->
Print
(
variables_
,
"private int $name$MemoizedSerializedSize;
\n
"
);
}
}
}
void
RepeatedPrimitiveFieldGenerator
::
void
RepeatedPrimitiveFieldGenerator
::
...
@@ -461,13 +457,34 @@ GenerateParsingCode(io::Printer* printer) const {
...
@@ -461,13 +457,34 @@ GenerateParsingCode(io::Printer* printer) const {
}
}
}
}
void
RepeatedPrimitiveFieldGenerator
::
GenerateRepeatedDataSizeCode
(
io
::
Printer
*
printer
)
const
{
// Creates a variable dataSize and puts the serialized size in
// there.
if
(
FixedSize
(
descriptor_
->
type
())
==
-
1
)
{
printer
->
Print
(
variables_
,
"int dataSize = 0;
\n
"
"for ($type$ element : this.$name$) {
\n
"
" dataSize += com.google.protobuf.nano.CodedOutputByteBufferNano
\n
"
" .compute$capitalized_type$SizeNoTag(element);
\n
"
"}
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
"int dataSize = $fixed_size$ * this.$name$.length;
\n
"
);
}
}
void
RepeatedPrimitiveFieldGenerator
::
void
RepeatedPrimitiveFieldGenerator
::
GenerateSerializationCode
(
io
::
Printer
*
printer
)
const
{
GenerateSerializationCode
(
io
::
Printer
*
printer
)
const
{
if
(
descriptor_
->
options
().
packed
())
{
if
(
descriptor_
->
options
().
packed
())
{
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"if (this.$name$.length > 0) {
\n
"
"if (this.$name$.length > 0) {
\n
"
);
printer
->
Indent
();
GenerateRepeatedDataSizeCode
(
printer
);
printer
->
Outdent
();
printer
->
Print
(
variables_
,
" output.writeRawVarint32($tag$);
\n
"
" output.writeRawVarint32($tag$);
\n
"
" output.writeRawVarint32(
$name$MemoizedSerialized
Size);
\n
"
" output.writeRawVarint32(
data
Size);
\n
"
"}
\n
"
);
"}
\n
"
);
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"for ($type$ element : this.$name$) {
\n
"
"for ($type$ element : this.$name$) {
\n
"
...
@@ -487,27 +504,15 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
...
@@ -487,27 +504,15 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
"if (this.$name$.length > 0) {
\n
"
);
"if (this.$name$.length > 0) {
\n
"
);
printer
->
Indent
();
printer
->
Indent
();
if
(
FixedSize
(
descriptor_
->
type
())
==
-
1
)
{
GenerateRepeatedDataSizeCode
(
printer
);
printer
->
Print
(
variables_
,
"int dataSize = 0;
\n
"
"for ($type$ element : this.$name$) {
\n
"
" dataSize += com.google.protobuf.nano.CodedOutputByteBufferNano
\n
"
" .compute$capitalized_type$SizeNoTag(element);
\n
"
"}
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
"int dataSize = $fixed_size$ * this.$name$.length;
\n
"
);
}
printer
->
Print
(
printer
->
Print
(
"size += dataSize;
\n
"
);
"size += dataSize;
\n
"
);
if
(
descriptor_
->
options
().
packed
())
{
if
(
descriptor_
->
options
().
packed
())
{
// cache the data size for packed fields.
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"size += $tag_size$;
\n
"
"size += $tag_size$;
\n
"
"size += com.google.protobuf.nano.CodedOutputByteBufferNano
\n
"
"size += com.google.protobuf.nano.CodedOutputByteBufferNano
\n
"
" .computeRawVarint32Size(dataSize);
\n
"
" .computeRawVarint32Size(dataSize);
\n
"
);
"$name$MemoizedSerializedSize = dataSize;
\n
"
);
}
else
{
}
else
{
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"size += $tag_size$ * this.$name$.length;
\n
"
);
"size += $tag_size$ * this.$name$.length;
\n
"
);
...
@@ -515,16 +520,8 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
...
@@ -515,16 +520,8 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
printer
->
Outdent
();
printer
->
Outdent
();
// set cached size to 0 for empty packed fields.
if
(
descriptor_
->
options
().
packed
())
{
printer
->
Print
(
variables_
,
"} else {
\n
"
" $name$MemoizedSerializedSize = 0;
\n
"
"}
\n
"
);
}
else
{
printer
->
Print
(
printer
->
Print
(
"}
\n
"
);
"}
\n
"
);
}
}
}
string
RepeatedPrimitiveFieldGenerator
::
GetBoxedType
()
const
{
string
RepeatedPrimitiveFieldGenerator
::
GetBoxedType
()
const
{
...
...
src/google/protobuf/compiler/javanano/javanano_primitive_field.h
View file @
cebd784d
...
@@ -80,6 +80,8 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
...
@@ -80,6 +80,8 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
string
GetBoxedType
()
const
;
string
GetBoxedType
()
const
;
private
:
private
:
void
GenerateRepeatedDataSizeCode
(
io
::
Printer
*
printer
)
const
;
const
FieldDescriptor
*
descriptor_
;
const
FieldDescriptor
*
descriptor_
;
map
<
string
,
string
>
variables_
;
map
<
string
,
string
>
variables_
;
...
...
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