| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // http://code.google.com/p/protobuf/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| 11 // * Redistributions in binary form must reproduce the above | 11 // * Redistributions in binary form must reproduce the above |
| 12 // copyright notice, this list of conditions and the following disclaimer | 12 // copyright notice, this list of conditions and the following disclaimer |
| 13 // in the documentation and/or other materials provided with the | 13 // in the documentation and/or other materials provided with the |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 (*variables)["type"] = PrimitiveTypeName(descriptor->cpp_type()); | 86 (*variables)["type"] = PrimitiveTypeName(descriptor->cpp_type()); |
| 87 (*variables)["default"] = DefaultValue(descriptor); | 87 (*variables)["default"] = DefaultValue(descriptor); |
| 88 (*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor)); | 88 (*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor)); |
| 89 int fixed_size = FixedSize(descriptor->type()); | 89 int fixed_size = FixedSize(descriptor->type()); |
| 90 if (fixed_size != -1) { | 90 if (fixed_size != -1) { |
| 91 (*variables)["fixed_size"] = SimpleItoa(fixed_size); | 91 (*variables)["fixed_size"] = SimpleItoa(fixed_size); |
| 92 } | 92 } |
| 93 (*variables)["wire_format_field_type"] = | 93 (*variables)["wire_format_field_type"] = |
| 94 "::google::protobuf::internal::WireFormatLite::" + FieldDescriptorProto_Ty
pe_Name( | 94 "::google::protobuf::internal::WireFormatLite::" + FieldDescriptorProto_Ty
pe_Name( |
| 95 static_cast<FieldDescriptorProto_Type>(descriptor->type())); | 95 static_cast<FieldDescriptorProto_Type>(descriptor->type())); |
| 96 (*variables)["full_name"] = descriptor->full_name(); | |
| 97 } | 96 } |
| 98 | 97 |
| 99 } // namespace | 98 } // namespace |
| 100 | 99 |
| 101 // =================================================================== | 100 // =================================================================== |
| 102 | 101 |
| 103 PrimitiveFieldGenerator:: | 102 PrimitiveFieldGenerator:: |
| 104 PrimitiveFieldGenerator(const FieldDescriptor* descriptor, | 103 PrimitiveFieldGenerator(const FieldDescriptor* descriptor, |
| 105 const Options& options) | 104 const Options& options) |
| 106 : descriptor_(descriptor) { | 105 : descriptor_(descriptor) { |
| 107 SetPrimitiveVariables(descriptor, &variables_, options); | 106 SetPrimitiveVariables(descriptor, &variables_, options); |
| 108 } | 107 } |
| 109 | 108 |
| 110 PrimitiveFieldGenerator::~PrimitiveFieldGenerator() {} | 109 PrimitiveFieldGenerator::~PrimitiveFieldGenerator() {} |
| 111 | 110 |
| 112 void PrimitiveFieldGenerator:: | 111 void PrimitiveFieldGenerator:: |
| 113 GeneratePrivateMembers(io::Printer* printer) const { | 112 GeneratePrivateMembers(io::Printer* printer) const { |
| 114 printer->Print(variables_, "$type$ $name$_;\n"); | 113 printer->Print(variables_, "$type$ $name$_;\n"); |
| 115 } | 114 } |
| 116 | 115 |
| 117 void PrimitiveFieldGenerator:: | 116 void PrimitiveFieldGenerator:: |
| 118 GenerateAccessorDeclarations(io::Printer* printer) const { | 117 GenerateAccessorDeclarations(io::Printer* printer) const { |
| 119 printer->Print(variables_, | 118 printer->Print(variables_, |
| 120 "$type$ $name$() const$deprecation$;\n" | 119 "inline $type$ $name$() const$deprecation$;\n" |
| 121 "void set_$name$($type$ value)$deprecation$;\n"); | 120 "inline void set_$name$($type$ value)$deprecation$;\n"); |
| 122 } | 121 } |
| 123 | 122 |
| 124 void PrimitiveFieldGenerator:: | 123 void PrimitiveFieldGenerator:: |
| 125 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { | 124 GenerateInlineAccessorDefinitions(io::Printer* printer) const { |
| 126 map<string, string> variables(variables_); | 125 printer->Print(variables_, |
| 127 variables["inline"] = is_inline ? "inline" : ""; | 126 "inline $type$ $classname$::$name$() const {\n" |
| 128 printer->Print(variables, | |
| 129 "$inline$ $type$ $classname$::$name$() const {\n" | |
| 130 " // @@protoc_insertion_point(field_get:$full_name$)\n" | |
| 131 " return $name$_;\n" | 127 " return $name$_;\n" |
| 132 "}\n" | 128 "}\n" |
| 133 "$inline$ void $classname$::set_$name$($type$ value) {\n" | 129 "inline void $classname$::set_$name$($type$ value) {\n" |
| 134 " $set_hasbit$\n" | 130 " set_has_$name$();\n" |
| 135 " $name$_ = value;\n" | 131 " $name$_ = value;\n" |
| 136 " // @@protoc_insertion_point(field_set:$full_name$)\n" | |
| 137 "}\n"); | 132 "}\n"); |
| 138 } | 133 } |
| 139 | 134 |
| 140 void PrimitiveFieldGenerator:: | 135 void PrimitiveFieldGenerator:: |
| 141 GenerateClearingCode(io::Printer* printer) const { | 136 GenerateClearingCode(io::Printer* printer) const { |
| 142 printer->Print(variables_, "$name$_ = $default$;\n"); | 137 printer->Print(variables_, "$name$_ = $default$;\n"); |
| 143 } | 138 } |
| 144 | 139 |
| 145 void PrimitiveFieldGenerator:: | 140 void PrimitiveFieldGenerator:: |
| 146 GenerateMergingCode(io::Printer* printer) const { | 141 GenerateMergingCode(io::Printer* printer) const { |
| 147 printer->Print(variables_, "set_$name$(from.$name$());\n"); | 142 printer->Print(variables_, "set_$name$(from.$name$());\n"); |
| 148 } | 143 } |
| 149 | 144 |
| 150 void PrimitiveFieldGenerator:: | 145 void PrimitiveFieldGenerator:: |
| 151 GenerateSwappingCode(io::Printer* printer) const { | 146 GenerateSwappingCode(io::Printer* printer) const { |
| 152 printer->Print(variables_, "std::swap($name$_, other->$name$_);\n"); | 147 printer->Print(variables_, "std::swap($name$_, other->$name$_);\n"); |
| 153 } | 148 } |
| 154 | 149 |
| 155 void PrimitiveFieldGenerator:: | 150 void PrimitiveFieldGenerator:: |
| 156 GenerateConstructorCode(io::Printer* printer) const { | 151 GenerateConstructorCode(io::Printer* printer) const { |
| 157 printer->Print(variables_, "$name$_ = $default$;\n"); | 152 printer->Print(variables_, "$name$_ = $default$;\n"); |
| 158 } | 153 } |
| 159 | 154 |
| 160 void PrimitiveFieldGenerator:: | 155 void PrimitiveFieldGenerator:: |
| 161 GenerateMergeFromCodedStream(io::Printer* printer) const { | 156 GenerateMergeFromCodedStream(io::Printer* printer) const { |
| 162 printer->Print(variables_, | 157 printer->Print(variables_, |
| 163 "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n" | 158 "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n" |
| 164 " $type$, $wire_format_field_type$>(\n" | 159 " $type$, $wire_format_field_type$>(\n" |
| 165 " input, &$name$_)));\n" | 160 " input, &$name$_)));\n" |
| 166 "$set_hasbit$\n"); | 161 "set_has_$name$();\n"); |
| 167 } | 162 } |
| 168 | 163 |
| 169 void PrimitiveFieldGenerator:: | 164 void PrimitiveFieldGenerator:: |
| 170 GenerateSerializeWithCachedSizes(io::Printer* printer) const { | 165 GenerateSerializeWithCachedSizes(io::Printer* printer) const { |
| 171 printer->Print(variables_, | 166 printer->Print(variables_, |
| 172 "::google::protobuf::internal::WireFormatLite::Write$declared_type$(" | 167 "::google::protobuf::internal::WireFormatLite::Write$declared_type$(" |
| 173 "$number$, this->$name$(), output);\n"); | 168 "$number$, this->$name$(), output);\n"); |
| 174 } | 169 } |
| 175 | 170 |
| 176 void PrimitiveFieldGenerator:: | 171 void PrimitiveFieldGenerator:: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 189 " ::google::protobuf::internal::WireFormatLite::$declared_type$Size(\n" | 184 " ::google::protobuf::internal::WireFormatLite::$declared_type$Size(\n" |
| 190 " this->$name$());\n"); | 185 " this->$name$());\n"); |
| 191 } else { | 186 } else { |
| 192 printer->Print(variables_, | 187 printer->Print(variables_, |
| 193 "total_size += $tag_size$ + $fixed_size$;\n"); | 188 "total_size += $tag_size$ + $fixed_size$;\n"); |
| 194 } | 189 } |
| 195 } | 190 } |
| 196 | 191 |
| 197 // =================================================================== | 192 // =================================================================== |
| 198 | 193 |
| 199 PrimitiveOneofFieldGenerator:: | |
| 200 PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor, | |
| 201 const Options& options) | |
| 202 : PrimitiveFieldGenerator(descriptor, options) { | |
| 203 SetCommonOneofFieldVariables(descriptor, &variables_); | |
| 204 } | |
| 205 | |
| 206 PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {} | |
| 207 | |
| 208 void PrimitiveOneofFieldGenerator:: | |
| 209 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { | |
| 210 map<string, string> variables(variables_); | |
| 211 variables["inline"] = is_inline ? "inline" : ""; | |
| 212 printer->Print(variables, | |
| 213 "$inline$ $type$ $classname$::$name$() const {\n" | |
| 214 " // @@protoc_insertion_point(field_get:$full_name$)\n" | |
| 215 " if (has_$name$()) {\n" | |
| 216 " return $oneof_prefix$$name$_;\n" | |
| 217 " }\n" | |
| 218 " return $default$;\n" | |
| 219 "}\n" | |
| 220 "$inline$ void $classname$::set_$name$($type$ value) {\n" | |
| 221 " if (!has_$name$()) {\n" | |
| 222 " clear_$oneof_name$();\n" | |
| 223 " set_has_$name$();\n" | |
| 224 " }\n" | |
| 225 " $oneof_prefix$$name$_ = value;\n" | |
| 226 " // @@protoc_insertion_point(field_set:$full_name$)\n" | |
| 227 "}\n"); | |
| 228 } | |
| 229 | |
| 230 void PrimitiveOneofFieldGenerator:: | |
| 231 GenerateClearingCode(io::Printer* printer) const { | |
| 232 printer->Print(variables_, "$oneof_prefix$$name$_ = $default$;\n"); | |
| 233 } | |
| 234 | |
| 235 void PrimitiveOneofFieldGenerator:: | |
| 236 GenerateSwappingCode(io::Printer* printer) const { | |
| 237 // Don't print any swapping code. Swapping the union will swap this field. | |
| 238 } | |
| 239 | |
| 240 void PrimitiveOneofFieldGenerator:: | |
| 241 GenerateConstructorCode(io::Printer* printer) const { | |
| 242 printer->Print( | |
| 243 variables_, | |
| 244 " $classname$_default_oneof_instance_->$name$_ = $default$;\n"); | |
| 245 } | |
| 246 | |
| 247 void PrimitiveOneofFieldGenerator:: | |
| 248 GenerateMergeFromCodedStream(io::Printer* printer) const { | |
| 249 printer->Print(variables_, | |
| 250 "clear_$oneof_name$();\n" | |
| 251 "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n" | |
| 252 " $type$, $wire_format_field_type$>(\n" | |
| 253 " input, &$oneof_prefix$$name$_)));\n" | |
| 254 "set_has_$name$();\n"); | |
| 255 } | |
| 256 | |
| 257 // =================================================================== | |
| 258 | |
| 259 RepeatedPrimitiveFieldGenerator:: | 194 RepeatedPrimitiveFieldGenerator:: |
| 260 RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, | 195 RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, |
| 261 const Options& options) | 196 const Options& options) |
| 262 : descriptor_(descriptor) { | 197 : descriptor_(descriptor) { |
| 263 SetPrimitiveVariables(descriptor, &variables_, options); | 198 SetPrimitiveVariables(descriptor, &variables_, options); |
| 264 | 199 |
| 265 if (descriptor->is_packed()) { | 200 if (descriptor->options().packed()) { |
| 266 variables_["packed_reader"] = "ReadPackedPrimitive"; | 201 variables_["packed_reader"] = "ReadPackedPrimitive"; |
| 267 variables_["repeated_reader"] = "ReadRepeatedPrimitiveNoInline"; | 202 variables_["repeated_reader"] = "ReadRepeatedPrimitiveNoInline"; |
| 268 } else { | 203 } else { |
| 269 variables_["packed_reader"] = "ReadPackedPrimitiveNoInline"; | 204 variables_["packed_reader"] = "ReadPackedPrimitiveNoInline"; |
| 270 variables_["repeated_reader"] = "ReadRepeatedPrimitive"; | 205 variables_["repeated_reader"] = "ReadRepeatedPrimitive"; |
| 271 } | 206 } |
| 272 } | 207 } |
| 273 | 208 |
| 274 RepeatedPrimitiveFieldGenerator::~RepeatedPrimitiveFieldGenerator() {} | 209 RepeatedPrimitiveFieldGenerator::~RepeatedPrimitiveFieldGenerator() {} |
| 275 | 210 |
| 276 void RepeatedPrimitiveFieldGenerator:: | 211 void RepeatedPrimitiveFieldGenerator:: |
| 277 GeneratePrivateMembers(io::Printer* printer) const { | 212 GeneratePrivateMembers(io::Printer* printer) const { |
| 278 printer->Print(variables_, | 213 printer->Print(variables_, |
| 279 "::google::protobuf::RepeatedField< $type$ > $name$_;\n"); | 214 "::google::protobuf::RepeatedField< $type$ > $name$_;\n"); |
| 280 if (descriptor_->is_packed() && HasGeneratedMethods(descriptor_->file())) { | 215 if (descriptor_->options().packed() && HasGeneratedMethods(descriptor_->file()
)) { |
| 281 printer->Print(variables_, | 216 printer->Print(variables_, |
| 282 "mutable int _$name$_cached_byte_size_;\n"); | 217 "mutable int _$name$_cached_byte_size_;\n"); |
| 283 } | 218 } |
| 284 } | 219 } |
| 285 | 220 |
| 286 void RepeatedPrimitiveFieldGenerator:: | 221 void RepeatedPrimitiveFieldGenerator:: |
| 287 GenerateAccessorDeclarations(io::Printer* printer) const { | 222 GenerateAccessorDeclarations(io::Printer* printer) const { |
| 288 printer->Print(variables_, | 223 printer->Print(variables_, |
| 289 "$type$ $name$(int index) const$deprecation$;\n" | 224 "inline $type$ $name$(int index) const$deprecation$;\n" |
| 290 "void set_$name$(int index, $type$ value)$deprecation$;\n" | 225 "inline void set_$name$(int index, $type$ value)$deprecation$;\n" |
| 291 "void add_$name$($type$ value)$deprecation$;\n"); | 226 "inline void add_$name$($type$ value)$deprecation$;\n"); |
| 292 printer->Print(variables_, | 227 printer->Print(variables_, |
| 293 "const ::google::protobuf::RepeatedField< $type$ >&\n" | 228 "inline const ::google::protobuf::RepeatedField< $type$ >&\n" |
| 294 " $name$() const$deprecation$;\n" | 229 " $name$() const$deprecation$;\n" |
| 295 "::google::protobuf::RepeatedField< $type$ >*\n" | 230 "inline ::google::protobuf::RepeatedField< $type$ >*\n" |
| 296 " mutable_$name$()$deprecation$;\n"); | 231 " mutable_$name$()$deprecation$;\n"); |
| 297 } | 232 } |
| 298 | 233 |
| 299 void RepeatedPrimitiveFieldGenerator:: | 234 void RepeatedPrimitiveFieldGenerator:: |
| 300 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { | 235 GenerateInlineAccessorDefinitions(io::Printer* printer) const { |
| 301 map<string, string> variables(variables_); | 236 printer->Print(variables_, |
| 302 variables["inline"] = is_inline ? "inline" : ""; | 237 "inline $type$ $classname$::$name$(int index) const {\n" |
| 303 printer->Print(variables, | |
| 304 "$inline$ $type$ $classname$::$name$(int index) const {\n" | |
| 305 " // @@protoc_insertion_point(field_get:$full_name$)\n" | |
| 306 " return $name$_.Get(index);\n" | 238 " return $name$_.Get(index);\n" |
| 307 "}\n" | 239 "}\n" |
| 308 "$inline$ void $classname$::set_$name$(int index, $type$ value) {\n" | 240 "inline void $classname$::set_$name$(int index, $type$ value) {\n" |
| 309 " $name$_.Set(index, value);\n" | 241 " $name$_.Set(index, value);\n" |
| 310 " // @@protoc_insertion_point(field_set:$full_name$)\n" | |
| 311 "}\n" | 242 "}\n" |
| 312 "$inline$ void $classname$::add_$name$($type$ value) {\n" | 243 "inline void $classname$::add_$name$($type$ value) {\n" |
| 313 " $name$_.Add(value);\n" | 244 " $name$_.Add(value);\n" |
| 314 " // @@protoc_insertion_point(field_add:$full_name$)\n" | |
| 315 "}\n"); | 245 "}\n"); |
| 316 printer->Print(variables, | 246 printer->Print(variables_, |
| 317 "$inline$ const ::google::protobuf::RepeatedField< $type$ >&\n" | 247 "inline const ::google::protobuf::RepeatedField< $type$ >&\n" |
| 318 "$classname$::$name$() const {\n" | 248 "$classname$::$name$() const {\n" |
| 319 " // @@protoc_insertion_point(field_list:$full_name$)\n" | |
| 320 " return $name$_;\n" | 249 " return $name$_;\n" |
| 321 "}\n" | 250 "}\n" |
| 322 "$inline$ ::google::protobuf::RepeatedField< $type$ >*\n" | 251 "inline ::google::protobuf::RepeatedField< $type$ >*\n" |
| 323 "$classname$::mutable_$name$() {\n" | 252 "$classname$::mutable_$name$() {\n" |
| 324 " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" | |
| 325 " return &$name$_;\n" | 253 " return &$name$_;\n" |
| 326 "}\n"); | 254 "}\n"); |
| 327 } | 255 } |
| 328 | 256 |
| 329 void RepeatedPrimitiveFieldGenerator:: | 257 void RepeatedPrimitiveFieldGenerator:: |
| 330 GenerateClearingCode(io::Printer* printer) const { | 258 GenerateClearingCode(io::Printer* printer) const { |
| 331 printer->Print(variables_, "$name$_.Clear();\n"); | 259 printer->Print(variables_, "$name$_.Clear();\n"); |
| 332 } | 260 } |
| 333 | 261 |
| 334 void RepeatedPrimitiveFieldGenerator:: | 262 void RepeatedPrimitiveFieldGenerator:: |
| 335 GenerateMergingCode(io::Printer* printer) const { | 263 GenerateMergingCode(io::Printer* printer) const { |
| 336 printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n"); | 264 printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n"); |
| 337 } | 265 } |
| 338 | 266 |
| 339 void RepeatedPrimitiveFieldGenerator:: | 267 void RepeatedPrimitiveFieldGenerator:: |
| 340 GenerateSwappingCode(io::Printer* printer) const { | 268 GenerateSwappingCode(io::Printer* printer) const { |
| 341 printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); | 269 printer->Print(variables_, "$name$_.Swap(&other->$name$_);\n"); |
| 342 } | 270 } |
| 343 | 271 |
| 344 void RepeatedPrimitiveFieldGenerator:: | 272 void RepeatedPrimitiveFieldGenerator:: |
| 345 GenerateConstructorCode(io::Printer* printer) const { | 273 GenerateConstructorCode(io::Printer* printer) const { |
| 346 // Not needed for repeated fields. | 274 // Not needed for repeated fields. |
| 347 } | 275 } |
| 348 | 276 |
| 349 void RepeatedPrimitiveFieldGenerator:: | 277 void RepeatedPrimitiveFieldGenerator:: |
| 350 GenerateMergeFromCodedStream(io::Printer* printer) const { | 278 GenerateMergeFromCodedStream(io::Printer* printer) const { |
| 351 printer->Print(variables_, | 279 printer->Print(variables_, |
| 352 "DO_((::google::protobuf::internal::WireFormatLite::$repeated_reader$<\n" | 280 "DO_((::google::protobuf::internal::WireFormatLite::$repeated_reader$<\n" |
| 353 " $type$, $wire_format_field_type$>(\n" | 281 " $type$, $wire_format_field_type$>(\n" |
| 354 " $tag_size$, $tag$, input, this->mutable_$name$())));\n"); | 282 " $tag_size$, $tag$, input, this->mutable_$name$())));\n"); |
| 355 } | 283 } |
| 356 | 284 |
| 357 void RepeatedPrimitiveFieldGenerator:: | 285 void RepeatedPrimitiveFieldGenerator:: |
| 358 GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const { | 286 GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const { |
| 359 printer->Print(variables_, | 287 printer->Print(variables_, |
| 360 "DO_((::google::protobuf::internal::WireFormatLite::$packed_reader$<\n" | 288 "DO_((::google::protobuf::internal::WireFormatLite::$packed_reader$<\n" |
| 361 " $type$, $wire_format_field_type$>(\n" | 289 " $type$, $wire_format_field_type$>(\n" |
| 362 " input, this->mutable_$name$())));\n"); | 290 " input, this->mutable_$name$())));\n"); |
| 363 } | 291 } |
| 364 | 292 |
| 365 void RepeatedPrimitiveFieldGenerator:: | 293 void RepeatedPrimitiveFieldGenerator:: |
| 366 GenerateSerializeWithCachedSizes(io::Printer* printer) const { | 294 GenerateSerializeWithCachedSizes(io::Printer* printer) const { |
| 367 if (descriptor_->is_packed()) { | 295 if (descriptor_->options().packed()) { |
| 368 // Write the tag and the size. | 296 // Write the tag and the size. |
| 369 printer->Print(variables_, | 297 printer->Print(variables_, |
| 370 "if (this->$name$_size() > 0) {\n" | 298 "if (this->$name$_size() > 0) {\n" |
| 371 " ::google::protobuf::internal::WireFormatLite::WriteTag(" | 299 " ::google::protobuf::internal::WireFormatLite::WriteTag(" |
| 372 "$number$, " | 300 "$number$, " |
| 373 "::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMIT
ED, " | 301 "::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMIT
ED, " |
| 374 "output);\n" | 302 "output);\n" |
| 375 " output->WriteVarint32(_$name$_cached_byte_size_);\n" | 303 " output->WriteVarint32(_$name$_cached_byte_size_);\n" |
| 376 "}\n"); | 304 "}\n"); |
| 377 } | 305 } |
| 378 printer->Print(variables_, | 306 printer->Print(variables_, |
| 379 "for (int i = 0; i < this->$name$_size(); i++) {\n"); | 307 "for (int i = 0; i < this->$name$_size(); i++) {\n"); |
| 380 if (descriptor_->is_packed()) { | 308 if (descriptor_->options().packed()) { |
| 381 printer->Print(variables_, | 309 printer->Print(variables_, |
| 382 " ::google::protobuf::internal::WireFormatLite::Write$declared_type$NoTag
(\n" | 310 " ::google::protobuf::internal::WireFormatLite::Write$declared_type$NoTag
(\n" |
| 383 " this->$name$(i), output);\n"); | 311 " this->$name$(i), output);\n"); |
| 384 } else { | 312 } else { |
| 385 printer->Print(variables_, | 313 printer->Print(variables_, |
| 386 " ::google::protobuf::internal::WireFormatLite::Write$declared_type$(\n" | 314 " ::google::protobuf::internal::WireFormatLite::Write$declared_type$(\n" |
| 387 " $number$, this->$name$(i), output);\n"); | 315 " $number$, this->$name$(i), output);\n"); |
| 388 } | 316 } |
| 389 printer->Print("}\n"); | 317 printer->Print("}\n"); |
| 390 } | 318 } |
| 391 | 319 |
| 392 void RepeatedPrimitiveFieldGenerator:: | 320 void RepeatedPrimitiveFieldGenerator:: |
| 393 GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { | 321 GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { |
| 394 if (descriptor_->is_packed()) { | 322 if (descriptor_->options().packed()) { |
| 395 // Write the tag and the size. | 323 // Write the tag and the size. |
| 396 printer->Print(variables_, | 324 printer->Print(variables_, |
| 397 "if (this->$name$_size() > 0) {\n" | 325 "if (this->$name$_size() > 0) {\n" |
| 398 " target = ::google::protobuf::internal::WireFormatLite::WriteTagToArray(
\n" | 326 " target = ::google::protobuf::internal::WireFormatLite::WriteTagToArray(
\n" |
| 399 " $number$,\n" | 327 " $number$,\n" |
| 400 " ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMIT
ED,\n" | 328 " ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMIT
ED,\n" |
| 401 " target);\n" | 329 " target);\n" |
| 402 " target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArra
y(\n" | 330 " target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArra
y(\n" |
| 403 " _$name$_cached_byte_size_, target);\n" | 331 " _$name$_cached_byte_size_, target);\n" |
| 404 "}\n"); | 332 "}\n"); |
| 405 } | 333 } |
| 406 printer->Print(variables_, | 334 printer->Print(variables_, |
| 407 "for (int i = 0; i < this->$name$_size(); i++) {\n"); | 335 "for (int i = 0; i < this->$name$_size(); i++) {\n"); |
| 408 if (descriptor_->is_packed()) { | 336 if (descriptor_->options().packed()) { |
| 409 printer->Print(variables_, | 337 printer->Print(variables_, |
| 410 " target = ::google::protobuf::internal::WireFormatLite::\n" | 338 " target = ::google::protobuf::internal::WireFormatLite::\n" |
| 411 " Write$declared_type$NoTagToArray(this->$name$(i), target);\n"); | 339 " Write$declared_type$NoTagToArray(this->$name$(i), target);\n"); |
| 412 } else { | 340 } else { |
| 413 printer->Print(variables_, | 341 printer->Print(variables_, |
| 414 " target = ::google::protobuf::internal::WireFormatLite::\n" | 342 " target = ::google::protobuf::internal::WireFormatLite::\n" |
| 415 " Write$declared_type$ToArray($number$, this->$name$(i), target);\n"); | 343 " Write$declared_type$ToArray($number$, this->$name$(i), target);\n"); |
| 416 } | 344 } |
| 417 printer->Print("}\n"); | 345 printer->Print("}\n"); |
| 418 } | 346 } |
| 419 | 347 |
| 420 void RepeatedPrimitiveFieldGenerator:: | 348 void RepeatedPrimitiveFieldGenerator:: |
| 421 GenerateByteSize(io::Printer* printer) const { | 349 GenerateByteSize(io::Printer* printer) const { |
| 422 printer->Print(variables_, | 350 printer->Print(variables_, |
| 423 "{\n" | 351 "{\n" |
| 424 " int data_size = 0;\n"); | 352 " int data_size = 0;\n"); |
| 425 printer->Indent(); | 353 printer->Indent(); |
| 426 int fixed_size = FixedSize(descriptor_->type()); | 354 int fixed_size = FixedSize(descriptor_->type()); |
| 427 if (fixed_size == -1) { | 355 if (fixed_size == -1) { |
| 428 printer->Print(variables_, | 356 printer->Print(variables_, |
| 429 "for (int i = 0; i < this->$name$_size(); i++) {\n" | 357 "for (int i = 0; i < this->$name$_size(); i++) {\n" |
| 430 " data_size += ::google::protobuf::internal::WireFormatLite::\n" | 358 " data_size += ::google::protobuf::internal::WireFormatLite::\n" |
| 431 " $declared_type$Size(this->$name$(i));\n" | 359 " $declared_type$Size(this->$name$(i));\n" |
| 432 "}\n"); | 360 "}\n"); |
| 433 } else { | 361 } else { |
| 434 printer->Print(variables_, | 362 printer->Print(variables_, |
| 435 "data_size = $fixed_size$ * this->$name$_size();\n"); | 363 "data_size = $fixed_size$ * this->$name$_size();\n"); |
| 436 } | 364 } |
| 437 | 365 |
| 438 if (descriptor_->is_packed()) { | 366 if (descriptor_->options().packed()) { |
| 439 printer->Print(variables_, | 367 printer->Print(variables_, |
| 440 "if (data_size > 0) {\n" | 368 "if (data_size > 0) {\n" |
| 441 " total_size += $tag_size$ +\n" | 369 " total_size += $tag_size$ +\n" |
| 442 " ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n
" | 370 " ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n
" |
| 443 "}\n" | 371 "}\n" |
| 444 "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" | 372 "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" |
| 445 "_$name$_cached_byte_size_ = data_size;\n" | 373 "_$name$_cached_byte_size_ = data_size;\n" |
| 446 "GOOGLE_SAFE_CONCURRENT_WRITES_END();\n" | 374 "GOOGLE_SAFE_CONCURRENT_WRITES_END();\n" |
| 447 "total_size += data_size;\n"); | 375 "total_size += data_size;\n"); |
| 448 } else { | 376 } else { |
| 449 printer->Print(variables_, | 377 printer->Print(variables_, |
| 450 "total_size += $tag_size$ * this->$name$_size() + data_size;\n"); | 378 "total_size += $tag_size$ * this->$name$_size() + data_size;\n"); |
| 451 } | 379 } |
| 452 printer->Outdent(); | 380 printer->Outdent(); |
| 453 printer->Print("}\n"); | 381 printer->Print("}\n"); |
| 454 } | 382 } |
| 455 | 383 |
| 456 } // namespace cpp | 384 } // namespace cpp |
| 457 } // namespace compiler | 385 } // namespace compiler |
| 458 } // namespace protobuf | 386 } // namespace protobuf |
| 459 } // namespace google | 387 } // namespace google |
| OLD | NEW |