Merge "Prevent conflicts between local and proto variable names."
This commit is contained in:
commit
d4bb580f1b
@ -84,26 +84,21 @@ GenerateMembers(io::Printer* printer) const {
|
|||||||
"public int $name$ = $default$;\n");
|
"public int $name$ = $default$;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnumFieldGenerator::
|
|
||||||
GenerateMergingCode(io::Printer* printer) const {
|
|
||||||
printer->Print(variables_, "$name$ = other.$name$;\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void EnumFieldGenerator::
|
void EnumFieldGenerator::
|
||||||
GenerateParsingCode(io::Printer* printer) const {
|
GenerateParsingCode(io::Printer* printer) const {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
" $name$ = input.readInt32();\n");
|
" this.$name$ = input.readInt32();\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnumFieldGenerator::
|
void EnumFieldGenerator::
|
||||||
GenerateSerializationCode(io::Printer* printer) const {
|
GenerateSerializationCode(io::Printer* printer) const {
|
||||||
if (descriptor_->is_required()) {
|
if (descriptor_->is_required()) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"output.writeInt32($number$, $name$);\n");
|
"output.writeInt32($number$, this.$name$);\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if ($name$ != $default$) {\n"
|
"if (this.$name$ != $default$) {\n"
|
||||||
" output.writeInt32($number$, $name$);\n"
|
" output.writeInt32($number$, this.$name$);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,12 +108,12 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
|
|||||||
if (descriptor_->is_required()) {
|
if (descriptor_->is_required()) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
"size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
||||||
" .computeInt32Size($number$, $name$);\n");
|
" .computeInt32Size($number$, this.$name$);\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if ($name$ != $default$) {\n"
|
"if (this.$name$ != $default$) {\n"
|
||||||
" size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
" size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
||||||
" .computeInt32Size($number$, $name$);\n"
|
" .computeInt32Size($number$, this.$name$);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,16 +142,6 @@ GenerateMembers(io::Printer* printer) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepeatedEnumFieldGenerator::
|
|
||||||
GenerateMergingCode(io::Printer* printer) const {
|
|
||||||
printer->Print(variables_,
|
|
||||||
"if (other.$name$.length > 0) {\n"
|
|
||||||
" int[] merged = java.util.Arrays.copyOf(result.$name$, result.$name$.length + other.$name$.length);\n"
|
|
||||||
" java.lang.System.arraycopy(other.$name$, 0, merged, results.$name$.length, other.$name$.length);\n"
|
|
||||||
" result.$name$ = merged;\n"
|
|
||||||
"}\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void RepeatedEnumFieldGenerator::
|
void RepeatedEnumFieldGenerator::
|
||||||
GenerateParsingCode(io::Printer* printer) const {
|
GenerateParsingCode(io::Printer* printer) const {
|
||||||
// First, figure out the length of the array, then parse.
|
// First, figure out the length of the array, then parse.
|
||||||
@ -172,41 +157,41 @@ GenerateParsingCode(io::Printer* printer) const {
|
|||||||
" arrayLength++;\n"
|
" arrayLength++;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"input.rewindToPosition(startPos);\n"
|
"input.rewindToPosition(startPos);\n"
|
||||||
"$name$ = new $type$[arrayLength];\n"
|
"this.$name$ = new $type$[arrayLength];\n"
|
||||||
"for (int i = 0; i < arrayLength; i++) {\n"
|
"for (int i = 0; i < arrayLength; i++) {\n"
|
||||||
" $name$[i] = input.readInt32();\n"
|
" this.$name$[i] = input.readInt32();\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"input.popLimit(limit);\n");
|
"input.popLimit(limit);\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n"
|
"int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n"
|
||||||
"int i = $name$.length;\n"
|
"int i = this.$name$.length;\n"
|
||||||
"$name$ = java.util.Arrays.copyOf($name$, $name$.length + arrayLength);\n"
|
"this.$name$ = java.util.Arrays.copyOf(this.$name$, this.$name$.length + arrayLength);\n"
|
||||||
"for (; i < $name$.length - 1; i++) {\n"
|
"for (; i < this.$name$.length - 1; i++) {\n"
|
||||||
" $name$[i] = input.readInt32();\n"
|
" this.$name$[i] = input.readInt32();\n"
|
||||||
" input.readTag();\n"
|
" input.readTag();\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"// Last one without readTag.\n"
|
"// Last one without readTag.\n"
|
||||||
"$name$[i] = input.readInt32();\n");
|
"this.$name$[i] = input.readInt32();\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepeatedEnumFieldGenerator::
|
void RepeatedEnumFieldGenerator::
|
||||||
GenerateSerializationCode(io::Printer* printer) const {
|
GenerateSerializationCode(io::Printer* printer) const {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if ($name$.length > 0) {\n");
|
"if (this.$name$.length > 0) {\n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
|
|
||||||
if (descriptor_->options().packed()) {
|
if (descriptor_->options().packed()) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"output.writeRawVarint32($tag$);\n"
|
"output.writeRawVarint32($tag$);\n"
|
||||||
"output.writeRawVarint32($name$MemoizedSerializedSize);\n"
|
"output.writeRawVarint32($name$MemoizedSerializedSize);\n"
|
||||||
"for (int element : $name$) {\n"
|
"for (int element : this.$name$) {\n"
|
||||||
" output.writeRawVarint32(element);\n"
|
" output.writeRawVarint32(element);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"for (int element : $name$) {\n"
|
"for (int element : this.$name$) {\n"
|
||||||
" output.writeInt32($number$, element);\n"
|
" output.writeInt32($number$, element);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
}
|
}
|
||||||
@ -218,12 +203,12 @@ GenerateSerializationCode(io::Printer* printer) const {
|
|||||||
void RepeatedEnumFieldGenerator::
|
void RepeatedEnumFieldGenerator::
|
||||||
GenerateSerializedSizeCode(io::Printer* printer) const {
|
GenerateSerializedSizeCode(io::Printer* printer) const {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if ($name$.length > 0) {\n");
|
"if (this.$name$.length > 0) {\n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
|
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"int dataSize = 0;\n"
|
"int dataSize = 0;\n"
|
||||||
"for (int element : $name$) {\n"
|
"for (int element : this.$name$) {\n"
|
||||||
" dataSize += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
" dataSize += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
||||||
" .computeInt32SizeNoTag(element);\n"
|
" .computeInt32SizeNoTag(element);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
@ -239,7 +224,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
|
|||||||
"$name$MemoizedSerializedSize = dataSize;\n");
|
"$name$MemoizedSerializedSize = dataSize;\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"size += $tag_size$ * $name$.length;\n");
|
"size += $tag_size$ * this.$name$.length;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printer->Outdent();
|
printer->Outdent();
|
||||||
|
@ -51,7 +51,6 @@ class EnumFieldGenerator : public FieldGenerator {
|
|||||||
|
|
||||||
// implements FieldGenerator ---------------------------------------
|
// implements FieldGenerator ---------------------------------------
|
||||||
void GenerateMembers(io::Printer* printer) const;
|
void GenerateMembers(io::Printer* printer) const;
|
||||||
void GenerateMergingCode(io::Printer* printer) const;
|
|
||||||
void GenerateParsingCode(io::Printer* printer) const;
|
void GenerateParsingCode(io::Printer* printer) const;
|
||||||
void GenerateSerializationCode(io::Printer* printer) const;
|
void GenerateSerializationCode(io::Printer* printer) const;
|
||||||
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
||||||
@ -72,7 +71,6 @@ class RepeatedEnumFieldGenerator : public FieldGenerator {
|
|||||||
|
|
||||||
// implements FieldGenerator ---------------------------------------
|
// implements FieldGenerator ---------------------------------------
|
||||||
void GenerateMembers(io::Printer* printer) const;
|
void GenerateMembers(io::Printer* printer) const;
|
||||||
void GenerateMergingCode(io::Printer* printer) const;
|
|
||||||
void GenerateParsingCode(io::Printer* printer) const;
|
void GenerateParsingCode(io::Printer* printer) const;
|
||||||
void GenerateSerializationCode(io::Printer* printer) const;
|
void GenerateSerializationCode(io::Printer* printer) const;
|
||||||
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
||||||
|
@ -58,7 +58,6 @@ class FieldGenerator {
|
|||||||
virtual ~FieldGenerator();
|
virtual ~FieldGenerator();
|
||||||
|
|
||||||
virtual void GenerateMembers(io::Printer* printer) const = 0;
|
virtual void GenerateMembers(io::Printer* printer) const = 0;
|
||||||
virtual void GenerateMergingCode(io::Printer* printer) const = 0;
|
|
||||||
virtual void GenerateParsingCode(io::Printer* printer) const = 0;
|
virtual void GenerateParsingCode(io::Printer* printer) const = 0;
|
||||||
virtual void GenerateSerializationCode(io::Printer* printer) const = 0;
|
virtual void GenerateSerializationCode(io::Printer* printer) const = 0;
|
||||||
virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0;
|
virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0;
|
||||||
|
@ -87,42 +87,34 @@ GenerateMembers(io::Printer* printer) const {
|
|||||||
"public $type$ $name$ = null;\n");
|
"public $type$ $name$ = null;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageFieldGenerator::
|
|
||||||
GenerateMergingCode(io::Printer* printer) const {
|
|
||||||
printer->Print(variables_,
|
|
||||||
"if (other.$name$ != null) {\n"
|
|
||||||
" merge$capitalized_name$(other.$name$);\n"
|
|
||||||
"}\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void MessageFieldGenerator::
|
void MessageFieldGenerator::
|
||||||
GenerateParsingCode(io::Printer* printer) const {
|
GenerateParsingCode(io::Printer* printer) const {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"$name$ = new $type$();\n");
|
"this.$name$ = new $type$();\n");
|
||||||
|
|
||||||
if (descriptor_->type() == FieldDescriptor::TYPE_GROUP) {
|
if (descriptor_->type() == FieldDescriptor::TYPE_GROUP) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"input.readGroup($name$, $number$);\n");
|
"input.readGroup(this.$name$, $number$);\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"input.readMessage($name$);\n");
|
"input.readMessage(this.$name$);\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageFieldGenerator::
|
void MessageFieldGenerator::
|
||||||
GenerateSerializationCode(io::Printer* printer) const {
|
GenerateSerializationCode(io::Printer* printer) const {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if ($name$ != null) {\n"
|
"if (this.$name$ != null) {\n"
|
||||||
" output.write$group_or_message$($number$, $name$);\n"
|
" output.write$group_or_message$($number$, this.$name$);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageFieldGenerator::
|
void MessageFieldGenerator::
|
||||||
GenerateSerializedSizeCode(io::Printer* printer) const {
|
GenerateSerializedSizeCode(io::Printer* printer) const {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if ($name$ != null) {\n"
|
"if (this.$name$ != null) {\n"
|
||||||
" size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
" size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
||||||
" .compute$group_or_message$Size($number$, $name$);\n"
|
" .compute$group_or_message$Size($number$, this.$name$);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,53 +138,43 @@ GenerateMembers(io::Printer* printer) const {
|
|||||||
"public $type$[] $name$ = $type$.EMPTY_ARRAY;\n");
|
"public $type$[] $name$ = $type$.EMPTY_ARRAY;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepeatedMessageFieldGenerator::
|
|
||||||
GenerateMergingCode(io::Printer* printer) const {
|
|
||||||
printer->Print(variables_,
|
|
||||||
"if (other.$name$.length > 0) {\n"
|
|
||||||
" $type$[] merged = java.util.Arrays.copyOf(result.$name$, result.$name$.length + other.$name$.length);\n"
|
|
||||||
" java.lang.System.arraycopy(other.$name$, 0, merged, results.$name$.length, other.$name$.length);\n"
|
|
||||||
" result.$name$ = merged;\n"
|
|
||||||
"}\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void RepeatedMessageFieldGenerator::
|
void RepeatedMessageFieldGenerator::
|
||||||
GenerateParsingCode(io::Printer* printer) const {
|
GenerateParsingCode(io::Printer* printer) const {
|
||||||
// First, figure out the length of the array, then parse.
|
// First, figure out the length of the array, then parse.
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n"
|
"int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n"
|
||||||
"int i = $name$.length;\n"
|
"int i = this.$name$.length;\n"
|
||||||
"$name$ = java.util.Arrays.copyOf($name$, i + arrayLength);\n"
|
"this.$name$ = java.util.Arrays.copyOf(this.$name$, i + arrayLength);\n"
|
||||||
"for (; i < $name$.length - 1; i++) {\n"
|
"for (; i < this.$name$.length - 1; i++) {\n"
|
||||||
" $name$[i] = new $type$();\n");
|
" this.$name$[i] = new $type$();\n");
|
||||||
|
|
||||||
if (descriptor_->type() == FieldDescriptor::TYPE_GROUP) {
|
if (descriptor_->type() == FieldDescriptor::TYPE_GROUP) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
" input.readGroup($name$[i], $number$);\n");
|
" input.readGroup(this.$name$[i], $number$);\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
" input.readMessage($name$[i]);\n");
|
" input.readMessage(this.$name$[i]);\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
" input.readTag();\n"
|
" input.readTag();\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"// Last one without readTag.\n"
|
"// Last one without readTag.\n"
|
||||||
"$name$[i] = new $type$();\n");
|
"this.$name$[i] = new $type$();\n");
|
||||||
|
|
||||||
if (descriptor_->type() == FieldDescriptor::TYPE_GROUP) {
|
if (descriptor_->type() == FieldDescriptor::TYPE_GROUP) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"input.readGroup($name$[i], $number$);\n");
|
"input.readGroup(this.$name$[i], $number$);\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"input.readMessage($name$[i]);\n");
|
"input.readMessage(this.$name$[i]);\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepeatedMessageFieldGenerator::
|
void RepeatedMessageFieldGenerator::
|
||||||
GenerateSerializationCode(io::Printer* printer) const {
|
GenerateSerializationCode(io::Printer* printer) const {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"for ($type$ element : $name$) {\n"
|
"for ($type$ element : this.$name$) {\n"
|
||||||
" output.write$group_or_message$($number$, element);\n"
|
" output.write$group_or_message$($number$, element);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
}
|
}
|
||||||
@ -200,7 +182,7 @@ GenerateSerializationCode(io::Printer* printer) const {
|
|||||||
void RepeatedMessageFieldGenerator::
|
void RepeatedMessageFieldGenerator::
|
||||||
GenerateSerializedSizeCode(io::Printer* printer) const {
|
GenerateSerializedSizeCode(io::Printer* printer) const {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"for ($type$ element : $name$) {\n"
|
"for ($type$ element : this.$name$) {\n"
|
||||||
" size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
" size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
||||||
" .compute$group_or_message$Size($number$, element);\n"
|
" .compute$group_or_message$Size($number$, element);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
@ -51,7 +51,6 @@ class MessageFieldGenerator : public FieldGenerator {
|
|||||||
|
|
||||||
// implements FieldGenerator ---------------------------------------
|
// implements FieldGenerator ---------------------------------------
|
||||||
void GenerateMembers(io::Printer* printer) const;
|
void GenerateMembers(io::Printer* printer) const;
|
||||||
void GenerateMergingCode(io::Printer* printer) const;
|
|
||||||
void GenerateParsingCode(io::Printer* printer) const;
|
void GenerateParsingCode(io::Printer* printer) const;
|
||||||
void GenerateSerializationCode(io::Printer* printer) const;
|
void GenerateSerializationCode(io::Printer* printer) const;
|
||||||
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
||||||
@ -73,7 +72,6 @@ class RepeatedMessageFieldGenerator : public FieldGenerator {
|
|||||||
|
|
||||||
// implements FieldGenerator ---------------------------------------
|
// implements FieldGenerator ---------------------------------------
|
||||||
void GenerateMembers(io::Printer* printer) const;
|
void GenerateMembers(io::Printer* printer) const;
|
||||||
void GenerateMergingCode(io::Printer* printer) const;
|
|
||||||
void GenerateParsingCode(io::Printer* printer) const;
|
void GenerateParsingCode(io::Printer* printer) const;
|
||||||
void GenerateSerializationCode(io::Printer* printer) const;
|
void GenerateSerializationCode(io::Printer* printer) const;
|
||||||
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
||||||
|
@ -290,36 +290,31 @@ GenerateMembers(io::Printer* printer) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrimitiveFieldGenerator::
|
|
||||||
GenerateMergingCode(io::Printer* printer) const {
|
|
||||||
printer->Print(variables_, "$name$ = other.$name$;\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrimitiveFieldGenerator::
|
void PrimitiveFieldGenerator::
|
||||||
GenerateParsingCode(io::Printer* printer) const {
|
GenerateParsingCode(io::Printer* printer) const {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"$name$ = input.read$capitalized_type$();\n");
|
"this.$name$ = input.read$capitalized_type$();\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrimitiveFieldGenerator::
|
void PrimitiveFieldGenerator::
|
||||||
GenerateSerializationCode(io::Printer* printer) const {
|
GenerateSerializationCode(io::Printer* printer) const {
|
||||||
if (descriptor_->is_required()) {
|
if (descriptor_->is_required()) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"output.write$capitalized_type$($number$, $name$);\n");
|
"output.write$capitalized_type$($number$, this.$name$);\n");
|
||||||
} else {
|
} else {
|
||||||
if (IsArrayType(GetJavaType(descriptor_))) {
|
if (IsArrayType(GetJavaType(descriptor_))) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if (!java.util.Arrays.equals($name$, $default$)) {\n");
|
"if (!java.util.Arrays.equals(this.$name$, $default$)) {\n");
|
||||||
} else if (IsReferenceType(GetJavaType(descriptor_))) {
|
} else if (IsReferenceType(GetJavaType(descriptor_))) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if (!$name$.equals($default$)) {\n");
|
"if (!this.$name$.equals($default$)) {\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if ($name$ != $default$) {\n");
|
"if (this.$name$ != $default$) {\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
" output.write$capitalized_type$($number$, $name$);\n"
|
" output.write$capitalized_type$($number$, this.$name$);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,22 +324,22 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
|
|||||||
if (descriptor_->is_required()) {
|
if (descriptor_->is_required()) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
"size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
||||||
" .compute$capitalized_type$Size($number$, $name$);\n");
|
" .compute$capitalized_type$Size($number$, this.$name$);\n");
|
||||||
} else {
|
} else {
|
||||||
if (IsArrayType(GetJavaType(descriptor_))) {
|
if (IsArrayType(GetJavaType(descriptor_))) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if (!java.util.Arrays.equals($name$, $default$)) {\n");
|
"if (!java.util.Arrays.equals(this.$name$, $default$)) {\n");
|
||||||
} else if (IsReferenceType(GetJavaType(descriptor_))) {
|
} else if (IsReferenceType(GetJavaType(descriptor_))) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if (!$name$.equals($default$)) {\n");
|
"if (!this.$name$.equals($default$)) {\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if ($name$ != $default$) {\n");
|
"if (this.$name$ != $default$) {\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
" size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
" size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
||||||
" .compute$capitalized_type$Size($number$, $name$);\n"
|
" .compute$capitalized_type$Size($number$, this.$name$);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -373,16 +368,6 @@ GenerateMembers(io::Printer* printer) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepeatedPrimitiveFieldGenerator::
|
|
||||||
GenerateMergingCode(io::Printer* printer) const {
|
|
||||||
printer->Print(variables_,
|
|
||||||
"if (other.$name$.length > 0) {\n"
|
|
||||||
" $type$[] merged = java.util.Arrays.copyOf(result.$name$, result.$name$.length + other.$name$.length);\n"
|
|
||||||
" java.lang.System.arraycopy(other.$name$, 0, merged, results.$name$.length, other.$name$.length);\n"
|
|
||||||
" result.$name$ = merged;\n"
|
|
||||||
"}\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void RepeatedPrimitiveFieldGenerator::
|
void RepeatedPrimitiveFieldGenerator::
|
||||||
GenerateParsingCode(io::Printer* printer) const {
|
GenerateParsingCode(io::Printer* printer) const {
|
||||||
// First, figure out the length of the array, then parse.
|
// First, figure out the length of the array, then parse.
|
||||||
@ -398,22 +383,22 @@ GenerateParsingCode(io::Printer* printer) const {
|
|||||||
" arrayLength++;\n"
|
" arrayLength++;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"input.rewindToPosition(startPos);\n"
|
"input.rewindToPosition(startPos);\n"
|
||||||
"$name$ = new $type$[arrayLength];\n"
|
"this.$name$ = new $type$[arrayLength];\n"
|
||||||
"for (int i = 0; i < arrayLength; i++) {\n"
|
"for (int i = 0; i < arrayLength; i++) {\n"
|
||||||
" $name$[i] = input.read$capitalized_type$();\n"
|
" this.$name$[i] = input.read$capitalized_type$();\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"input.popLimit(limit);\n");
|
"input.popLimit(limit);\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n"
|
"int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n"
|
||||||
"int i = $name$.length;\n"
|
"int i = this.$name$.length;\n"
|
||||||
"$name$ = java.util.Arrays.copyOf($name$, $name$.length + arrayLength);\n"
|
"this.$name$ = java.util.Arrays.copyOf(this.$name$, this.$name$.length + arrayLength);\n"
|
||||||
"for (; i < $name$.length - 1; i++) {\n"
|
"for (; i < this.$name$.length - 1; i++) {\n"
|
||||||
" $name$[i] = input.read$capitalized_type$();\n"
|
" this.$name$[i] = input.read$capitalized_type$();\n"
|
||||||
" input.readTag();\n"
|
" input.readTag();\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"// Last one without readTag.\n"
|
"// Last one without readTag.\n"
|
||||||
"$name$[i] = input.read$capitalized_type$();\n");
|
"this.$name$[i] = input.read$capitalized_type$();\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,17 +406,17 @@ 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 ($name$.length > 0) {\n"
|
"if (this.$name$.length > 0) {\n"
|
||||||
" output.writeRawVarint32($tag$);\n"
|
" output.writeRawVarint32($tag$);\n"
|
||||||
" output.writeRawVarint32($name$MemoizedSerializedSize);\n"
|
" output.writeRawVarint32($name$MemoizedSerializedSize);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"for ($type$ element : $name$) {\n"
|
"for ($type$ element : this.$name$) {\n"
|
||||||
" output.write$capitalized_type$NoTag(element);\n"
|
" output.write$capitalized_type$NoTag(element);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"for ($type$ element : $name$) {\n"
|
"for ($type$ element : this.$name$) {\n"
|
||||||
" output.write$capitalized_type$($number$, element);\n"
|
" output.write$capitalized_type$($number$, element);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
}
|
}
|
||||||
@ -440,19 +425,19 @@ GenerateSerializationCode(io::Printer* printer) const {
|
|||||||
void RepeatedPrimitiveFieldGenerator::
|
void RepeatedPrimitiveFieldGenerator::
|
||||||
GenerateSerializedSizeCode(io::Printer* printer) const {
|
GenerateSerializedSizeCode(io::Printer* printer) const {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"if ($name$.length > 0) {\n");
|
"if (this.$name$.length > 0) {\n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
|
|
||||||
if (FixedSize(descriptor_->type()) == -1) {
|
if (FixedSize(descriptor_->type()) == -1) {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"int dataSize = 0;\n"
|
"int dataSize = 0;\n"
|
||||||
"for ($type$ element : $name$) {\n"
|
"for ($type$ element : this.$name$) {\n"
|
||||||
" dataSize += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
" dataSize += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
|
||||||
" .compute$capitalized_type$SizeNoTag(element);\n"
|
" .compute$capitalized_type$SizeNoTag(element);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"int dataSize = $fixed_size$ * $name$.length;\n");
|
"int dataSize = $fixed_size$ * this.$name$.length;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printer->Print(
|
printer->Print(
|
||||||
@ -466,7 +451,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
|
|||||||
"$name$MemoizedSerializedSize = dataSize;\n");
|
"$name$MemoizedSerializedSize = dataSize;\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(variables_,
|
printer->Print(variables_,
|
||||||
"size += $tag_size$ * $name$.length;\n");
|
"size += $tag_size$ * this.$name$.length;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printer->Outdent();
|
printer->Outdent();
|
||||||
|
@ -51,7 +51,6 @@ class PrimitiveFieldGenerator : public FieldGenerator {
|
|||||||
|
|
||||||
// implements FieldGenerator ---------------------------------------
|
// implements FieldGenerator ---------------------------------------
|
||||||
void GenerateMembers(io::Printer* printer) const;
|
void GenerateMembers(io::Printer* printer) const;
|
||||||
void GenerateMergingCode(io::Printer* printer) const;
|
|
||||||
void GenerateParsingCode(io::Printer* printer) const;
|
void GenerateParsingCode(io::Printer* printer) const;
|
||||||
void GenerateSerializationCode(io::Printer* printer) const;
|
void GenerateSerializationCode(io::Printer* printer) const;
|
||||||
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
||||||
@ -72,7 +71,6 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
|
|||||||
|
|
||||||
// implements FieldGenerator ---------------------------------------
|
// implements FieldGenerator ---------------------------------------
|
||||||
void GenerateMembers(io::Printer* printer) const;
|
void GenerateMembers(io::Printer* printer) const;
|
||||||
void GenerateMergingCode(io::Printer* printer) const;
|
|
||||||
void GenerateParsingCode(io::Printer* printer) const;
|
void GenerateParsingCode(io::Printer* printer) const;
|
||||||
void GenerateSerializationCode(io::Printer* printer) const;
|
void GenerateSerializationCode(io::Printer* printer) const;
|
||||||
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
void GenerateSerializedSizeCode(io::Printer* printer) const;
|
||||||
|
@ -152,6 +152,11 @@ message TestAllTypesNano {
|
|||||||
optional string default_cord = 85 [ctype=CORD,default="123"];
|
optional string default_cord = 85 [ctype=CORD,default="123"];
|
||||||
|
|
||||||
required int32 id = 86;
|
required int32 id = 86;
|
||||||
|
|
||||||
|
// Try to cause conflicts.
|
||||||
|
optional int32 tag = 93;
|
||||||
|
optional int32 get_serialized_size = 94;
|
||||||
|
optional int32 write_to = 95;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ForeignMessageNano {
|
message ForeignMessageNano {
|
||||||
|
Loading…
Reference in New Issue
Block a user