|
|
@ -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 { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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$MemoizedSerializedSize);\n" |
|
|
|
" output.writeRawVarint32(dataSize);\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 { |
|
|
|
"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 { |
|
|
|
|
|
|
|
|
|
|
|
printer->Outdent(); |
|
|
|
printer->Outdent(); |
|
|
|
|
|
|
|
|
|
|
|
// set cached size to 0 for empty packed fields.
|
|
|
|
printer->Print( |
|
|
|
if (descriptor_->options().packed()) { |
|
|
|
"}\n"); |
|
|
|
printer->Print(variables_, |
|
|
|
|
|
|
|
"} else {\n" |
|
|
|
|
|
|
|
" $name$MemoizedSerializedSize = 0;\n" |
|
|
|
|
|
|
|
"}\n"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
printer->Print( |
|
|
|
|
|
|
|
"}\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string RepeatedPrimitiveFieldGenerator::GetBoxedType() const { |
|
|
|
string RepeatedPrimitiveFieldGenerator::GetBoxedType() const { |
|
|
|