text_format.cc
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 // Author: jschorr@google.com (Joseph Schorr)
32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others.
34 
36 
37 #include <float.h>
38 #include <math.h>
39 #include <stdio.h>
40 #include <algorithm>
41 #include <climits>
42 #include <limits>
43 #include <vector>
44 
46 #include <google/protobuf/any.h>
61 
62 
63 
66 
67 #include <google/protobuf/port_def.inc>
68 
69 
70 namespace google {
71 namespace protobuf {
72 
73 namespace {
74 
75 inline bool IsHexNumber(const std::string& str) {
76  return (str.length() >= 2 && str[0] == '0' &&
77  (str[1] == 'x' || str[1] == 'X'));
78 }
79 
80 inline bool IsOctNumber(const std::string& str) {
81  return (str.length() >= 2 && str[0] == '0' &&
82  (str[1] >= '0' && str[1] < '8'));
83 }
84 
85 } // namespace
86 
88  std::string debug_string;
89 
90  TextFormat::Printer printer;
91  printer.SetExpandAny(true);
92 
93  printer.PrintToString(*this, &debug_string);
94 
95  return debug_string;
96 }
97 
99  std::string debug_string;
100 
101  TextFormat::Printer printer;
102  printer.SetSingleLineMode(true);
103  printer.SetExpandAny(true);
104 
105  printer.PrintToString(*this, &debug_string);
106  // Single line mode currently might have an extra space at the end.
107  if (debug_string.size() > 0 && debug_string[debug_string.size() - 1] == ' ') {
108  debug_string.resize(debug_string.size() - 1);
109  }
110 
111  return debug_string;
112 }
113 
115  std::string debug_string;
116 
117  TextFormat::Printer printer;
118  printer.SetUseUtf8StringEscaping(true);
119  printer.SetExpandAny(true);
120 
121  printer.PrintToString(*this, &debug_string);
122 
123  return debug_string;
124 }
125 
126 void Message::PrintDebugString() const { printf("%s", DebugString().c_str()); }
127 
128 
129 // ===========================================================================
130 // Implementation of the parse information tree class.
132 
134  // Remove any nested information trees, as they are owned by this tree.
135  for (NestedMap::iterator it = nested_.begin(); it != nested_.end(); ++it) {
136  STLDeleteElements(&(it->second));
137  }
138 }
139 
142  locations_[field].push_back(location);
143 }
144 
146  const FieldDescriptor* field) {
147  // Owned by us in the map.
149  std::vector<TextFormat::ParseInfoTree*>* trees = &nested_[field];
150  GOOGLE_CHECK(trees);
151  trees->push_back(instance);
152  return instance;
153 }
154 
156  if (field == nullptr) {
157  return;
158  }
159 
160  if (field->is_repeated() && index == -1) {
161  GOOGLE_LOG(DFATAL) << "Index must be in range of repeated field values. "
162  << "Field: " << field->name();
163  } else if (!field->is_repeated() && index != -1) {
164  GOOGLE_LOG(DFATAL) << "Index must be -1 for singular fields."
165  << "Field: " << field->name();
166  }
167 }
168 
170  const FieldDescriptor* field, int index) const {
172  if (index == -1) {
173  index = 0;
174  }
175 
176  const std::vector<TextFormat::ParseLocation>* locations =
177  FindOrNull(locations_, field);
178  if (locations == nullptr || index >= locations->size()) {
179  return TextFormat::ParseLocation();
180  }
181 
182  return (*locations)[index];
183 }
184 
186  const FieldDescriptor* field, int index) const {
188  if (index == -1) {
189  index = 0;
190  }
191 
192  const std::vector<TextFormat::ParseInfoTree*>* trees =
193  FindOrNull(nested_, field);
194  if (trees == nullptr || index >= trees->size()) {
195  return nullptr;
196  }
197 
198  return (*trees)[index];
199 }
200 
201 namespace {
202 // These functions implement the behavior of the "default" TextFormat::Finder,
203 // they are defined as standalone to be called when finder_ is nullptr.
204 const FieldDescriptor* DefaultFinderFindExtension(Message* message,
205  const std::string& name) {
206  const Descriptor* descriptor = message->GetDescriptor();
207  return descriptor->file()->pool()->FindExtensionByPrintableName(descriptor,
208  name);
209 }
210 
211 const FieldDescriptor* DefaultFinderFindExtensionByNumber(
212  const Descriptor* descriptor, int number) {
213  return descriptor->file()->pool()->FindExtensionByNumber(descriptor, number);
214 }
215 
216 const Descriptor* DefaultFinderFindAnyType(const Message& message,
217  const std::string& prefix,
218  const std::string& name) {
221  return nullptr;
222  }
223  return message.GetDescriptor()->file()->pool()->FindMessageTypeByName(name);
224 }
225 } // namespace
226 
227 // ===========================================================================
228 // Internal class for parsing an ASCII representation of a Protocol Message.
229 // This class makes use of the Protocol Message compiler's tokenizer found
230 // in //net/proto2/io/public/tokenizer.h. Note that class's Parse
231 // method is *not* thread-safe and should only be used in a single thread at
232 // a time.
233 
234 // Makes code slightly more readable. The meaning of "DO(foo)" is
235 // "Execute foo and fail if it fails.", where failure is indicated by
236 // returning false. Borrowed from parser.cc (Thanks Kenton!).
237 #define DO(STATEMENT) \
238  if (STATEMENT) { \
239  } else { \
240  return false; \
241  }
242 
244  public:
245  // Determines if repeated values for non-repeated fields and
246  // oneofs are permitted, e.g., the string "foo: 1 foo: 2" for a
247  // required/optional field named "foo", or "baz: 1 qux: 2"
248  // where "baz" and "qux" are members of the same oneof.
250  ALLOW_SINGULAR_OVERWRITES = 0, // the last value is retained
251  FORBID_SINGULAR_OVERWRITES = 1, // an error is issued
252  };
253 
254  ParserImpl(const Descriptor* root_message_type,
255  io::ZeroCopyInputStream* input_stream,
256  io::ErrorCollector* error_collector,
257  const TextFormat::Finder* finder, ParseInfoTree* parse_info_tree,
258  SingularOverwritePolicy singular_overwrite_policy,
259  bool allow_case_insensitive_field, bool allow_unknown_field,
260  bool allow_unknown_extension, bool allow_unknown_enum,
261  bool allow_field_number, bool allow_relaxed_whitespace,
262  bool allow_partial, int recursion_limit)
263  : error_collector_(error_collector),
264  finder_(finder),
265  parse_info_tree_(parse_info_tree),
266  tokenizer_error_collector_(this),
267  tokenizer_(input_stream, &tokenizer_error_collector_),
268  root_message_type_(root_message_type),
269  singular_overwrite_policy_(singular_overwrite_policy),
270  allow_case_insensitive_field_(allow_case_insensitive_field),
271  allow_unknown_field_(allow_unknown_field),
272  allow_unknown_extension_(allow_unknown_extension),
273  allow_unknown_enum_(allow_unknown_enum),
274  allow_field_number_(allow_field_number),
275  allow_partial_(allow_partial),
276  recursion_limit_(recursion_limit),
277  had_errors_(false) {
278  // For backwards-compatibility with proto1, we need to allow the 'f' suffix
279  // for floats.
280  tokenizer_.set_allow_f_after_float(true);
281 
282  // '#' starts a comment.
283  tokenizer_.set_comment_style(io::Tokenizer::SH_COMMENT_STYLE);
284 
285  if (allow_relaxed_whitespace) {
286  tokenizer_.set_require_space_after_number(false);
287  tokenizer_.set_allow_multiline_strings(true);
288  }
289 
290  // Consume the starting token.
291  tokenizer_.Next();
292  }
294 
295  // Parses the ASCII representation specified in input and saves the
296  // information into the output pointer (a Message). Returns
297  // false if an error occurs (an error will also be logged to
298  // GOOGLE_LOG(ERROR)).
300  // Consume fields until we cannot do so anymore.
301  while (true) {
302  if (LookingAtType(io::Tokenizer::TYPE_END)) {
303  return !had_errors_;
304  }
305 
306  DO(ConsumeField(output));
307  }
308  }
309 
311  bool suc;
312  if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
313  suc = ConsumeFieldMessage(output, output->GetReflection(), field);
314  } else {
315  suc = ConsumeFieldValue(output, output->GetReflection(), field);
316  }
317  return suc && LookingAtType(io::Tokenizer::TYPE_END);
318  }
319 
320  void ReportError(int line, int col, const std::string& message) {
321  had_errors_ = true;
322  if (error_collector_ == nullptr) {
323  if (line >= 0) {
324  GOOGLE_LOG(ERROR) << "Error parsing text-format "
325  << root_message_type_->full_name() << ": " << (line + 1)
326  << ":" << (col + 1) << ": " << message;
327  } else {
328  GOOGLE_LOG(ERROR) << "Error parsing text-format "
329  << root_message_type_->full_name() << ": " << message;
330  }
331  } else {
332  error_collector_->AddError(line, col, message);
333  }
334  }
335 
336  void ReportWarning(int line, int col, const std::string& message) {
337  if (error_collector_ == nullptr) {
338  if (line >= 0) {
339  GOOGLE_LOG(WARNING) << "Warning parsing text-format "
340  << root_message_type_->full_name() << ": " << (line + 1)
341  << ":" << (col + 1) << ": " << message;
342  } else {
343  GOOGLE_LOG(WARNING) << "Warning parsing text-format "
344  << root_message_type_->full_name() << ": " << message;
345  }
346  } else {
347  error_collector_->AddWarning(line, col, message);
348  }
349  }
350 
351  private:
353 
354  // Reports an error with the given message with information indicating
355  // the position (as derived from the current token).
357  ReportError(tokenizer_.current().line, tokenizer_.current().column,
358  message);
359  }
360 
361  // Reports a warning with the given message with information indicating
362  // the position (as derived from the current token).
364  ReportWarning(tokenizer_.current().line, tokenizer_.current().column,
365  message);
366  }
367 
368  // Consumes the specified message with the given starting delimiter.
369  // This method checks to see that the end delimiter at the conclusion of
370  // the consumption matches the starting delimiter passed in here.
371  bool ConsumeMessage(Message* message, const std::string delimiter) {
372  while (!LookingAt(">") && !LookingAt("}")) {
373  DO(ConsumeField(message));
374  }
375 
376  // Confirm that we have a valid ending delimiter.
377  DO(Consume(delimiter));
378  return true;
379  }
380 
381  // Consume either "<" or "{".
383  if (TryConsume("<")) {
384  *delimiter = ">";
385  } else {
386  DO(Consume("{"));
387  *delimiter = "}";
388  }
389  return true;
390  }
391 
392 
393  // Consumes the current field (as returned by the tokenizer) on the
394  // passed in message.
396  const Reflection* reflection = message->GetReflection();
397  const Descriptor* descriptor = message->GetDescriptor();
398 
399  std::string field_name;
400  bool reserved_field = false;
401  const FieldDescriptor* field = nullptr;
402  int start_line = tokenizer_.current().line;
403  int start_column = tokenizer_.current().column;
404 
405  const FieldDescriptor* any_type_url_field;
406  const FieldDescriptor* any_value_field;
407  if (internal::GetAnyFieldDescriptors(*message, &any_type_url_field,
408  &any_value_field) &&
409  TryConsume("[")) {
410  std::string full_type_name, prefix;
411  DO(ConsumeAnyTypeUrl(&full_type_name, &prefix));
412  DO(Consume("]"));
413  TryConsume(":"); // ':' is optional between message labels and values.
414  std::string serialized_value;
415  const Descriptor* value_descriptor =
416  finder_ ? finder_->FindAnyType(*message, prefix, full_type_name)
417  : DefaultFinderFindAnyType(*message, prefix, full_type_name);
418  if (value_descriptor == nullptr) {
419  ReportError("Could not find type \"" + prefix + full_type_name +
420  "\" stored in google.protobuf.Any.");
421  return false;
422  }
423  DO(ConsumeAnyValue(value_descriptor, &serialized_value));
424  if (singular_overwrite_policy_ == FORBID_SINGULAR_OVERWRITES) {
425  // Fail if any_type_url_field has already been specified.
426  if ((!any_type_url_field->is_repeated() &&
427  reflection->HasField(*message, any_type_url_field)) ||
428  (!any_value_field->is_repeated() &&
429  reflection->HasField(*message, any_value_field))) {
430  ReportError("Non-repeated Any specified multiple times.");
431  return false;
432  }
433  }
434  reflection->SetString(message, any_type_url_field,
435  std::string(prefix + full_type_name));
436  reflection->SetString(message, any_value_field, serialized_value);
437  return true;
438  }
439  if (TryConsume("[")) {
440  // Extension.
441  DO(ConsumeFullTypeName(&field_name));
442  DO(Consume("]"));
443 
444  field = finder_ ? finder_->FindExtension(message, field_name)
445  : DefaultFinderFindExtension(message, field_name);
446 
447  if (field == nullptr) {
448  if (!allow_unknown_field_ && !allow_unknown_extension_) {
449  ReportError("Extension \"" + field_name +
450  "\" is not defined or "
451  "is not an extension of \"" +
452  descriptor->full_name() + "\".");
453  return false;
454  } else {
455  ReportWarning("Ignoring extension \"" + field_name +
456  "\" which is not defined or is not an extension of \"" +
457  descriptor->full_name() + "\".");
458  }
459  }
460  } else {
461  DO(ConsumeIdentifier(&field_name));
462 
463  int32 field_number;
464  if (allow_field_number_ &&
465  safe_strto32(field_name, &field_number)) {
466  if (descriptor->IsExtensionNumber(field_number)) {
467  field = finder_
468  ? finder_->FindExtensionByNumber(descriptor, field_number)
469  : DefaultFinderFindExtensionByNumber(descriptor,
470  field_number);
471  } else if (descriptor->IsReservedNumber(field_number)) {
472  reserved_field = true;
473  } else {
474  field = descriptor->FindFieldByNumber(field_number);
475  }
476  } else {
477  field = descriptor->FindFieldByName(field_name);
478  // Group names are expected to be capitalized as they appear in the
479  // .proto file, which actually matches their type names, not their
480  // field names.
481  if (field == nullptr) {
482  std::string lower_field_name = field_name;
483  LowerString(&lower_field_name);
484  field = descriptor->FindFieldByName(lower_field_name);
485  // If the case-insensitive match worked but the field is NOT a group,
486  if (field != nullptr &&
487  field->type() != FieldDescriptor::TYPE_GROUP) {
488  field = nullptr;
489  }
490  }
491  // Again, special-case group names as described above.
492  if (field != nullptr && field->type() == FieldDescriptor::TYPE_GROUP &&
493  field->message_type()->name() != field_name) {
494  field = nullptr;
495  }
496 
497  if (field == nullptr && allow_case_insensitive_field_) {
498  std::string lower_field_name = field_name;
499  LowerString(&lower_field_name);
500  field = descriptor->FindFieldByLowercaseName(lower_field_name);
501  }
502 
503  if (field == nullptr) {
504  reserved_field = descriptor->IsReservedName(field_name);
505  }
506  }
507 
508  if (field == nullptr && !reserved_field) {
509  if (!allow_unknown_field_) {
510  ReportError("Message type \"" + descriptor->full_name() +
511  "\" has no field named \"" + field_name + "\".");
512  return false;
513  } else {
514  ReportWarning("Message type \"" + descriptor->full_name() +
515  "\" has no field named \"" + field_name + "\".");
516  }
517  }
518  }
519 
520  // Skips unknown or reserved fields.
521  if (field == nullptr) {
522  GOOGLE_CHECK(allow_unknown_field_ || allow_unknown_extension_ || reserved_field);
523 
524  // Try to guess the type of this field.
525  // If this field is not a message, there should be a ":" between the
526  // field name and the field value and also the field value should not
527  // start with "{" or "<" which indicates the beginning of a message body.
528  // If there is no ":" or there is a "{" or "<" after ":", this field has
529  // to be a message or the input is ill-formed.
530  if (TryConsume(":") && !LookingAt("{") && !LookingAt("<")) {
531  return SkipFieldValue();
532  } else {
533  return SkipFieldMessage();
534  }
535  }
536 
537  if (singular_overwrite_policy_ == FORBID_SINGULAR_OVERWRITES) {
538  // Fail if the field is not repeated and it has already been specified.
539  if (!field->is_repeated() && reflection->HasField(*message, field)) {
540  ReportError("Non-repeated field \"" + field_name +
541  "\" is specified multiple times.");
542  return false;
543  }
544  // Fail if the field is a member of a oneof and another member has already
545  // been specified.
546  const OneofDescriptor* oneof = field->containing_oneof();
547  if (oneof != nullptr && reflection->HasOneof(*message, oneof)) {
548  const FieldDescriptor* other_field =
549  reflection->GetOneofFieldDescriptor(*message, oneof);
550  ReportError("Field \"" + field_name +
551  "\" is specified along with "
552  "field \"" +
553  other_field->name() +
554  "\", another member "
555  "of oneof \"" +
556  oneof->name() + "\".");
557  return false;
558  }
559  }
560 
561  // Perform special handling for embedded message types.
562  if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
563  // ':' is optional here.
564  bool consumed_semicolon = TryConsume(":");
565  if (consumed_semicolon && field->options().weak() &&
566  LookingAtType(io::Tokenizer::TYPE_STRING)) {
567  // we are getting a bytes string for a weak field.
568  std::string tmp;
569  DO(ConsumeString(&tmp));
570  MessageFactory* factory =
571  finder_ ? finder_->FindExtensionFactory(field) : nullptr;
572  reflection->MutableMessage(message, field, factory)
573  ->ParseFromString(tmp);
574  goto label_skip_parsing;
575  }
576  } else {
577  // ':' is required here.
578  DO(Consume(":"));
579  }
580 
581  if (field->is_repeated() && TryConsume("[")) {
582  // Short repeated format, e.g. "foo: [1, 2, 3]".
583  if (!TryConsume("]")) {
584  // "foo: []" is treated as empty.
585  while (true) {
586  if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
587  // Perform special handling for embedded message types.
588  DO(ConsumeFieldMessage(message, reflection, field));
589  } else {
590  DO(ConsumeFieldValue(message, reflection, field));
591  }
592  if (TryConsume("]")) {
593  break;
594  }
595  DO(Consume(","));
596  }
597  }
598  } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
599  DO(ConsumeFieldMessage(message, reflection, field));
600  } else {
601  DO(ConsumeFieldValue(message, reflection, field));
602  }
603  label_skip_parsing:
604  // For historical reasons, fields may optionally be separated by commas or
605  // semicolons.
606  TryConsume(";") || TryConsume(",");
607 
608  if (field->options().deprecated()) {
609  ReportWarning("text format contains deprecated field \"" + field_name +
610  "\"");
611  }
612 
613  // If a parse info tree exists, add the location for the parsed
614  // field.
615  if (parse_info_tree_ != nullptr) {
616  RecordLocation(parse_info_tree_, field,
617  ParseLocation(start_line, start_column));
618  }
619 
620  return true;
621  }
622 
623  // Skips the next field including the field's name and value.
624  bool SkipField() {
625  if (TryConsume("[")) {
626  // Extension name or type URL.
627  DO(ConsumeTypeUrlOrFullTypeName());
628  DO(Consume("]"));
629  } else {
630  std::string field_name;
631  DO(ConsumeIdentifier(&field_name));
632  }
633 
634  // Try to guess the type of this field.
635  // If this field is not a message, there should be a ":" between the
636  // field name and the field value and also the field value should not
637  // start with "{" or "<" which indicates the beginning of a message body.
638  // If there is no ":" or there is a "{" or "<" after ":", this field has
639  // to be a message or the input is ill-formed.
640  if (TryConsume(":") && !LookingAt("{") && !LookingAt("<")) {
641  DO(SkipFieldValue());
642  } else {
643  DO(SkipFieldMessage());
644  }
645  // For historical reasons, fields may optionally be separated by commas or
646  // semicolons.
647  TryConsume(";") || TryConsume(",");
648  return true;
649  }
650 
651  bool ConsumeFieldMessage(Message* message, const Reflection* reflection,
652  const FieldDescriptor* field) {
653  if (--recursion_limit_ < 0) {
654  ReportError("Message is too deep");
655  return false;
656  }
657  // If the parse information tree is not nullptr, create a nested one
658  // for the nested message.
659  ParseInfoTree* parent = parse_info_tree_;
660  if (parent != nullptr) {
661  parse_info_tree_ = CreateNested(parent, field);
662  }
663 
664  std::string delimiter;
665  DO(ConsumeMessageDelimiter(&delimiter));
666  MessageFactory* factory =
667  finder_ ? finder_->FindExtensionFactory(field) : nullptr;
668  if (field->is_repeated()) {
669  DO(ConsumeMessage(reflection->AddMessage(message, field, factory),
670  delimiter));
671  } else {
672  DO(ConsumeMessage(reflection->MutableMessage(message, field, factory),
673  delimiter));
674  }
675 
676  ++recursion_limit_;
677 
678  // Reset the parse information tree.
679  parse_info_tree_ = parent;
680  return true;
681  }
682 
683  // Skips the whole body of a message including the beginning delimiter and
684  // the ending delimiter.
686  std::string delimiter;
687  DO(ConsumeMessageDelimiter(&delimiter));
688  while (!LookingAt(">") && !LookingAt("}")) {
689  DO(SkipField());
690  }
691  DO(Consume(delimiter));
692  return true;
693  }
694 
695  bool ConsumeFieldValue(Message* message, const Reflection* reflection,
696  const FieldDescriptor* field) {
697 // Define an easy to use macro for setting fields. This macro checks
698 // to see if the field is repeated (in which case we need to use the Add
699 // methods or not (in which case we need to use the Set methods).
700 #define SET_FIELD(CPPTYPE, VALUE) \
701  if (field->is_repeated()) { \
702  reflection->Add##CPPTYPE(message, field, VALUE); \
703  } else { \
704  reflection->Set##CPPTYPE(message, field, VALUE); \
705  }
706 
707  switch (field->cpp_type()) {
709  int64 value;
710  DO(ConsumeSignedInteger(&value, kint32max));
711  SET_FIELD(Int32, static_cast<int32>(value));
712  break;
713  }
714 
716  uint64 value;
717  DO(ConsumeUnsignedInteger(&value, kuint32max));
718  SET_FIELD(UInt32, static_cast<uint32>(value));
719  break;
720  }
721 
723  int64 value;
724  DO(ConsumeSignedInteger(&value, kint64max));
726  break;
727  }
728 
730  uint64 value;
731  DO(ConsumeUnsignedInteger(&value, kuint64max));
733  break;
734  }
735 
737  double value;
738  DO(ConsumeDouble(&value));
740  break;
741  }
742 
744  double value;
745  DO(ConsumeDouble(&value));
747  break;
748  }
749 
752  DO(ConsumeString(&value));
753  SET_FIELD(String, value);
754  break;
755  }
756 
758  if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) {
759  uint64 value;
760  DO(ConsumeUnsignedInteger(&value, 1));
761  SET_FIELD(Bool, value);
762  } else {
764  DO(ConsumeIdentifier(&value));
765  if (value == "true" || value == "True" || value == "t") {
766  SET_FIELD(Bool, true);
767  } else if (value == "false" || value == "False" || value == "f") {
768  SET_FIELD(Bool, false);
769  } else {
770  ReportError("Invalid value for boolean field \"" + field->name() +
771  "\". Value: \"" + value + "\".");
772  return false;
773  }
774  }
775  break;
776  }
777 
780  int64 int_value = kint64max;
781  const EnumDescriptor* enum_type = field->enum_type();
782  const EnumValueDescriptor* enum_value = nullptr;
783 
784  if (LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) {
785  DO(ConsumeIdentifier(&value));
786  // Find the enumeration value.
787  enum_value = enum_type->FindValueByName(value);
788 
789  } else if (LookingAt("-") ||
790  LookingAtType(io::Tokenizer::TYPE_INTEGER)) {
791  DO(ConsumeSignedInteger(&int_value, kint32max));
792  value = StrCat(int_value); // for error reporting
793  enum_value = enum_type->FindValueByNumber(int_value);
794  } else {
795  ReportError("Expected integer or identifier, got: " +
796  tokenizer_.current().text);
797  return false;
798  }
799 
800  if (enum_value == nullptr) {
801  if (int_value != kint64max &&
802  reflection->SupportsUnknownEnumValues()) {
803  SET_FIELD(EnumValue, int_value);
804  return true;
805  } else if (!allow_unknown_enum_) {
806  ReportError("Unknown enumeration value of \"" + value +
807  "\" for "
808  "field \"" +
809  field->name() + "\".");
810  return false;
811  } else {
812  ReportWarning("Unknown enumeration value of \"" + value +
813  "\" for "
814  "field \"" +
815  field->name() + "\".");
816  return true;
817  }
818  }
819 
820  SET_FIELD(Enum, enum_value);
821  break;
822  }
823 
825  // We should never get here. Put here instead of a default
826  // so that if new types are added, we get a nice compiler warning.
827  GOOGLE_LOG(FATAL) << "Reached an unintended state: CPPTYPE_MESSAGE";
828  break;
829  }
830  }
831 #undef SET_FIELD
832  return true;
833  }
834 
835  bool SkipFieldValue() {
836  if (LookingAtType(io::Tokenizer::TYPE_STRING)) {
837  while (LookingAtType(io::Tokenizer::TYPE_STRING)) {
838  tokenizer_.Next();
839  }
840  return true;
841  }
842  if (TryConsume("[")) {
843  while (true) {
844  if (!LookingAt("{") && !LookingAt("<")) {
845  DO(SkipFieldValue());
846  } else {
847  DO(SkipFieldMessage());
848  }
849  if (TryConsume("]")) {
850  break;
851  }
852  DO(Consume(","));
853  }
854  return true;
855  }
856  // Possible field values other than string:
857  // 12345 => TYPE_INTEGER
858  // -12345 => TYPE_SYMBOL + TYPE_INTEGER
859  // 1.2345 => TYPE_FLOAT
860  // -1.2345 => TYPE_SYMBOL + TYPE_FLOAT
861  // inf => TYPE_IDENTIFIER
862  // -inf => TYPE_SYMBOL + TYPE_IDENTIFIER
863  // TYPE_INTEGER => TYPE_IDENTIFIER
864  // Divides them into two group, one with TYPE_SYMBOL
865  // and the other without:
866  // Group one:
867  // 12345 => TYPE_INTEGER
868  // 1.2345 => TYPE_FLOAT
869  // inf => TYPE_IDENTIFIER
870  // TYPE_INTEGER => TYPE_IDENTIFIER
871  // Group two:
872  // -12345 => TYPE_SYMBOL + TYPE_INTEGER
873  // -1.2345 => TYPE_SYMBOL + TYPE_FLOAT
874  // -inf => TYPE_SYMBOL + TYPE_IDENTIFIER
875  // As we can see, the field value consists of an optional '-' and one of
876  // TYPE_INTEGER, TYPE_FLOAT and TYPE_IDENTIFIER.
877  bool has_minus = TryConsume("-");
878  if (!LookingAtType(io::Tokenizer::TYPE_INTEGER) &&
879  !LookingAtType(io::Tokenizer::TYPE_FLOAT) &&
880  !LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) {
881  std::string text = tokenizer_.current().text;
882  ReportError("Cannot skip field value, unexpected token: " + text);
883  return false;
884  }
885  // Combination of '-' and TYPE_IDENTIFIER may result in an invalid field
886  // value while other combinations all generate valid values.
887  // We check if the value of this combination is valid here.
888  // TYPE_IDENTIFIER after a '-' should be one of the float values listed
889  // below:
890  // inf, inff, infinity, nan
891  if (has_minus && LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) {
892  std::string text = tokenizer_.current().text;
893  LowerString(&text);
894  if (text != "inf" &&
895  text != "infinity" && text != "nan") {
896  ReportError("Invalid float number: " + text);
897  return false;
898  }
899  }
900  tokenizer_.Next();
901  return true;
902  }
903 
904  // Returns true if the current token's text is equal to that specified.
905  bool LookingAt(const std::string& text) {
906  return tokenizer_.current().text == text;
907  }
908 
909  // Returns true if the current token's type is equal to that specified.
911  return tokenizer_.current().type == token_type;
912  }
913 
914  // Consumes an identifier and saves its value in the identifier parameter.
915  // Returns false if the token is not of type IDENTFIER.
916  bool ConsumeIdentifier(std::string* identifier) {
917  if (LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) {
918  *identifier = tokenizer_.current().text;
919  tokenizer_.Next();
920  return true;
921  }
922 
923  // If allow_field_numer_ or allow_unknown_field_ is true, we should able
924  // to parse integer identifiers.
925  if ((allow_field_number_ || allow_unknown_field_ ||
926  allow_unknown_extension_) &&
927  LookingAtType(io::Tokenizer::TYPE_INTEGER)) {
928  *identifier = tokenizer_.current().text;
929  tokenizer_.Next();
930  return true;
931  }
932 
933  ReportError("Expected identifier, got: " + tokenizer_.current().text);
934  return false;
935  }
936 
937  // Consume a string of form "<id1>.<id2>....<idN>".
939  DO(ConsumeIdentifier(name));
940  while (TryConsume(".")) {
941  std::string part;
942  DO(ConsumeIdentifier(&part));
943  *name += ".";
944  *name += part;
945  }
946  return true;
947  }
948 
950  std::string discarded;
951  DO(ConsumeIdentifier(&discarded));
952  while (TryConsume(".") || TryConsume("/")) {
953  DO(ConsumeIdentifier(&discarded));
954  }
955  return true;
956  }
957 
958  // Consumes a string and saves its value in the text parameter.
959  // Returns false if the token is not of type STRING.
961  if (!LookingAtType(io::Tokenizer::TYPE_STRING)) {
962  ReportError("Expected string, got: " + tokenizer_.current().text);
963  return false;
964  }
965 
966  text->clear();
967  while (LookingAtType(io::Tokenizer::TYPE_STRING)) {
968  io::Tokenizer::ParseStringAppend(tokenizer_.current().text, text);
969 
970  tokenizer_.Next();
971  }
972 
973  return true;
974  }
975 
976  // Consumes a uint64 and saves its value in the value parameter.
977  // Returns false if the token is not of type INTEGER.
979  if (!LookingAtType(io::Tokenizer::TYPE_INTEGER)) {
980  ReportError("Expected integer, got: " + tokenizer_.current().text);
981  return false;
982  }
983 
984  if (!io::Tokenizer::ParseInteger(tokenizer_.current().text, max_value,
985  value)) {
986  ReportError("Integer out of range (" + tokenizer_.current().text + ")");
987  return false;
988  }
989 
990  tokenizer_.Next();
991  return true;
992  }
993 
994  // Consumes an int64 and saves its value in the value parameter.
995  // Note that since the tokenizer does not support negative numbers,
996  // we actually may consume an additional token (for the minus sign) in this
997  // method. Returns false if the token is not an integer
998  // (signed or otherwise).
1000  bool negative = false;
1001 
1002  if (TryConsume("-")) {
1003  negative = true;
1004  // Two's complement always allows one more negative integer than
1005  // positive.
1006  ++max_value;
1007  }
1008 
1009  uint64 unsigned_value;
1010 
1011  DO(ConsumeUnsignedInteger(&unsigned_value, max_value));
1012 
1013  if (negative) {
1014  if ((static_cast<uint64>(kint64max) + 1) == unsigned_value) {
1015  *value = kint64min;
1016  } else {
1017  *value = -static_cast<int64>(unsigned_value);
1018  }
1019  } else {
1020  *value = static_cast<int64>(unsigned_value);
1021  }
1022 
1023  return true;
1024  }
1025 
1026  // Consumes a double and saves its value in the value parameter.
1027  // Accepts decimal numbers only, rejects hex or oct numbers.
1028  bool ConsumeUnsignedDecimalAsDouble(double* value, uint64 max_value) {
1029  if (!LookingAtType(io::Tokenizer::TYPE_INTEGER)) {
1030  ReportError("Expected integer, got: " + tokenizer_.current().text);
1031  return false;
1032  }
1033 
1034  const std::string& text = tokenizer_.current().text;
1035  if (IsHexNumber(text) || IsOctNumber(text)) {
1036  ReportError("Expect a decimal number, got: " + text);
1037  return false;
1038  }
1039 
1040  uint64 uint64_value;
1041  if (io::Tokenizer::ParseInteger(text, max_value, &uint64_value)) {
1042  *value = static_cast<double>(uint64_value);
1043  } else {
1044  // Uint64 overflow, attempt to parse as a double instead.
1046  }
1047 
1048  tokenizer_.Next();
1049  return true;
1050  }
1051 
1052  // Consumes a double and saves its value in the value parameter.
1053  // Note that since the tokenizer does not support negative numbers,
1054  // we actually may consume an additional token (for the minus sign) in this
1055  // method. Returns false if the token is not a double
1056  // (signed or otherwise).
1057  bool ConsumeDouble(double* value) {
1058  bool negative = false;
1059 
1060  if (TryConsume("-")) {
1061  negative = true;
1062  }
1063 
1064  // A double can actually be an integer, according to the tokenizer.
1065  // Therefore, we must check both cases here.
1066  if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) {
1067  // We have found an integer value for the double.
1068  DO(ConsumeUnsignedDecimalAsDouble(value, kuint64max));
1069  } else if (LookingAtType(io::Tokenizer::TYPE_FLOAT)) {
1070  // We have found a float value for the double.
1071  *value = io::Tokenizer::ParseFloat(tokenizer_.current().text);
1072 
1073  // Mark the current token as consumed.
1074  tokenizer_.Next();
1075  } else if (LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) {
1076  std::string text = tokenizer_.current().text;
1077  LowerString(&text);
1078  if (text == "inf" ||
1079  text == "infinity") {
1080  *value = std::numeric_limits<double>::infinity();
1081  tokenizer_.Next();
1082  } else if (text == "nan") {
1083  *value = std::numeric_limits<double>::quiet_NaN();
1084  tokenizer_.Next();
1085  } else {
1086  ReportError("Expected double, got: " + text);
1087  return false;
1088  }
1089  } else {
1090  ReportError("Expected double, got: " + tokenizer_.current().text);
1091  return false;
1092  }
1093 
1094  if (negative) {
1095  *value = -*value;
1096  }
1097 
1098  return true;
1099  }
1100 
1101  // Consumes Any::type_url value, of form "type.googleapis.com/full.type.Name"
1102  // or "type.googleprod.com/full.type.Name"
1104  // TODO(saito) Extend Consume() to consume multiple tokens at once, so that
1105  // this code can be written as just DO(Consume(kGoogleApisTypePrefix)).
1106  DO(ConsumeIdentifier(prefix));
1107  while (TryConsume(".")) {
1108  std::string url;
1109  DO(ConsumeIdentifier(&url));
1110  *prefix += "." + url;
1111  }
1112  DO(Consume("/"));
1113  *prefix += "/";
1114  DO(ConsumeFullTypeName(full_type_name));
1115 
1116  return true;
1117  }
1118 
1119  // A helper function for reconstructing Any::value. Consumes a text of
1120  // full_type_name, then serializes it into serialized_value.
1121  bool ConsumeAnyValue(const Descriptor* value_descriptor,
1122  std::string* serialized_value) {
1123  DynamicMessageFactory factory;
1124  const Message* value_prototype = factory.GetPrototype(value_descriptor);
1125  if (value_prototype == nullptr) {
1126  return false;
1127  }
1128  std::unique_ptr<Message> value(value_prototype->New());
1129  std::string sub_delimiter;
1130  DO(ConsumeMessageDelimiter(&sub_delimiter));
1131  DO(ConsumeMessage(value.get(), sub_delimiter));
1132 
1133  if (allow_partial_) {
1134  value->AppendPartialToString(serialized_value);
1135  } else {
1136  if (!value->IsInitialized()) {
1137  ReportError(
1138  "Value of type \"" + value_descriptor->full_name() +
1139  "\" stored in google.protobuf.Any has missing required fields");
1140  return false;
1141  }
1142  value->AppendToString(serialized_value);
1143  }
1144  return true;
1145  }
1146 
1147  // Consumes a token and confirms that it matches that specified in the
1148  // value parameter. Returns false if the token found does not match that
1149  // which was specified.
1150  bool Consume(const std::string& value) {
1151  const std::string& current_value = tokenizer_.current().text;
1152 
1153  if (current_value != value) {
1154  ReportError("Expected \"" + value + "\", found \"" + current_value +
1155  "\".");
1156  return false;
1157  }
1158 
1159  tokenizer_.Next();
1160 
1161  return true;
1162  }
1163 
1164  // Attempts to consume the supplied value. Returns false if a the
1165  // token found does not match the value specified.
1167  if (tokenizer_.current().text == value) {
1168  tokenizer_.Next();
1169  return true;
1170  } else {
1171  return false;
1172  }
1173  }
1174 
1175  // An internal instance of the Tokenizer's error collector, used to
1176  // collect any base-level parse errors and feed them to the ParserImpl.
1178  public:
1180  : parser_(parser) {}
1181 
1183 
1184  void AddError(int line, int column, const std::string& message) override {
1185  parser_->ReportError(line, column, message);
1186  }
1187 
1188  void AddWarning(int line, int column, const std::string& message) override {
1189  parser_->ReportWarning(line, column, message);
1190  }
1191 
1192  private:
1195  };
1196 
1209  const bool allow_partial_;
1212 };
1213 
1214 // ===========================================================================
1215 // Internal class for writing text to the io::ZeroCopyOutputStream. Adapted
1216 // from the Printer found in //net/proto2/io/public/printer.h
1217 class TextFormat::Printer::TextGenerator
1219  public:
1221  int initial_indent_level)
1222  : output_(output),
1223  buffer_(nullptr),
1224  buffer_size_(0),
1225  at_start_of_line_(true),
1226  failed_(false),
1227  indent_level_(initial_indent_level),
1228  initial_indent_level_(initial_indent_level) {}
1229 
1231  // Only BackUp() if we're sure we've successfully called Next() at least
1232  // once.
1233  if (!failed_ && buffer_size_ > 0) {
1234  output_->BackUp(buffer_size_);
1235  }
1236  }
1237 
1238  // Indent text by two spaces. After calling Indent(), two spaces will be
1239  // inserted at the beginning of each line of text. Indent() may be called
1240  // multiple times to produce deeper indents.
1241  void Indent() override { ++indent_level_; }
1242 
1243  // Reduces the current indent level by two spaces, or crashes if the indent
1244  // level is zero.
1245  void Outdent() override {
1246  if (indent_level_ == 0 || indent_level_ < initial_indent_level_) {
1247  GOOGLE_LOG(DFATAL) << " Outdent() without matching Indent().";
1248  return;
1249  }
1250 
1251  --indent_level_;
1252  }
1253 
1254  // Print text to the output stream.
1255  void Print(const char* text, size_t size) override {
1256  if (indent_level_ > 0) {
1257  size_t pos = 0; // The number of bytes we've written so far.
1258  for (size_t i = 0; i < size; i++) {
1259  if (text[i] == '\n') {
1260  // Saw newline. If there is more text, we may need to insert an
1261  // indent here. So, write what we have so far, including the '\n'.
1262  Write(text + pos, i - pos + 1);
1263  pos = i + 1;
1264 
1265  // Setting this true will cause the next Write() to insert an indent
1266  // first.
1267  at_start_of_line_ = true;
1268  }
1269  }
1270  // Write the rest.
1271  Write(text + pos, size - pos);
1272  } else {
1273  Write(text, size);
1274  if (size > 0 && text[size - 1] == '\n') {
1275  at_start_of_line_ = true;
1276  }
1277  }
1278  }
1279 
1280  // True if any write to the underlying stream failed. (We don't just
1281  // crash in this case because this is an I/O failure, not a programming
1282  // error.)
1283  bool failed() const { return failed_; }
1284 
1285  private:
1287 
1288  void Write(const char* data, size_t size) {
1289  if (failed_) return;
1290  if (size == 0) return;
1291 
1292  if (at_start_of_line_) {
1293  // Insert an indent.
1294  at_start_of_line_ = false;
1295  WriteIndent();
1296  if (failed_) return;
1297  }
1298 
1299  while (size > buffer_size_) {
1300  // Data exceeds space in the buffer. Copy what we can and request a
1301  // new buffer.
1302  if (buffer_size_ > 0) {
1303  memcpy(buffer_, data, buffer_size_);
1304  data += buffer_size_;
1305  size -= buffer_size_;
1306  }
1307  void* void_buffer = nullptr;
1308  failed_ = !output_->Next(&void_buffer, &buffer_size_);
1309  if (failed_) return;
1310  buffer_ = reinterpret_cast<char*>(void_buffer);
1311  }
1312 
1313  // Buffer is big enough to receive the data; copy it.
1314  memcpy(buffer_, data, size);
1315  buffer_ += size;
1316  buffer_size_ -= size;
1317  }
1318 
1319  void WriteIndent() {
1320  if (indent_level_ == 0) {
1321  return;
1322  }
1323  GOOGLE_DCHECK(!failed_);
1324  int size = 2 * indent_level_;
1325 
1326  while (size > buffer_size_) {
1327  // Data exceeds space in the buffer. Write what we can and request a new
1328  // buffer.
1329  if (buffer_size_ > 0) {
1330  memset(buffer_, ' ', buffer_size_);
1331  }
1332  size -= buffer_size_;
1333  void* void_buffer;
1334  failed_ = !output_->Next(&void_buffer, &buffer_size_);
1335  if (failed_) return;
1336  buffer_ = reinterpret_cast<char*>(void_buffer);
1337  }
1338 
1339  // Buffer is big enough to receive the data; copy it.
1340  memset(buffer_, ' ', size);
1341  buffer_ += size;
1342  buffer_size_ -= size;
1343  }
1344 
1346  char* buffer_;
1349  bool failed_;
1350 
1353 };
1354 
1355 // ===========================================================================
1356 // Implementation of the default Finder for extensions.
1358 
1360  Message* message, const std::string& name) const {
1361  return DefaultFinderFindExtension(message, name);
1362 }
1363 
1365  const Descriptor* descriptor, int number) const {
1366  return DefaultFinderFindExtensionByNumber(descriptor, number);
1367 }
1368 
1370  const Message& message, const std::string& prefix,
1371  const std::string& name) const {
1372  return DefaultFinderFindAnyType(message, prefix, name);
1373 }
1374 
1376  const FieldDescriptor* field) const {
1377  return nullptr;
1378 }
1379 
1380 // ===========================================================================
1381 
1383  : error_collector_(nullptr),
1384  finder_(nullptr),
1385  parse_info_tree_(nullptr),
1386  allow_partial_(false),
1387  allow_case_insensitive_field_(false),
1388  allow_unknown_field_(false),
1389  allow_unknown_extension_(false),
1390  allow_unknown_enum_(false),
1391  allow_field_number_(false),
1392  allow_relaxed_whitespace_(false),
1393  allow_singular_overwrites_(false),
1394  recursion_limit_(std::numeric_limits<int>::max()) {}
1395 
1397 
1398 namespace {
1399 
1400 bool CheckParseInputSize(StringPiece input,
1401  io::ErrorCollector* error_collector) {
1402  if (input.size() > INT_MAX) {
1403  error_collector->AddError(
1404  -1, 0,
1405  StrCat("Input size too large: ", static_cast<int64>(input.size()),
1406  " bytes", " > ", INT_MAX, " bytes."));
1407  return false;
1408  }
1409  return true;
1410 }
1411 
1412 } // namespace
1413 
1415  Message* output) {
1416  output->Clear();
1417 
1418  ParserImpl::SingularOverwritePolicy overwrites_policy =
1419  allow_singular_overwrites_ ? ParserImpl::ALLOW_SINGULAR_OVERWRITES
1420  : ParserImpl::FORBID_SINGULAR_OVERWRITES;
1421 
1422  ParserImpl parser(output->GetDescriptor(), input, error_collector_, finder_,
1423  parse_info_tree_, overwrites_policy,
1424  allow_case_insensitive_field_, allow_unknown_field_,
1425  allow_unknown_extension_, allow_unknown_enum_,
1426  allow_field_number_, allow_relaxed_whitespace_,
1427  allow_partial_, recursion_limit_);
1428  return MergeUsingImpl(input, output, &parser);
1429 }
1430 
1432  Message* output) {
1433  DO(CheckParseInputSize(input, error_collector_));
1434  io::ArrayInputStream input_stream(input.data(), input.size());
1435  return Parse(&input_stream, output);
1436 }
1437 
1438 
1440  Message* output) {
1441  ParserImpl parser(output->GetDescriptor(), input, error_collector_, finder_,
1442  parse_info_tree_, ParserImpl::ALLOW_SINGULAR_OVERWRITES,
1443  allow_case_insensitive_field_, allow_unknown_field_,
1444  allow_unknown_extension_, allow_unknown_enum_,
1445  allow_field_number_, allow_relaxed_whitespace_,
1446  allow_partial_, recursion_limit_);
1447  return MergeUsingImpl(input, output, &parser);
1448 }
1449 
1451  Message* output) {
1452  DO(CheckParseInputSize(input, error_collector_));
1453  io::ArrayInputStream input_stream(input.data(), input.size());
1454  return Merge(&input_stream, output);
1455 }
1456 
1457 
1459  Message* output,
1460  ParserImpl* parser_impl) {
1461  if (!parser_impl->Parse(output)) return false;
1462  if (!allow_partial_ && !output->IsInitialized()) {
1463  std::vector<std::string> missing_fields;
1464  output->FindInitializationErrors(&missing_fields);
1465  parser_impl->ReportError(-1, 0,
1466  "Message missing required fields: " +
1467  Join(missing_fields, ", "));
1468  return false;
1469  }
1470  return true;
1471 }
1472 
1474  const FieldDescriptor* field,
1475  Message* output) {
1476  io::ArrayInputStream input_stream(input.data(), input.size());
1478  output->GetDescriptor(), &input_stream, error_collector_, finder_,
1479  parse_info_tree_, ParserImpl::ALLOW_SINGULAR_OVERWRITES,
1480  allow_case_insensitive_field_, allow_unknown_field_,
1481  allow_unknown_extension_, allow_unknown_enum_, allow_field_number_,
1482  allow_relaxed_whitespace_, allow_partial_, recursion_limit_);
1483  return parser.ParseField(field, output);
1484 }
1485 
1487  Message* output) {
1488  return Parser().Parse(input, output);
1489 }
1490 
1492  Message* output) {
1493  return Parser().Merge(input, output);
1494 }
1495 
1497  Message* output) {
1498  return Parser().ParseFromString(input, output);
1499 }
1500 
1502  Message* output) {
1503  return Parser().MergeFromString(input, output);
1504 }
1505 
1506 
1507 #undef DO
1508 
1509 // ===========================================================================
1510 
1512 
1513 namespace {
1514 
1515 // A BaseTextGenerator that writes to a string.
1516 class StringBaseTextGenerator : public TextFormat::BaseTextGenerator {
1517  public:
1518  void Print(const char* text, size_t size) override {
1519  output_.append(text, size);
1520  }
1521 
1522 // Some compilers do not support ref-qualifiers even in C++11 mode.
1523 // Disable the optimization for now and revisit it later.
1524 #if 0 // LANG_CXX11
1525  std::string Consume() && { return std::move(output_); }
1526 #else // !LANG_CXX11
1527  const std::string& Get() { return output_; }
1528 #endif // LANG_CXX11
1529 
1530  private:
1532 };
1533 
1534 } // namespace
1535 
1536 // The default implementation for FieldValuePrinter. We just delegate the
1537 // implementation to the default FastFieldValuePrinter to avoid duplicating the
1538 // logic.
1539 TextFormat::FieldValuePrinter::FieldValuePrinter() {}
1540 TextFormat::FieldValuePrinter::~FieldValuePrinter() {}
1541 
1542 #if 0 // LANG_CXX11
1543 #define FORWARD_IMPL(fn, ...) \
1544  StringBaseTextGenerator generator; \
1545  delegate_.fn(__VA_ARGS__, &generator); \
1546  return std::move(generator).Consume()
1547 #else // !LANG_CXX11
1548 #define FORWARD_IMPL(fn, ...) \
1549  StringBaseTextGenerator generator; \
1550  delegate_.fn(__VA_ARGS__, &generator); \
1551  return generator.Get()
1552 #endif // LANG_CXX11
1553 
1554 std::string TextFormat::FieldValuePrinter::PrintBool(bool val) const {
1555  FORWARD_IMPL(PrintBool, val);
1556 }
1557 std::string TextFormat::FieldValuePrinter::PrintInt32(int32 val) const {
1558  FORWARD_IMPL(PrintInt32, val);
1559 }
1560 std::string TextFormat::FieldValuePrinter::PrintUInt32(uint32 val) const {
1561  FORWARD_IMPL(PrintUInt32, val);
1562 }
1563 std::string TextFormat::FieldValuePrinter::PrintInt64(int64 val) const {
1564  FORWARD_IMPL(PrintInt64, val);
1565 }
1566 std::string TextFormat::FieldValuePrinter::PrintUInt64(uint64 val) const {
1567  FORWARD_IMPL(PrintUInt64, val);
1568 }
1569 std::string TextFormat::FieldValuePrinter::PrintFloat(float val) const {
1570  FORWARD_IMPL(PrintFloat, val);
1571 }
1572 std::string TextFormat::FieldValuePrinter::PrintDouble(double val) const {
1573  FORWARD_IMPL(PrintDouble, val);
1574 }
1575 std::string TextFormat::FieldValuePrinter::PrintString(
1576  const std::string& val) const {
1577  FORWARD_IMPL(PrintString, val);
1578 }
1579 std::string TextFormat::FieldValuePrinter::PrintBytes(
1580  const std::string& val) const {
1581  return PrintString(val);
1582 }
1583 std::string TextFormat::FieldValuePrinter::PrintEnum(
1584  int32 val, const std::string& name) const {
1585  FORWARD_IMPL(PrintEnum, val, name);
1586 }
1587 std::string TextFormat::FieldValuePrinter::PrintFieldName(
1588  const Message& message, const Reflection* reflection,
1589  const FieldDescriptor* field) const {
1590  FORWARD_IMPL(PrintFieldName, message, reflection, field);
1591 }
1592 std::string TextFormat::FieldValuePrinter::PrintMessageStart(
1593  const Message& message, int field_index, int field_count,
1594  bool single_line_mode) const {
1595  FORWARD_IMPL(PrintMessageStart, message, field_index, field_count,
1596  single_line_mode);
1597 }
1598 std::string TextFormat::FieldValuePrinter::PrintMessageEnd(
1599  const Message& message, int field_index, int field_count,
1600  bool single_line_mode) const {
1601  FORWARD_IMPL(PrintMessageEnd, message, field_index, field_count,
1602  single_line_mode);
1603 }
1604 #undef FORWARD_IMPL
1605 
1609  bool val, BaseTextGenerator* generator) const {
1610  if (val) {
1611  generator->PrintLiteral("true");
1612  } else {
1613  generator->PrintLiteral("false");
1614  }
1615 }
1617  int32 val, BaseTextGenerator* generator) const {
1618  generator->PrintString(StrCat(val));
1619 }
1621  uint32 val, BaseTextGenerator* generator) const {
1622  generator->PrintString(StrCat(val));
1623 }
1625  int64 val, BaseTextGenerator* generator) const {
1626  generator->PrintString(StrCat(val));
1627 }
1629  uint64 val, BaseTextGenerator* generator) const {
1630  generator->PrintString(StrCat(val));
1631 }
1633  float val, BaseTextGenerator* generator) const {
1634  generator->PrintString(SimpleFtoa(val));
1635 }
1637  double val, BaseTextGenerator* generator) const {
1638  generator->PrintString(SimpleDtoa(val));
1639 }
1641  int32 val, const std::string& name, BaseTextGenerator* generator) const {
1642  generator->PrintString(name);
1643 }
1644 
1646  const std::string& val, BaseTextGenerator* generator) const {
1647  generator->PrintLiteral("\"");
1648  generator->PrintString(CEscape(val));
1649  generator->PrintLiteral("\"");
1650 }
1652  const std::string& val, BaseTextGenerator* generator) const {
1653  PrintString(val, generator);
1654 }
1656  const Message& message, int field_index, int field_count,
1657  const Reflection* reflection, const FieldDescriptor* field,
1658  BaseTextGenerator* generator) const {
1659  PrintFieldName(message, reflection, field, generator);
1660 }
1662  const Message& message, const Reflection* reflection,
1663  const FieldDescriptor* field, BaseTextGenerator* generator) const {
1664  if (field->is_extension()) {
1665  generator->PrintLiteral("[");
1666  generator->PrintString(field->PrintableNameForExtension());
1667  generator->PrintLiteral("]");
1668  } else if (field->type() == FieldDescriptor::TYPE_GROUP) {
1669  // Groups must be serialized with their original capitalization.
1670  generator->PrintString(field->message_type()->name());
1671  } else {
1672  generator->PrintString(field->name());
1673  }
1674 }
1676  const Message& message, int field_index, int field_count,
1677  bool single_line_mode, BaseTextGenerator* generator) const {
1678  if (single_line_mode) {
1679  generator->PrintLiteral(" { ");
1680  } else {
1681  generator->PrintLiteral(" {\n");
1682  }
1683 }
1685  const Message& message, int field_index, int field_count,
1686  bool single_line_mode, BaseTextGenerator* generator) const {
1687  if (single_line_mode) {
1688  generator->PrintLiteral("} ");
1689  } else {
1690  generator->PrintLiteral("}\n");
1691  }
1692 }
1693 
1694 namespace {
1695 
1696 // A legacy compatibility wrapper. Takes ownership of the delegate.
1697 class FieldValuePrinterWrapper : public TextFormat::FastFieldValuePrinter {
1698  public:
1699  explicit FieldValuePrinterWrapper(
1700  const TextFormat::FieldValuePrinter* delegate)
1701  : delegate_(delegate) {}
1702 
1703  void SetDelegate(const TextFormat::FieldValuePrinter* delegate) {
1704  delegate_.reset(delegate);
1705  }
1706 
1707  void PrintBool(bool val,
1708  TextFormat::BaseTextGenerator* generator) const override {
1709  generator->PrintString(delegate_->PrintBool(val));
1710  }
1711  void PrintInt32(int32 val,
1712  TextFormat::BaseTextGenerator* generator) const override {
1713  generator->PrintString(delegate_->PrintInt32(val));
1714  }
1715  void PrintUInt32(uint32 val,
1716  TextFormat::BaseTextGenerator* generator) const override {
1717  generator->PrintString(delegate_->PrintUInt32(val));
1718  }
1719  void PrintInt64(int64 val,
1720  TextFormat::BaseTextGenerator* generator) const override {
1721  generator->PrintString(delegate_->PrintInt64(val));
1722  }
1723  void PrintUInt64(uint64 val,
1724  TextFormat::BaseTextGenerator* generator) const override {
1725  generator->PrintString(delegate_->PrintUInt64(val));
1726  }
1727  void PrintFloat(float val,
1728  TextFormat::BaseTextGenerator* generator) const override {
1729  generator->PrintString(delegate_->PrintFloat(val));
1730  }
1731  void PrintDouble(double val,
1732  TextFormat::BaseTextGenerator* generator) const override {
1733  generator->PrintString(delegate_->PrintDouble(val));
1734  }
1735  void PrintString(const std::string& val,
1736  TextFormat::BaseTextGenerator* generator) const override {
1737  generator->PrintString(delegate_->PrintString(val));
1738  }
1739  void PrintBytes(const std::string& val,
1740  TextFormat::BaseTextGenerator* generator) const override {
1741  generator->PrintString(delegate_->PrintBytes(val));
1742  }
1743  void PrintEnum(int32 val, const std::string& name,
1744  TextFormat::BaseTextGenerator* generator) const override {
1745  generator->PrintString(delegate_->PrintEnum(val, name));
1746  }
1747  void PrintFieldName(const Message& message, int field_index, int field_count,
1748  const Reflection* reflection,
1749  const FieldDescriptor* field,
1750  TextFormat::BaseTextGenerator* generator) const override {
1751  generator->PrintString(
1752  delegate_->PrintFieldName(message, reflection, field));
1753  }
1754  void PrintFieldName(const Message& message, const Reflection* reflection,
1755  const FieldDescriptor* field,
1756  TextFormat::BaseTextGenerator* generator) const override {
1757  generator->PrintString(
1758  delegate_->PrintFieldName(message, reflection, field));
1759  }
1760  void PrintMessageStart(
1761  const Message& message, int field_index, int field_count,
1762  bool single_line_mode,
1763  TextFormat::BaseTextGenerator* generator) const override {
1764  generator->PrintString(delegate_->PrintMessageStart(
1765  message, field_index, field_count, single_line_mode));
1766  }
1767  void PrintMessageEnd(
1768  const Message& message, int field_index, int field_count,
1769  bool single_line_mode,
1770  TextFormat::BaseTextGenerator* generator) const override {
1771  generator->PrintString(delegate_->PrintMessageEnd(
1772  message, field_index, field_count, single_line_mode));
1773  }
1774 
1775  private:
1776  std::unique_ptr<const TextFormat::FieldValuePrinter> delegate_;
1777 };
1778 
1779 // Our own specialization: for UTF8 escaped strings.
1780 class FastFieldValuePrinterUtf8Escaping
1781  : public TextFormat::FastFieldValuePrinter {
1782  public:
1783  void PrintString(const std::string& val,
1784  TextFormat::BaseTextGenerator* generator) const override {
1785  generator->PrintLiteral("\"");
1786  generator->PrintString(strings::Utf8SafeCEscape(val));
1787  generator->PrintLiteral("\"");
1788  }
1789  void PrintBytes(const std::string& val,
1790  TextFormat::BaseTextGenerator* generator) const override {
1791  return FastFieldValuePrinter::PrintString(val, generator);
1792  }
1793 };
1794 
1795 } // namespace
1796 
1798  : initial_indent_level_(0),
1799  single_line_mode_(false),
1800  use_field_number_(false),
1801  use_short_repeated_primitives_(false),
1802  hide_unknown_fields_(false),
1803  print_message_fields_in_index_order_(false),
1804  expand_any_(false),
1805  truncate_string_field_longer_than_(0LL),
1806  finder_(nullptr) {
1807  SetUseUtf8StringEscaping(false);
1808 }
1809 
1811  STLDeleteValues(&custom_printers_);
1812  STLDeleteValues(&custom_message_printers_);
1813 }
1814 
1816  SetDefaultFieldValuePrinter(as_utf8 ? new FastFieldValuePrinterUtf8Escaping()
1817  : new FastFieldValuePrinter());
1818 }
1819 
1821  const FieldValuePrinter* printer) {
1822  default_field_value_printer_.reset(new FieldValuePrinterWrapper(printer));
1823 }
1824 
1826  const FastFieldValuePrinter* printer) {
1827  default_field_value_printer_.reset(printer);
1828 }
1829 
1831  const FieldDescriptor* field, const FieldValuePrinter* printer) {
1832  if (field == nullptr || printer == nullptr) {
1833  return false;
1834  }
1835  FieldValuePrinterWrapper* const wrapper =
1836  new FieldValuePrinterWrapper(nullptr);
1837  if (custom_printers_.insert(std::make_pair(field, wrapper)).second) {
1838  wrapper->SetDelegate(printer);
1839  return true;
1840  } else {
1841  delete wrapper;
1842  return false;
1843  }
1844 }
1845 
1847  const FieldDescriptor* field, const FastFieldValuePrinter* printer) {
1848  return field != nullptr && printer != nullptr &&
1849  custom_printers_.insert(std::make_pair(field, printer)).second;
1850 }
1851 
1853  const Descriptor* descriptor, const MessagePrinter* printer) {
1854  return descriptor != nullptr && printer != nullptr &&
1855  custom_message_printers_.insert(std::make_pair(descriptor, printer))
1856  .second;
1857 }
1858 
1860  std::string* output) const {
1861  GOOGLE_DCHECK(output) << "output specified is nullptr";
1862 
1863  output->clear();
1864  io::StringOutputStream output_stream(output);
1865 
1866  return Print(message, &output_stream);
1867 }
1868 
1870  const UnknownFieldSet& unknown_fields, std::string* output) const {
1871  GOOGLE_DCHECK(output) << "output specified is nullptr";
1872 
1873  output->clear();
1874  io::StringOutputStream output_stream(output);
1875  return PrintUnknownFields(unknown_fields, &output_stream);
1876 }
1877 
1880  TextGenerator generator(output, initial_indent_level_);
1881 
1882  Print(message, &generator);
1883 
1884  // Output false if the generator failed internally.
1885  return !generator.failed();
1886 }
1887 
1889  const UnknownFieldSet& unknown_fields,
1891  TextGenerator generator(output, initial_indent_level_);
1892 
1893  PrintUnknownFields(unknown_fields, &generator);
1894 
1895  // Output false if the generator failed internally.
1896  return !generator.failed();
1897 }
1898 
1899 namespace {
1900 // Comparison functor for sorting FieldDescriptors by field index.
1901 // Normal fields have higher precedence than extensions.
1902 struct FieldIndexSorter {
1903  bool operator()(const FieldDescriptor* left,
1904  const FieldDescriptor* right) const {
1905  if (left->is_extension() && right->is_extension()) {
1906  return left->number() < right->number();
1907  } else if (left->is_extension()) {
1908  return false;
1909  } else if (right->is_extension()) {
1910  return true;
1911  } else {
1912  return left->index() < right->index();
1913  }
1914  }
1915 };
1916 
1917 } // namespace
1918 
1920  TextGenerator* generator) const {
1921  const FieldDescriptor* type_url_field;
1922  const FieldDescriptor* value_field;
1923  if (!internal::GetAnyFieldDescriptors(message, &type_url_field,
1924  &value_field)) {
1925  return false;
1926  }
1927 
1928  const Reflection* reflection = message.GetReflection();
1929 
1930  // Extract the full type name from the type_url field.
1931  const std::string& type_url = reflection->GetString(message, type_url_field);
1932  std::string url_prefix;
1933  std::string full_type_name;
1934  if (!internal::ParseAnyTypeUrl(type_url, &url_prefix, &full_type_name)) {
1935  return false;
1936  }
1937 
1938  // Print the "value" in text.
1939  const Descriptor* value_descriptor =
1940  finder_ ? finder_->FindAnyType(message, url_prefix, full_type_name)
1941  : DefaultFinderFindAnyType(message, url_prefix, full_type_name);
1942  if (value_descriptor == nullptr) {
1943  GOOGLE_LOG(WARNING) << "Proto type " << type_url << " not found";
1944  return false;
1945  }
1946  DynamicMessageFactory factory;
1947  std::unique_ptr<Message> value_message(
1948  factory.GetPrototype(value_descriptor)->New());
1949  std::string serialized_value = reflection->GetString(message, value_field);
1950  if (!value_message->ParseFromString(serialized_value)) {
1951  GOOGLE_LOG(WARNING) << type_url << ": failed to parse contents";
1952  return false;
1953  }
1954  generator->PrintLiteral("[");
1955  generator->PrintString(type_url);
1956  generator->PrintLiteral("]");
1957  const FastFieldValuePrinter* printer = FindWithDefault(
1958  custom_printers_, value_field, default_field_value_printer_.get());
1959  printer->PrintMessageStart(message, -1, 0, single_line_mode_, generator);
1960  generator->Indent();
1961  Print(*value_message, generator);
1962  generator->Outdent();
1963  printer->PrintMessageEnd(message, -1, 0, single_line_mode_, generator);
1964  return true;
1965 }
1966 
1968  TextGenerator* generator) const {
1969  const Reflection* reflection = message.GetReflection();
1970  if (!reflection) {
1971  // This message does not provide any way to describe its structure.
1972  // Parse it again in an UnknownFieldSet, and display this instead.
1973  UnknownFieldSet unknown_fields;
1974  {
1975  std::string serialized = message.SerializeAsString();
1976  io::ArrayInputStream input(serialized.data(), serialized.size());
1977  unknown_fields.ParseFromZeroCopyStream(&input);
1978  }
1979  PrintUnknownFields(unknown_fields, generator);
1980  return;
1981  }
1982  const Descriptor* descriptor = message.GetDescriptor();
1983  auto itr = custom_message_printers_.find(descriptor);
1984  if (itr != custom_message_printers_.end()) {
1985  itr->second->Print(message, single_line_mode_, generator);
1986  return;
1987  }
1988  if (descriptor->full_name() == internal::kAnyFullTypeName && expand_any_ &&
1989  PrintAny(message, generator)) {
1990  return;
1991  }
1992  std::vector<const FieldDescriptor*> fields;
1993  if (descriptor->options().map_entry()) {
1994  fields.push_back(descriptor->field(0));
1995  fields.push_back(descriptor->field(1));
1996  } else {
1997  reflection->ListFields(message, &fields);
1998  }
1999 
2000  if (print_message_fields_in_index_order_) {
2001  std::sort(fields.begin(), fields.end(), FieldIndexSorter());
2002  }
2003  for (int i = 0; i < fields.size(); i++) {
2004  PrintField(message, reflection, fields[i], generator);
2005  }
2006  if (!hide_unknown_fields_) {
2007  PrintUnknownFields(reflection->GetUnknownFields(message), generator);
2008  }
2009 }
2010 
2012  const FieldDescriptor* field,
2013  int index,
2014  std::string* output) const {
2015  GOOGLE_DCHECK(output) << "output specified is nullptr";
2016 
2017  output->clear();
2018  io::StringOutputStream output_stream(output);
2019  TextGenerator generator(&output_stream, initial_indent_level_);
2020 
2021  PrintFieldValue(message, message.GetReflection(), field, index, &generator);
2022 }
2023 
2025  public:
2027  : field_(descriptor->field(0)) {}
2028 
2029  bool operator()(const Message* a, const Message* b) {
2030  const Reflection* reflection = a->GetReflection();
2031  switch (field_->cpp_type()) {
2033  bool first = reflection->GetBool(*a, field_);
2034  bool second = reflection->GetBool(*b, field_);
2035  return first < second;
2036  }
2038  int32 first = reflection->GetInt32(*a, field_);
2039  int32 second = reflection->GetInt32(*b, field_);
2040  return first < second;
2041  }
2043  int64 first = reflection->GetInt64(*a, field_);
2044  int64 second = reflection->GetInt64(*b, field_);
2045  return first < second;
2046  }
2048  uint32 first = reflection->GetUInt32(*a, field_);
2049  uint32 second = reflection->GetUInt32(*b, field_);
2050  return first < second;
2051  }
2053  uint64 first = reflection->GetUInt64(*a, field_);
2054  uint64 second = reflection->GetUInt64(*b, field_);
2055  return first < second;
2056  }
2058  std::string first = reflection->GetString(*a, field_);
2059  std::string second = reflection->GetString(*b, field_);
2060  return first < second;
2061  }
2062  default:
2063  GOOGLE_LOG(DFATAL) << "Invalid key for map field.";
2064  return true;
2065  }
2066  }
2067 
2068  private:
2070 };
2071 
2072 namespace internal {
2074  public:
2075  // DynamicMapSorter::Sort cannot be used because it enfores syncing with
2076  // repeated field.
2077  static bool SortMap(const Message& message, const Reflection* reflection,
2078  const FieldDescriptor* field, MessageFactory* factory,
2079  std::vector<const Message*>* sorted_map_field);
2080  static void CopyKey(const MapKey& key, Message* message,
2081  const FieldDescriptor* field_desc);
2082  static void CopyValue(const MapValueRef& value, Message* message,
2083  const FieldDescriptor* field_desc);
2084 };
2085 
2086 // Returns true if elements contained in sorted_map_field need to be released.
2087 bool MapFieldPrinterHelper::SortMap(
2088  const Message& message, const Reflection* reflection,
2089  const FieldDescriptor* field, MessageFactory* factory,
2090  std::vector<const Message*>* sorted_map_field) {
2091  bool need_release = false;
2092  const MapFieldBase& base = *reflection->GetMapData(message, field);
2093 
2094  if (base.IsRepeatedFieldValid()) {
2095  const RepeatedPtrField<Message>& map_field =
2096  reflection->GetRepeatedPtrField<Message>(message, field);
2097  for (int i = 0; i < map_field.size(); ++i) {
2098  sorted_map_field->push_back(
2099  const_cast<RepeatedPtrField<Message>*>(&map_field)->Mutable(i));
2100  }
2101  } else {
2102  // TODO(teboring): For performance, instead of creating map entry message
2103  // for each element, just store map keys and sort them.
2104  const Descriptor* map_entry_desc = field->message_type();
2105  const Message* prototype = factory->GetPrototype(map_entry_desc);
2106  for (MapIterator iter =
2107  reflection->MapBegin(const_cast<Message*>(&message), field);
2108  iter != reflection->MapEnd(const_cast<Message*>(&message), field);
2109  ++iter) {
2110  Message* map_entry_message = prototype->New();
2111  CopyKey(iter.GetKey(), map_entry_message, map_entry_desc->field(0));
2112  CopyValue(iter.GetValueRef(), map_entry_message,
2113  map_entry_desc->field(1));
2114  sorted_map_field->push_back(map_entry_message);
2115  }
2116  need_release = true;
2117  }
2118 
2119  MapEntryMessageComparator comparator(field->message_type());
2120  std::stable_sort(sorted_map_field->begin(), sorted_map_field->end(),
2121  comparator);
2122  return need_release;
2123 }
2124 
2125 void MapFieldPrinterHelper::CopyKey(const MapKey& key, Message* message,
2126  const FieldDescriptor* field_desc) {
2127  const Reflection* reflection = message->GetReflection();
2128  switch (field_desc->cpp_type()) {
2133  GOOGLE_LOG(ERROR) << "Not supported.";
2134  break;
2136  reflection->SetString(message, field_desc, key.GetStringValue());
2137  return;
2139  reflection->SetInt64(message, field_desc, key.GetInt64Value());
2140  return;
2142  reflection->SetInt32(message, field_desc, key.GetInt32Value());
2143  return;
2145  reflection->SetUInt64(message, field_desc, key.GetUInt64Value());
2146  return;
2148  reflection->SetUInt32(message, field_desc, key.GetUInt32Value());
2149  return;
2151  reflection->SetBool(message, field_desc, key.GetBoolValue());
2152  return;
2153  }
2154 }
2155 
2156 void MapFieldPrinterHelper::CopyValue(const MapValueRef& value,
2157  Message* message,
2158  const FieldDescriptor* field_desc) {
2159  const Reflection* reflection = message->GetReflection();
2160  switch (field_desc->cpp_type()) {
2162  reflection->SetDouble(message, field_desc, value.GetDoubleValue());
2163  return;
2165  reflection->SetFloat(message, field_desc, value.GetFloatValue());
2166  return;
2168  reflection->SetEnumValue(message, field_desc, value.GetEnumValue());
2169  return;
2171  Message* sub_message = value.GetMessageValue().New();
2172  sub_message->CopyFrom(value.GetMessageValue());
2173  reflection->SetAllocatedMessage(message, sub_message, field_desc);
2174  return;
2175  }
2177  reflection->SetString(message, field_desc, value.GetStringValue());
2178  return;
2180  reflection->SetInt64(message, field_desc, value.GetInt64Value());
2181  return;
2183  reflection->SetInt32(message, field_desc, value.GetInt32Value());
2184  return;
2186  reflection->SetUInt64(message, field_desc, value.GetUInt64Value());
2187  return;
2189  reflection->SetUInt32(message, field_desc, value.GetUInt32Value());
2190  return;
2192  reflection->SetBool(message, field_desc, value.GetBoolValue());
2193  return;
2194  }
2195 }
2196 } // namespace internal
2197 
2199  const Reflection* reflection,
2200  const FieldDescriptor* field,
2201  TextGenerator* generator) const {
2202  if (use_short_repeated_primitives_ && field->is_repeated() &&
2203  field->cpp_type() != FieldDescriptor::CPPTYPE_STRING &&
2204  field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
2205  PrintShortRepeatedField(message, reflection, field, generator);
2206  return;
2207  }
2208 
2209  int count = 0;
2210 
2211  if (field->is_repeated()) {
2212  count = reflection->FieldSize(message, field);
2213  } else if (reflection->HasField(message, field) ||
2214  field->containing_type()->options().map_entry()) {
2215  count = 1;
2216  }
2217 
2218  DynamicMessageFactory factory;
2219  std::vector<const Message*> sorted_map_field;
2220  bool need_release = false;
2221  bool is_map = field->is_map();
2222  if (is_map) {
2224  message, reflection, field, &factory, &sorted_map_field);
2225  }
2226 
2227  for (int j = 0; j < count; ++j) {
2228  const int field_index = field->is_repeated() ? j : -1;
2229 
2230  PrintFieldName(message, field_index, count, reflection, field, generator);
2231 
2232  if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
2233  const FastFieldValuePrinter* printer = FindWithDefault(
2234  custom_printers_, field, default_field_value_printer_.get());
2235  const Message& sub_message =
2236  field->is_repeated()
2237  ? (is_map ? *sorted_map_field[j]
2238  : reflection->GetRepeatedMessage(message, field, j))
2239  : reflection->GetMessage(message, field);
2240  printer->PrintMessageStart(sub_message, field_index, count,
2241  single_line_mode_, generator);
2242  generator->Indent();
2243  Print(sub_message, generator);
2244  generator->Outdent();
2245  printer->PrintMessageEnd(sub_message, field_index, count,
2246  single_line_mode_, generator);
2247  } else {
2248  generator->PrintLiteral(": ");
2249  // Write the field value.
2250  PrintFieldValue(message, reflection, field, field_index, generator);
2251  if (single_line_mode_) {
2252  generator->PrintLiteral(" ");
2253  } else {
2254  generator->PrintLiteral("\n");
2255  }
2256  }
2257  }
2258 
2259  if (need_release) {
2260  for (int j = 0; j < sorted_map_field.size(); ++j) {
2261  delete sorted_map_field[j];
2262  }
2263  }
2264 }
2265 
2267  const Message& message, const Reflection* reflection,
2268  const FieldDescriptor* field, TextGenerator* generator) const {
2269  // Print primitive repeated field in short form.
2270  int size = reflection->FieldSize(message, field);
2271  PrintFieldName(message, /*field_index=*/-1, /*field_count=*/size, reflection,
2272  field, generator);
2273  generator->PrintLiteral(": [");
2274  for (int i = 0; i < size; i++) {
2275  if (i > 0) generator->PrintLiteral(", ");
2276  PrintFieldValue(message, reflection, field, i, generator);
2277  }
2278  if (single_line_mode_) {
2279  generator->PrintLiteral("] ");
2280  } else {
2281  generator->PrintLiteral("]\n");
2282  }
2283 }
2284 
2286  int field_index, int field_count,
2287  const Reflection* reflection,
2288  const FieldDescriptor* field,
2289  TextGenerator* generator) const {
2290  // if use_field_number_ is true, prints field number instead
2291  // of field name.
2292  if (use_field_number_) {
2293  generator->PrintString(StrCat(field->number()));
2294  return;
2295  }
2296 
2297  const FastFieldValuePrinter* printer = FindWithDefault(
2298  custom_printers_, field, default_field_value_printer_.get());
2299  printer->PrintFieldName(message, field_index, field_count, reflection, field,
2300  generator);
2301 }
2302 
2304  const Reflection* reflection,
2305  const FieldDescriptor* field,
2306  int index,
2307  TextGenerator* generator) const {
2308  GOOGLE_DCHECK(field->is_repeated() || (index == -1))
2309  << "Index must be -1 for non-repeated fields";
2310 
2311  const FastFieldValuePrinter* printer = FindWithDefault(
2312  custom_printers_, field, default_field_value_printer_.get());
2313 
2314  switch (field->cpp_type()) {
2315 #define OUTPUT_FIELD(CPPTYPE, METHOD) \
2316  case FieldDescriptor::CPPTYPE_##CPPTYPE: \
2317  printer->Print##METHOD( \
2318  field->is_repeated() \
2319  ? reflection->GetRepeated##METHOD(message, field, index) \
2320  : reflection->Get##METHOD(message, field), \
2321  generator); \
2322  break
2323 
2324  OUTPUT_FIELD(INT32, Int32);
2325  OUTPUT_FIELD(INT64, Int64);
2326  OUTPUT_FIELD(UINT32, UInt32);
2327  OUTPUT_FIELD(UINT64, UInt64);
2328  OUTPUT_FIELD(FLOAT, Float);
2329  OUTPUT_FIELD(DOUBLE, Double);
2330  OUTPUT_FIELD(BOOL, Bool);
2331 #undef OUTPUT_FIELD
2332 
2334  std::string scratch;
2335  const std::string& value =
2336  field->is_repeated()
2338  &scratch)
2339  : reflection->GetStringReference(message, field, &scratch);
2340  const std::string* value_to_print = &value;
2341  std::string truncated_value;
2342  if (truncate_string_field_longer_than_ > 0 &&
2343  truncate_string_field_longer_than_ < value.size()) {
2344  truncated_value = value.substr(0, truncate_string_field_longer_than_) +
2345  "...<truncated>...";
2346  value_to_print = &truncated_value;
2347  }
2348  if (field->type() == FieldDescriptor::TYPE_STRING) {
2349  printer->PrintString(*value_to_print, generator);
2350  } else {
2352  printer->PrintBytes(*value_to_print, generator);
2353  }
2354  break;
2355  }
2356 
2358  int enum_value =
2359  field->is_repeated()
2360  ? reflection->GetRepeatedEnumValue(message, field, index)
2361  : reflection->GetEnumValue(message, field);
2362  const EnumValueDescriptor* enum_desc =
2363  field->enum_type()->FindValueByNumber(enum_value);
2364  if (enum_desc != nullptr) {
2365  printer->PrintEnum(enum_value, enum_desc->name(), generator);
2366  } else {
2367  // Ordinarily, enum_desc should not be null, because proto2 has the
2368  // invariant that set enum field values must be in-range, but with the
2369  // new integer-based API for enums (or the RepeatedField<int> loophole),
2370  // it is possible for the user to force an unknown integer value. So we
2371  // simply use the integer value itself as the enum value name in this
2372  // case.
2373  printer->PrintEnum(enum_value, StringPrintf("%d", enum_value),
2374  generator);
2375  }
2376  break;
2377  }
2378 
2380  Print(field->is_repeated()
2381  ? reflection->GetRepeatedMessage(message, field, index)
2382  : reflection->GetMessage(message, field),
2383  generator);
2384  break;
2385  }
2386 }
2387 
2388 /* static */ bool TextFormat::Print(const Message& message,
2390  return Printer().Print(message, output);
2391 }
2392 
2394  const UnknownFieldSet& unknown_fields, io::ZeroCopyOutputStream* output) {
2395  return Printer().PrintUnknownFields(unknown_fields, output);
2396 }
2397 
2398 /* static */ bool TextFormat::PrintToString(const Message& message,
2399  std::string* output) {
2400  return Printer().PrintToString(message, output);
2401 }
2402 
2404  const UnknownFieldSet& unknown_fields, std::string* output) {
2405  return Printer().PrintUnknownFieldsToString(unknown_fields, output);
2406 }
2407 
2409  const Message& message, const FieldDescriptor* field, int index,
2410  std::string* output) {
2412 }
2413 
2417 }
2418 
2420  const UnknownFieldSet& unknown_fields, TextGenerator* generator) const {
2421  for (int i = 0; i < unknown_fields.field_count(); i++) {
2422  const UnknownField& field = unknown_fields.field(i);
2423  std::string field_number = StrCat(field.number());
2424 
2425  switch (field.type()) {
2427  generator->PrintString(field_number);
2428  generator->PrintLiteral(": ");
2429  generator->PrintString(StrCat(field.varint()));
2430  if (single_line_mode_) {
2431  generator->PrintLiteral(" ");
2432  } else {
2433  generator->PrintLiteral("\n");
2434  }
2435  break;
2437  generator->PrintString(field_number);
2438  generator->PrintLiteral(": 0x");
2439  generator->PrintString(
2440  StrCat(strings::Hex(field.fixed32(), strings::ZERO_PAD_8)));
2441  if (single_line_mode_) {
2442  generator->PrintLiteral(" ");
2443  } else {
2444  generator->PrintLiteral("\n");
2445  }
2446  break;
2447  }
2449  generator->PrintString(field_number);
2450  generator->PrintLiteral(": 0x");
2451  generator->PrintString(
2452  StrCat(strings::Hex(field.fixed64(), strings::ZERO_PAD_16)));
2453  if (single_line_mode_) {
2454  generator->PrintLiteral(" ");
2455  } else {
2456  generator->PrintLiteral("\n");
2457  }
2458  break;
2459  }
2461  generator->PrintString(field_number);
2462  const std::string& value = field.length_delimited();
2463  UnknownFieldSet embedded_unknown_fields;
2464  if (!value.empty() && embedded_unknown_fields.ParseFromString(value)) {
2465  // This field is parseable as a Message.
2466  // So it is probably an embedded message.
2467  if (single_line_mode_) {
2468  generator->PrintLiteral(" { ");
2469  } else {
2470  generator->PrintLiteral(" {\n");
2471  generator->Indent();
2472  }
2473  PrintUnknownFields(embedded_unknown_fields, generator);
2474  if (single_line_mode_) {
2475  generator->PrintLiteral("} ");
2476  } else {
2477  generator->Outdent();
2478  generator->PrintLiteral("}\n");
2479  }
2480  } else {
2481  // This field is not parseable as a Message.
2482  // So it is probably just a plain string.
2483  generator->PrintLiteral(": \"");
2484  generator->PrintString(CEscape(value));
2485  if (single_line_mode_) {
2486  generator->PrintLiteral("\" ");
2487  } else {
2488  generator->PrintLiteral("\"\n");
2489  }
2490  }
2491  break;
2492  }
2494  generator->PrintString(field_number);
2495  if (single_line_mode_) {
2496  generator->PrintLiteral(" { ");
2497  } else {
2498  generator->PrintLiteral(" {\n");
2499  generator->Indent();
2500  }
2501  PrintUnknownFields(field.group(), generator);
2502  if (single_line_mode_) {
2503  generator->PrintLiteral("} ");
2504  } else {
2505  generator->Outdent();
2506  generator->PrintLiteral("}\n");
2507  }
2508  break;
2509  }
2510  }
2511 }
2512 
2513 } // namespace protobuf
2514 } // namespace google
google::protobuf::Descriptor::full_name
const std::string & full_name() const
google::protobuf::strings::ZERO_PAD_16
@ ZERO_PAD_16
Definition: strutil.h:591
google::protobuf::io::Printer::TextGenerator::buffer_
char * buffer_
Definition: text_format.cc:1346
zero_copy_stream.h
google::protobuf::TextFormat::ParseInfoTree::RecordLocation
void RecordLocation(const FieldDescriptor *field, ParseLocation location)
Definition: text_format.cc:140
google::protobuf::TextFormat::Parser::ParserImpl::singular_overwrite_policy_
SingularOverwritePolicy singular_overwrite_policy_
Definition: text_format.cc:1203
google::protobuf::Reflection::GetString
std::string GetString(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1151
google::protobuf::TextFormat::Printer::SetSingleLineMode
void SetSingleLineMode(bool single_line_mode)
Definition: text_format.h:262
google::protobuf::TextFormat::ParseInfoTree::~ParseInfoTree
~ParseInfoTree()
Definition: text_format.cc:133
google::protobuf::Message::DebugString
std::string DebugString() const
Definition: text_format.cc:87
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeTypeUrlOrFullTypeName
bool ConsumeTypeUrlOrFullTypeName()
Definition: text_format.cc:949
google::protobuf::TextFormat::Parser::Parse
bool Parse(io::ZeroCopyInputStream *input, Message *output)
Definition: text_format.cc:1414
google::protobuf::FindWithDefault
const Collection::value_type::second_type & FindWithDefault(const Collection &collection, const typename Collection::value_type::first_type &key, const typename Collection::value_type::second_type &value)
Definition: map_util.h:123
Json::UInt64
unsigned long long int UInt64
Definition: json.h:241
google::protobuf::TextFormat::Printer::PrintUnknownFieldsToString
bool PrintUnknownFieldsToString(const UnknownFieldSet &unknown_fields, std::string *output) const
Definition: text_format.cc:1869
google::protobuf::Reflection::GetStringReference
const std::string & GetStringReference(const Message &message, const FieldDescriptor *field, std::string *scratch) const
Definition: generated_message_reflection.cc:1171
google::protobuf::io::Printer::TextGenerator::Write
void Write(const char *data, size_t size)
Definition: text_format.cc:1288
google::protobuf::UnknownField::TYPE_FIXED64
@ TYPE_FIXED64
Definition: unknown_field_set.h:228
google::protobuf::FieldDescriptor::CPPTYPE_ENUM
@ CPPTYPE_ENUM
Definition: src/google/protobuf/descriptor.h:561
google::protobuf::RepeatedPtrField
Definition: command_line_interface.h:62
name
GLuint const GLchar * name
Definition: glcorearb.h:3055
google::protobuf::TextFormat::FastFieldValuePrinter::PrintDouble
virtual void PrintDouble(double val, BaseTextGenerator *generator) const
Definition: text_format.cc:1636
google::protobuf::io::Printer::TextGenerator::Outdent
void Outdent() override
Definition: text_format.cc:1245
OUTPUT_FIELD
#define OUTPUT_FIELD(CPPTYPE, METHOD)
google::protobuf::TextFormat::FastFieldValuePrinter::PrintFieldName
virtual void PrintFieldName(const Message &message, int field_index, int field_count, const Reflection *reflection, const FieldDescriptor *field, BaseTextGenerator *generator) const
Definition: text_format.cc:1655
google::protobuf::value
const Descriptor::ReservedRange value
Definition: src/google/protobuf/descriptor.h:1954
map_util.h
google::protobuf::FieldDescriptor::CPPTYPE_STRING
@ CPPTYPE_STRING
Definition: src/google/protobuf/descriptor.h:562
google::protobuf::FieldDescriptor
Definition: src/google/protobuf/descriptor.h:515
google::protobuf::TextFormat::MessagePrinter
Definition: text_format.h:188
google::protobuf::io::Tokenizer::TYPE_FLOAT
@ TYPE_FLOAT
Definition: tokenizer.h:115
google::protobuf::TextFormat::Print
static bool Print(const Message &message, io::ZeroCopyOutputStream *output)
Definition: text_format.cc:2388
google::protobuf::Reflection::SetBool
void SetBool(Message *message, const FieldDescriptor *field, bool value) const
google::protobuf.internal.decoder.SkipField
def SkipField
Definition: decoder.py:1016
google::protobuf::SimpleDtoa
string SimpleDtoa(double value)
Definition: strutil.cc:1219
google::protobuf::io::Tokenizer::TYPE_IDENTIFIER
@ TYPE_IDENTIFIER
Definition: tokenizer.h:105
wire_format_lite.h
zero_copy_stream_impl.h
google::protobuf::io::Tokenizer::TokenType
TokenType
Definition: tokenizer.h:101
google::protobuf::TextFormat::Parser::ParserImpl::allow_unknown_enum_
const bool allow_unknown_enum_
Definition: text_format.cc:1207
google::protobuf::TextFormat::Printer::PrintFieldValueToString
void PrintFieldValueToString(const Message &message, const FieldDescriptor *field, int index, std::string *output) const
Definition: text_format.cc:2011
Bool
Definition: gtest_pred_impl_unittest.cc:56
google::protobuf::TextFormat::Parser::ParserImpl::allow_field_number_
const bool allow_field_number_
Definition: text_format.cc:1208
google::protobuf::int64
int64_t int64
Definition: protobuf/src/google/protobuf/stubs/port.h:151
google::protobuf::FieldDescriptor::is_extension
bool is_extension() const
google::protobuf::safe_strto32
bool safe_strto32(const string &str, int32 *value)
Definition: strutil.cc:1364
google::protobuf::StrCat
string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: strutil.cc:1480
google::protobuf::TextFormat::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TextFormat)
google::protobuf::io::Tokenizer::ParseInteger
static bool ParseInteger(const std::string &text, uint64 max_value, uint64 *output)
Definition: tokenizer.cc:862
google::protobuf::FieldDescriptor::CPPTYPE_UINT64
@ CPPTYPE_UINT64
Definition: src/google/protobuf/descriptor.h:557
google::protobuf::UnknownField::TYPE_FIXED32
@ TYPE_FIXED32
Definition: unknown_field_set.h:227
input
std::string input
Definition: tokenizer_unittest.cc:197
google::protobuf::Reflection::GetUInt32
uint32 GetUInt32(const Message &message, const FieldDescriptor *field) const
base
Definition: logging.cc:2162
google::protobuf.internal::ParseAnyTypeUrl
bool ParseAnyTypeUrl(const std::string &type_url, std::string *full_type_name)
Definition: any_lite.cc:117
google::protobuf::io::Tokenizer
Definition: tokenizer.h:93
FATAL
const int FATAL
Definition: log_severity.h:60
google::protobuf::TextFormat::BaseTextGenerator::PrintLiteral
void PrintLiteral(const char(&text)[n])
Definition: text_format.h:113
google::protobuf::Reflection::GetRepeatedStringReference
const std::string & GetRepeatedStringReference(const Message &message, const FieldDescriptor *field, int index, std::string *scratch) const
Definition: generated_message_reflection.cc:1241
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeField
bool ConsumeField(Message *message)
Definition: text_format.cc:395
google::protobuf::FieldDescriptor::TYPE_BYTES
@ TYPE_BYTES
Definition: src/google/protobuf/descriptor.h:538
google::protobuf.text_format.PrintField
def PrintField(field, value, out, indent=0, as_utf8=False, as_one_line=False, use_short_repeated_primitives=False, pointy_brackets=False, use_index_order=False, float_format=None, double_format=None, message_formatter=None, print_unknown_fields=False)
Definition: text_format.py:233
GOOGLE_DCHECK
#define GOOGLE_DCHECK
Definition: logging.h:194
google::protobuf::UnknownField::TYPE_VARINT
@ TYPE_VARINT
Definition: unknown_field_set.h:226
google::protobuf::TextFormat::Parser
Definition: text_format.h:509
tokenizer.h
google::protobuf::UnknownFieldSet::ParseFromZeroCopyStream
bool ParseFromZeroCopyStream(io::ZeroCopyInputStream *input)
Definition: unknown_field_set.cc:229
google::protobuf::TextFormat::Printer::PrintToString
bool PrintToString(const Message &message, std::string *output) const
Definition: text_format.cc:1859
google::protobuf::io::SafeDoubleToFloat
float SafeDoubleToFloat(double value)
Definition: strtod.cc:116
google::protobuf::FieldDescriptor::CPPTYPE_INT64
@ CPPTYPE_INT64
Definition: src/google/protobuf/descriptor.h:555
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeIdentifier
bool ConsumeIdentifier(std::string *identifier)
Definition: text_format.cc:916
google::protobuf::python::descriptor::Get
static PyObject * Get(PyContainer *self, PyObject *args)
Definition: descriptor_containers.cc:455
google::protobuf::TextFormat::FastFieldValuePrinter::PrintUInt64
virtual void PrintUInt64(uint64 val, BaseTextGenerator *generator) const
Definition: text_format.cc:1628
google::protobuf.internal::kAnyFullTypeName
const char kAnyFullTypeName[]
Definition: any_lite.cc:53
google::protobuf::FieldDescriptor::CPPTYPE_UINT32
@ CPPTYPE_UINT32
Definition: src/google/protobuf/descriptor.h:556
google::protobuf::io::Printer::TextGenerator::buffer_size_
int buffer_size_
Definition: text_format.cc:1347
google::protobuf::uint32
uint32_t uint32
Definition: protobuf/src/google/protobuf/stubs/port.h:155
google::protobuf::Message::CopyFrom
virtual void CopyFrom(const Message &from)
Definition: src/google/protobuf/message.cc:98
google::protobuf::TextFormat::PrintUnknownFields
static bool PrintUnknownFields(const UnknownFieldSet &unknown_fields, io::ZeroCopyOutputStream *output)
Definition: text_format.cc:2393
google::protobuf::TextFormat::Parser::ParserImpl::allow_case_insensitive_field_
const bool allow_case_insensitive_field_
Definition: text_format.cc:1204
google::protobuf::UnknownField
Definition: unknown_field_set.h:223
google::protobuf::CEscape
string CEscape(const string &src)
Definition: strutil.cc:615
google::protobuf::Reflection::SetAllocatedMessage
void SetAllocatedMessage(Message *message, Message *sub_message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1530
google::protobuf::TextFormat::Parser::ParserImpl::ReportWarning
void ReportWarning(int line, int col, const std::string &message)
Definition: text_format.cc:336
google::protobuf::MessageFactory::GetPrototype
virtual const Message * GetPrototype(const Descriptor *type)=0
SET_FIELD
#define SET_FIELD(CPPTYPE, VALUE)
google::protobuf::Message::ShortDebugString
std::string ShortDebugString() const
Definition: text_format.cc:98
google::protobuf::Reflection::SetDouble
void SetDouble(Message *message, const FieldDescriptor *field, double value) const
google::protobuf::Reflection::SupportsUnknownEnumValues
bool SupportsUnknownEnumValues() const
Definition: generated_message_reflection.cc:1823
google::protobuf::OneofDescriptor
Definition: src/google/protobuf/descriptor.h:843
google::protobuf::TextFormat::Parser::ParserImpl::~ParserImpl
~ParserImpl()
Definition: text_format.cc:293
google::protobuf::TextFormat::FastFieldValuePrinter::PrintMessageStart
virtual void PrintMessageStart(const Message &message, int field_index, int field_count, bool single_line_mode, BaseTextGenerator *generator) const
Definition: text_format.cc:1675
google::protobuf::TextFormat::Printer::PrintUnknownFields
bool PrintUnknownFields(const UnknownFieldSet &unknown_fields, io::ZeroCopyOutputStream *output) const
Definition: text_format.cc:1888
left
GLint left
Definition: glcorearb.h:4150
google::protobuf::io::ErrorCollector::AddError
virtual void AddError(int line, ColumnNumber column, const std::string &message)=0
dynamic_message.h
google::protobuf::TextFormat::Parser::ParserImpl::ReportError
void ReportError(const std::string &message)
Definition: text_format.cc:356
google::protobuf::TextFormat::CreateNested
static ParseInfoTree * CreateNested(ParseInfoTree *info_tree, const FieldDescriptor *field)
Definition: text_format.h:619
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf::Reflection::SetInt64
void SetInt64(Message *message, const FieldDescriptor *field, int64 value) const
google::protobuf::io::Printer::TextGenerator::failed
bool failed() const
Definition: text_format.cc:1283
google::protobuf::Reflection::SetString
void SetString(Message *message, const FieldDescriptor *field, const std::string &value) const
Definition: generated_message_reflection.cc:1193
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeFieldValue
bool ConsumeFieldValue(Message *message, const Reflection *reflection, const FieldDescriptor *field)
Definition: text_format.cc:695
google::protobuf::TextFormat::ParseLocation
Definition: text_format.h:456
google::protobuf::TextFormat::Printer::RegisterFieldValuePrinter
bool RegisterFieldValuePrinter(const FieldDescriptor *field, const FieldValuePrinter *printer)
Definition: text_format.cc:1830
google::protobuf::TextFormat::Parser::ParserImpl::SkipFieldValue
bool SkipFieldValue()
Definition: text_format.cc:835
enum_type
zend_class_entry * enum_type
Definition: php/ext/google/protobuf/message.c:1904
google::protobuf::TextFormat::PrintUnknownFieldsToString
static bool PrintUnknownFieldsToString(const UnknownFieldSet &unknown_fields, std::string *output)
Definition: text_format.cc:2403
google::protobuf::kint64min
static const int64 kint64min
Definition: protobuf/src/google/protobuf/stubs/port.h:162
google::protobuf::Reflection
Definition: src/google/protobuf/message.h:400
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
google::protobuf::OneofDescriptor::name
const std::string & name() const
google::protobuf::TextFormat::Parser::Parser
Parser()
Definition: text_format.cc:1382
google::protobuf::Reflection::HasField
bool HasField(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:728
google::protobuf::TextFormat::Parser::ParserImpl::allow_partial_
const bool allow_partial_
Definition: text_format.cc:1209
EnumValue
Definition: type.pb.h:1012
google::protobuf::Reflection::GetBool
bool GetBool(const Message &message, const FieldDescriptor *field) const
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeAnyValue
bool ConsumeAnyValue(const Descriptor *value_descriptor, std::string *serialized_value)
Definition: text_format.cc:1121
testing::internal::Int32
TypeWithSize< 4 >::Int Int32
Definition: gtest-port.h:2241
FORWARD_IMPL
#define FORWARD_IMPL(fn,...)
Definition: text_format.cc:1548
google::protobuf::MessageFactory
Definition: src/google/protobuf/message.h:1069
google::protobuf::CheckFieldIndex
void CheckFieldIndex(const FieldDescriptor *field, int index)
Definition: text_format.cc:155
Enum
Definition: type.pb.h:797
Descriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:113
google::protobuf::UnknownFieldSet::ParseFromString
bool ParseFromString(const std::string &data)
Definition: unknown_field_set.h:168
google::protobuf::TextFormat::Parser::ParserImpl::ReportWarning
void ReportWarning(const std::string &message)
Definition: text_format.cc:363
google::protobuf::Reflection::GetOneofFieldDescriptor
const FieldDescriptor * GetOneofFieldDescriptor(const Message &message, const OneofDescriptor *oneof_descriptor) const
Definition: generated_message_reflection.cc:1752
google::protobuf::TextFormat::FastFieldValuePrinter::PrintInt64
virtual void PrintInt64(int64 val, BaseTextGenerator *generator) const
Definition: text_format.cc:1624
map_field.h
google::protobuf::TextFormat::Parser::ParserImpl::Consume
bool Consume(const std::string &value)
Definition: text_format.cc:1150
google::protobuf::RepeatedPtrField::Mutable
Element * Mutable(int index)
Definition: repeated_field.h:2030
google::protobuf::TextFormat::Parser::ParserImpl::error_collector_
io::ErrorCollector * error_collector_
Definition: text_format.cc:1197
output_
std::string output_
Definition: text_format.cc:1531
google::protobuf::UnknownFieldSet::field_count
int field_count() const
Definition: unknown_field_set.h:311
google::protobuf::Reflection::SetUInt64
void SetUInt64(Message *message, const FieldDescriptor *field, uint64 value) const
google::protobuf::TextFormat::Printer::RegisterMessagePrinter
bool RegisterMessagePrinter(const Descriptor *descriptor, const MessagePrinter *printer)
Definition: text_format.cc:1852
google::protobuf::TextFormat::Printer::PrintAny
bool PrintAny(const Message &message, TextGenerator *generator) const
Definition: text_format.cc:1919
google::protobuf::EnumValueDescriptor::name
const std::string & name() const
testing::internal::Double
FloatingPoint< double > Double
Definition: gtest-internal.h:429
b
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:3228
google::protobuf::TextFormat::FastFieldValuePrinter::PrintMessageEnd
virtual void PrintMessageEnd(const Message &message, int field_index, int field_count, bool single_line_mode, BaseTextGenerator *generator) const
Definition: text_format.cc:1684
DO
#define DO(STATEMENT)
Definition: text_format.cc:237
testing::internal::UInt32
TypeWithSize< 4 >::UInt UInt32
Definition: gtest-port.h:2242
google::protobuf::TextFormat::Parser::ParserImpl::LookingAt
bool LookingAt(const std::string &text)
Definition: text_format.cc:905
FieldDescriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:129
google::protobuf::TextFormat::Parser::ParseFromString
bool ParseFromString(const std::string &input, Message *output)
Definition: text_format.cc:1431
google::protobuf::Descriptor::field
const FieldDescriptor * field(int index) const
google::protobuf::TextFormat::Parser::ParserImpl::root_message_type_
const Descriptor * root_message_type_
Definition: text_format.cc:1202
google::protobuf::TextFormat::ParseFieldValueFromString
static bool ParseFieldValueFromString(const std::string &input, const FieldDescriptor *field, Message *message)
Definition: text_format.cc:2414
google::protobuf::TextFormat::Parser::ParserImpl::recursion_limit_
int recursion_limit_
Definition: text_format.cc:1210
parser_
std::unique_ptr< Parser > parser_
Definition: parser_unittest.cc:187
google::protobuf::int32
int32_t int32
Definition: protobuf/src/google/protobuf/stubs/port.h:150
google::protobuf::io::Printer::TextGenerator::TextGenerator
TextGenerator(io::ZeroCopyOutputStream *output, int initial_indent_level)
Definition: text_format.cc:1220
google::protobuf::TextFormat::Printer::PrintShortRepeatedField
void PrintShortRepeatedField(const Message &message, const Reflection *reflection, const FieldDescriptor *field, TextGenerator *generator) const
Definition: text_format.cc:2266
google::protobuf::TextFormat::Parser::ParserImpl::ReportError
void ReportError(int line, int col, const std::string &message)
Definition: text_format.cc:320
google::protobuf::TextFormat::ParseInfoTree::GetTreeForNested
ParseInfoTree * GetTreeForNested(const FieldDescriptor *field, int index) const
Definition: text_format.cc:185
google::protobuf::FindOrNull
const Collection::value_type::second_type * FindOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:137
google::protobuf::TextFormat::Finder::FindExtension
virtual const FieldDescriptor * FindExtension(Message *message, const std::string &name) const
Definition: text_format.cc:1359
google::protobuf::Message::PrintDebugString
void PrintDebugString() const
Definition: text_format.cc:126
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeFullTypeName
bool ConsumeFullTypeName(std::string *name)
Definition: text_format.cc:938
google::protobuf::TextFormat::Parser::ParserImpl::ParserErrorCollector::~ParserErrorCollector
~ParserErrorCollector() override
Definition: text_format.cc:1182
any.h
google::protobuf::TextFormat::ParseInfoTree
Definition: text_format.h:467
google::protobuf::TextFormat::Parser::MergeUsingImpl
bool MergeUsingImpl(io::ZeroCopyInputStream *input, Message *output, ParserImpl *parser_impl)
Definition: text_format.cc:1458
strutil.h
google::protobuf::TextFormat::RecordLocation
static void RecordLocation(ParseInfoTree *info_tree, const FieldDescriptor *field, ParseLocation location)
Definition: text_format.h:613
unknown_field_set.h
google::protobuf::TextFormat::Parser::ParserImpl::allow_unknown_extension_
const bool allow_unknown_extension_
Definition: text_format.cc:1206
google::protobuf::TextFormat::FastFieldValuePrinter::PrintBool
virtual void PrintBool(bool val, BaseTextGenerator *generator) const
Definition: text_format.cc:1608
google::protobuf::TextFormat::Finder::FindExtensionByNumber
virtual const FieldDescriptor * FindExtensionByNumber(const Descriptor *descriptor, int number) const
Definition: text_format.cc:1364
google::protobuf.internal::kTypeGoogleApisComPrefix
const char kTypeGoogleApisComPrefix[]
Definition: any_lite.cc:54
google::protobuf::TextFormat::BaseTextGenerator
Definition: text_format.h:100
google::protobuf::io::Tokenizer::SH_COMMENT_STYLE
@ SH_COMMENT_STYLE
Definition: tokenizer.h:236
testing::internal::Float
FloatingPoint< float > Float
Definition: gtest-internal.h:428
coded_stream.h
prefix
static const char prefix[]
Definition: test_pair_ipc.cpp:26
google::protobuf::Reflection::HasOneof
bool HasOneof(const Message &message, const OneofDescriptor *oneof_descriptor) const
Definition: generated_message_reflection.cc:2021
google::protobuf::TextFormat::Printer::PrintFieldValue
void PrintFieldValue(const Message &message, const Reflection *reflection, const FieldDescriptor *field, int index, TextGenerator *generator) const
Definition: text_format.cc:2303
google::protobuf::StringPiece
Definition: stringpiece.h:180
google::protobuf::io::Printer::TextGenerator
Definition: text_format.cc:1217
google::protobuf::TextFormat::ParseFromString
static bool ParseFromString(const std::string &input, Message *output)
Definition: text_format.cc:1496
google::protobuf::TextFormat::Printer::SetDefaultFieldValuePrinter
void SetDefaultFieldValuePrinter(const FastFieldValuePrinter *printer)
Definition: text_format.cc:1825
google::protobuf::MapEntryMessageComparator::field_
const FieldDescriptor * field_
Definition: text_format.cc:2069
update_failure_list.str
str
Definition: update_failure_list.py:41
google::protobuf::TextFormat::Printer
Definition: text_format.h:234
google::protobuf::TextFormat::FastFieldValuePrinter::PrintBytes
virtual void PrintBytes(const std::string &val, BaseTextGenerator *generator) const
Definition: text_format.cc:1651
google::protobuf::io::Tokenizer::ParseFloat
static double ParseFloat(const std::string &text)
Definition: tokenizer.cc:901
google::protobuf::TextFormat::Parser::ParserImpl::tokenizer_
io::Tokenizer tokenizer_
Definition: text_format.cc:1201
google::protobuf.internal::GetAnyFieldDescriptors
bool GetAnyFieldDescriptors(const Message &message, const FieldDescriptor **type_url_field, const FieldDescriptor **value_field)
Definition: any.cc:64
google::protobuf::TextFormat::Printer::SetUseUtf8StringEscaping
void SetUseUtf8StringEscaping(bool as_utf8)
Definition: text_format.cc:1815
message.h
google::protobuf::STLDeleteElements
void STLDeleteElements(T *container)
Definition: stl_util.h:99
google::protobuf::Reflection::GetUnknownFields
const UnknownFieldSet & GetUnknownFields(const Message &message) const
Definition: generated_message_reflection.cc:232
google::protobuf::Reflection::GetRepeatedEnumValue
int GetRepeatedEnumValue(const Message &message, const FieldDescriptor *field, int index) const
Definition: generated_message_reflection.cc:1356
google::protobuf::Reflection::SetInt32
void SetInt32(Message *message, const FieldDescriptor *field, int32 value) const
google::protobuf::TextFormat::Printer::SetExpandAny
void SetExpandAny(bool expand)
Definition: text_format.h:320
google::protobuf::FieldDescriptor::number
int number() const
GOOGLE_LOG
#define GOOGLE_LOG(LEVEL)
Definition: logging.h:146
google::protobuf::TextFormat::FastFieldValuePrinter::PrintString
virtual void PrintString(const std::string &val, BaseTextGenerator *generator) const
Definition: text_format.cc:1645
google::protobuf::io::Printer::TextGenerator::Print
void Print(const char *text, size_t size) override
Definition: text_format.cc:1255
strtod.h
google::protobuf::io::ArrayInputStream
Definition: zero_copy_stream_impl_lite.h:65
google::protobuf::TextFormat::Parser::MergeFromString
bool MergeFromString(const std::string &input, Message *output)
Definition: text_format.cc:1450
google::protobuf::TextFormat::Parser::~Parser
~Parser()
Definition: text_format.cc:1396
google::protobuf::Reflection::MapBegin
MapIterator MapBegin(Message *message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1787
google::protobuf::TextFormat::Parser::ParserImpl::allow_unknown_field_
const bool allow_unknown_field_
Definition: text_format.cc:1205
google::protobuf::uint64
uint64_t uint64
Definition: protobuf/src/google/protobuf/stubs/port.h:156
size
#define size
Definition: glcorearb.h:2944
google::protobuf::TextFormat::FastFieldValuePrinter::PrintInt32
virtual void PrintInt32(int32 val, BaseTextGenerator *generator) const
Definition: text_format.cc:1616
repeated_field.h
google::protobuf::TextFormat::Finder::FindExtensionFactory
virtual MessageFactory * FindExtensionFactory(const FieldDescriptor *field) const
Definition: text_format.cc:1375
google::protobuf::WARNING
static const LogLevel WARNING
Definition: protobuf/src/google/protobuf/testing/googletest.h:71
google::protobuf::TextFormat::Parser::ParserImpl::TryConsume
bool TryConsume(const std::string &value)
Definition: text_format.cc:1166
google::protobuf::FieldDescriptor::TYPE_STRING
@ TYPE_STRING
Definition: src/google/protobuf/descriptor.h:534
google::protobuf::TextFormat::ParseInfoTree::CreateNested
ParseInfoTree * CreateNested(const FieldDescriptor *field)
Definition: text_format.cc:145
google::protobuf::io::Tokenizer::TYPE_STRING
@ TYPE_STRING
Definition: tokenizer.h:118
text_format.h
google::protobuf.internal::MapFieldPrinterHelper::SortMap
static bool SortMap(const Message &message, const Reflection *reflection, const FieldDescriptor *field, MessageFactory *factory, std::vector< const Message * > *sorted_map_field)
Definition: text_format.cc:2087
google::protobuf::Reflection::GetRepeatedPtrField
const RepeatedPtrField< T > & GetRepeatedPtrField(const Message &, const FieldDescriptor *) const
google::protobuf::io::Tokenizer::ParseStringAppend
static void ParseStringAppend(const std::string &text, std::string *output)
Definition: tokenizer.cc:1034
google::protobuf::StringPrintf
string StringPrintf(const char *format,...)
Definition: stringprintf.cc:109
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeDouble
bool ConsumeDouble(double *value)
Definition: text_format.cc:1057
google::protobuf::TextFormat::Parser::ParserImpl::had_errors_
bool had_errors_
Definition: text_format.cc:1211
google::protobuf::SimpleFtoa
string SimpleFtoa(float value)
Definition: strutil.cc:1224
google::protobuf::TextFormat::ParseInfoTree::GetLocation
ParseLocation GetLocation(const FieldDescriptor *field, int index) const
Definition: text_format.cc:169
field
const FieldDescriptor * field
Definition: parser_unittest.cc:2694
google::protobuf::TextFormat::Finder
Definition: text_format.h:201
google::protobuf::Reflection::FieldSize
int FieldSize(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:744
google::protobuf::ERROR
static const LogLevel ERROR
Definition: protobuf/src/google/protobuf/testing/googletest.h:70
google::protobuf::TextFormat::Parser::ParserImpl::ParserErrorCollector
Definition: text_format.cc:1177
key
const SETUP_TEARDOWN_TESTCONTEXT char * key
Definition: test_wss_transport.cpp:10
google::protobuf::Reflection::GetInt32
int32 GetInt32(const Message &message, const FieldDescriptor *field) const
google::protobuf::LowerString
void LowerString(string *s)
Definition: strutil.h:177
google::protobuf::io::Printer::TextGenerator::initial_indent_level_
int initial_indent_level_
Definition: text_format.cc:1352
google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE
@ CPPTYPE_DOUBLE
Definition: src/google/protobuf/descriptor.h:558
google::protobuf::TextFormat::Finder::~Finder
virtual ~Finder()
Definition: text_format.cc:1357
google::protobuf::Reflection::MutableMessage
Message * MutableMessage(Message *message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
Definition: generated_message_reflection.cc:1462
location
GLint location
Definition: glcorearb.h:3074
google::protobuf::TextFormat::Parser::ParserImpl::ParserErrorCollector::AddError
void AddError(int line, int column, const std::string &message) override
Definition: text_format.cc:1184
GOOGLE_CHECK
#define GOOGLE_CHECK(EXPRESSION)
Definition: logging.h:153
google::protobuf::TextFormat::Parser::ParserImpl::ParserErrorCollector::AddWarning
void AddWarning(int line, int column, const std::string &message) override
Definition: text_format.cc:1188
google::protobuf::Message::Utf8DebugString
std::string Utf8DebugString() const
Definition: text_format.cc:114
google::protobuf::strings::Utf8SafeCEscape
string Utf8SafeCEscape(const string &src)
Definition: strutil.cc:623
google::protobuf::TextFormat::FastFieldValuePrinter
Definition: text_format.h:122
google::protobuf::TextFormat::Parser::ParserImpl::finder_
const TextFormat::Finder * finder_
Definition: text_format.cc:1198
LL
#define LL(x)
google::protobuf::io::ZeroCopyInputStream
Definition: zero_copy_stream.h:126
google::protobuf::io::Printer::TextGenerator::~TextGenerator
~TextGenerator()
Definition: text_format.cc:1230
i
int i
Definition: gmock-matchers_test.cc:764
google::protobuf::RepeatedPtrField::size
int size() const
Definition: repeated_field.h:2009
google::protobuf::kuint32max
static const uint32 kuint32max
Definition: protobuf/src/google/protobuf/stubs/port.h:163
google::protobuf::TextFormat::Parser::ParserImpl::SingularOverwritePolicy
SingularOverwritePolicy
Definition: text_format.cc:249
google::protobuf::io::Printer::TextGenerator::Indent
void Indent() override
Definition: text_format.cc:1241
google::protobuf::TextFormat::Parser::ParseFieldValueFromString
bool ParseFieldValueFromString(const std::string &input, const FieldDescriptor *field, Message *output)
Definition: text_format.cc:1473
google::protobuf::TextFormat::Parser::ParserImpl::ParserErrorCollector::parser_
TextFormat::Parser::ParserImpl * parser_
Definition: text_format.cc:1194
google::protobuf::DynamicMessageFactory
Definition: dynamic_message.h:80
google::protobuf::MapEntryMessageComparator
Definition: text_format.cc:2024
fields
static const upb_fielddef fields[107]
Definition: ruby/ext/google/protobuf_c/upb.c:7671
google::protobuf::FieldDescriptor::CPPTYPE_FLOAT
@ CPPTYPE_FLOAT
Definition: src/google/protobuf/descriptor.h:559
google::protobuf::FieldDescriptor::CPPTYPE_BOOL
@ CPPTYPE_BOOL
Definition: src/google/protobuf/descriptor.h:560
google::protobuf::UnknownField::TYPE_GROUP
@ TYPE_GROUP
Definition: unknown_field_set.h:230
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeFieldMessage
bool ConsumeFieldMessage(Message *message, const Reflection *reflection, const FieldDescriptor *field)
Definition: text_format.cc:651
google::protobuf.internal::kTypeGoogleProdComPrefix
const char kTypeGoogleProdComPrefix[]
Definition: any_lite.cc:55
google::protobuf::UnknownFieldSet::field
const UnknownField & field(int index) const
Definition: unknown_field_set.h:314
google::protobuf::Message
Definition: src/google/protobuf/message.h:205
testing::internal::posix::Write
int Write(int fd, const void *buf, unsigned int count)
Definition: gtest-port.h:2129
error_collector_
MockErrorCollector error_collector_
Definition: importer_unittest.cc:129
google::protobuf::io::Printer::TextGenerator::indent_level_
int indent_level_
Definition: text_format.cc:1351
google::protobuf::io::StringOutputStream
Definition: zero_copy_stream_impl_lite.h:131
google::protobuf::MapEntryMessageComparator::MapEntryMessageComparator
MapEntryMessageComparator(const Descriptor *descriptor)
Definition: text_format.cc:2026
google::protobuf::io::Tokenizer::TYPE_END
@ TYPE_END
Definition: tokenizer.h:103
google::protobuf::kint32max
static const int32 kint32max
Definition: protobuf/src/google/protobuf/stubs/port.h:159
google::protobuf::UnknownField::TYPE_LENGTH_DELIMITED
@ TYPE_LENGTH_DELIMITED
Definition: unknown_field_set.h:229
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeMessageDelimiter
bool ConsumeMessageDelimiter(std::string *delimiter)
Definition: text_format.cc:382
google::protobuf::FieldDescriptor::name
const std::string & name() const
google::protobuf::TextFormat::Parser::ParserImpl::parse_info_tree_
ParseInfoTree * parse_info_tree_
Definition: text_format.cc:1199
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeAnyTypeUrl
bool ConsumeAnyTypeUrl(std::string *full_type_name, std::string *prefix)
Definition: text_format.cc:1103
google::protobuf::TextFormat::BaseTextGenerator::PrintString
void PrintString(const std::string &str)
Definition: text_format.h:110
google::protobuf::TextFormat::Finder::FindAnyType
virtual const Descriptor * FindAnyType(const Message &message, const std::string &prefix, const std::string &name) const
Definition: text_format.cc:1369
google::protobuf::TextFormat::ParseInfoTree::ParseInfoTree
ParseInfoTree()
Definition: text_format.cc:131
google::protobuf.text_format.PrintFieldValue
def PrintFieldValue(field, value, out, indent=0, as_utf8=False, as_one_line=False, use_short_repeated_primitives=False, pointy_brackets=False, use_index_order=False, float_format=None, double_format=None, message_formatter=None, print_unknown_fields=False)
Definition: text_format.py:255
google::protobuf::MapEntryMessageComparator::operator()
bool operator()(const Message *a, const Message *b)
Definition: text_format.cc:2029
google::protobuf::TextFormat::Printer::~Printer
~Printer()
Definition: text_format.cc:1810
google::protobuf::Reflection::SetEnumValue
void SetEnumValue(Message *message, const FieldDescriptor *field, int value) const
Definition: generated_message_reflection.cc:1322
google::protobuf::TextFormat::PrintToString
static bool PrintToString(const Message &message, std::string *output)
Definition: text_format.cc:2398
size
GLsizeiptr size
Definition: glcorearb.h:2943
google::protobuf::MapKey
Definition: map_field.h:371
google::protobuf::io::ErrorCollector
Definition: tokenizer.h:66
google::protobuf::TextFormat::Parser::Merge
bool Merge(io::ZeroCopyInputStream *input, Message *output)
Definition: text_format.cc:1439
stl_util.h
std
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeMessage
bool ConsumeMessage(Message *message, const std::string delimiter)
Definition: text_format.cc:371
google::protobuf::TextFormat::Parser::ParserImpl::ParserErrorCollector::ParserErrorCollector
ParserErrorCollector(TextFormat::Parser::ParserImpl *parser)
Definition: text_format.cc:1179
google::protobuf::FieldDescriptor::index
int index() const
Definition: src/google/protobuf/descriptor.h:2081
google::protobuf::UnknownFieldSet
Definition: unknown_field_set.h:86
delegate_
std::unique_ptr< const TextFormat::FieldValuePrinter > delegate_
Definition: text_format.cc:1776
google::protobuf::io::ZeroCopyOutputStream
Definition: zero_copy_stream.h:183
stringprintf.h
google::protobuf::TextFormat::Printer::Print
bool Print(const Message &message, io::ZeroCopyOutputStream *output) const
Definition: text_format.cc:1878
google::protobuf::MessageLite::ParseFromString
bool ParseFromString(const std::string &data)
Definition: message_lite.cc:321
google::protobuf::TextFormat::Parse
static bool Parse(io::ZeroCopyInputStream *input, Message *output)
Definition: text_format.cc:1486
google::protobuf::EnumValueDescriptor
Definition: src/google/protobuf/descriptor.h:1075
google::protobuf::Descriptor
Definition: src/google/protobuf/descriptor.h:231
descriptor.h
google::protobuf::FieldDescriptor::TYPE_GROUP
@ TYPE_GROUP
Definition: src/google/protobuf/descriptor.h:535
google::protobuf::TextFormat::Parser::ParserImpl::SkipField
bool SkipField()
Definition: text_format.cc:624
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeString
bool ConsumeString(std::string *text)
Definition: text_format.cc:960
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeSignedInteger
bool ConsumeSignedInteger(int64 *value, uint64 max_value)
Definition: text_format.cc:999
google::protobuf::TextFormat::FastFieldValuePrinter::PrintUInt32
virtual void PrintUInt32(uint32 val, BaseTextGenerator *generator) const
Definition: text_format.cc:1620
google::protobuf::io::Printer::TextGenerator::failed_
bool failed_
Definition: text_format.cc:1349
google::protobuf::Reflection::GetInt64
int64 GetInt64(const Message &message, const FieldDescriptor *field) const
google::protobuf::Message::New
Message * New() const override=0
first
GLint first
Definition: glcorearb.h:2830
google::protobuf::TextFormat::BaseTextGenerator::~BaseTextGenerator
virtual ~BaseTextGenerator()
Definition: text_format.cc:1511
google::protobuf::io::Tokenizer::TYPE_INTEGER
@ TYPE_INTEGER
Definition: tokenizer.h:109
google::protobuf::TextFormat::Parser::ParserImpl
Definition: text_format.cc:243
google::protobuf::TextFormat::Parser::ParserImpl::LookingAtType
bool LookingAtType(io::Tokenizer::TokenType token_type)
Definition: text_format.cc:910
google::protobuf::Reflection::GetEnumValue
int GetEnumValue(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1301
google::protobuf::TextFormat::Parser::ParserImpl::Parse
bool Parse(Message *output)
Definition: text_format.cc:299
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: glcorearb.h:2879
google::protobuf::TextFormat::FastFieldValuePrinter::PrintFloat
virtual void PrintFloat(float val, BaseTextGenerator *generator) const
Definition: text_format.cc:1632
google::protobuf::io::Printer::TextGenerator::output_
io::ZeroCopyOutputStream *const output_
Definition: text_format.cc:1345
true
#define true
Definition: cJSON.c:65
google::protobuf::TextFormat::FastFieldValuePrinter::PrintEnum
virtual void PrintEnum(int32 val, const std::string &name, BaseTextGenerator *generator) const
Definition: text_format.cc:1640
google::protobuf::kint64max
static const int64 kint64max
Definition: protobuf/src/google/protobuf/stubs/port.h:161
setup.url
url
Definition: compatibility_tests/v2.5.0/setup.py:64
internal
Definition: any.pb.h:40
google::protobuf.internal::MapFieldBase
Definition: map_field.h:69
google::protobuf::TextFormat::Parser::ParserImpl::tokenizer_error_collector_
ParserErrorCollector tokenizer_error_collector_
Definition: text_format.cc:1200
google::protobuf::TextFormat::Printer::PrintFieldName
void PrintFieldName(const Message &message, int field_index, int field_count, const Reflection *reflection, const FieldDescriptor *field, TextGenerator *generator) const
Definition: text_format.cc:2285
google::protobuf::TextFormat::Printer::PrintField
void PrintField(const Message &message, const Reflection *reflection, const FieldDescriptor *field, TextGenerator *generator) const
Definition: text_format.cc:2198
google::protobuf::TextFormat::Parser::ParserImpl::ParseField
bool ParseField(const FieldDescriptor *field, Message *output)
Definition: text_format.cc:310
buffer_
static uint8 buffer_[kBufferSize]
Definition: coded_stream_unittest.cc:136
val
GLuint GLfloat * val
Definition: glcorearb.h:3604
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeUnsignedDecimalAsDouble
bool ConsumeUnsignedDecimalAsDouble(double *value, uint64 max_value)
Definition: text_format.cc:1028
google::protobuf::Join
void Join(Iterator start, Iterator end, const char *delim, string *result)
Definition: strutil.h:769
google::protobuf::kuint64max
static const uint64 kuint64max
Definition: protobuf/src/google/protobuf/stubs/port.h:164
google::protobuf::TextFormat::Merge
static bool Merge(io::ZeroCopyInputStream *input, Message *output)
Definition: text_format.cc:1491
type_url
string * type_url
Definition: conformance_cpp.cc:98
google::protobuf::Reflection::GetMapData
const internal::MapFieldBase * GetMapData(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:2218
google::protobuf::TextFormat::Parser::ParserImpl::ParserImpl
ParserImpl(const Descriptor *root_message_type, io::ZeroCopyInputStream *input_stream, io::ErrorCollector *error_collector, const TextFormat::Finder *finder, ParseInfoTree *parse_info_tree, SingularOverwritePolicy singular_overwrite_policy, bool allow_case_insensitive_field, bool allow_unknown_field, bool allow_unknown_extension, bool allow_unknown_enum, bool allow_field_number, bool allow_relaxed_whitespace, bool allow_partial, int recursion_limit)
Definition: text_format.cc:254
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
descriptor.pb.h
google::protobuf::io::Printer::TextGenerator::at_start_of_line_
bool at_start_of_line_
Definition: text_format.cc:1348
google::protobuf::Reflection::AddMessage
Message * AddMessage(Message *message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
Definition: generated_message_reflection.cc:1638
google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE
@ CPPTYPE_MESSAGE
Definition: src/google/protobuf/descriptor.h:563
google::protobuf::TextFormat::FastFieldValuePrinter::FastFieldValuePrinter
FastFieldValuePrinter()
Definition: text_format.cc:1606
output
const upb_json_parsermethod const upb_symtab upb_sink * output
Definition: ruby/ext/google/protobuf_c/upb.h:10503
benchmarks.python.py_benchmark.parser
parser
Definition: py_benchmark.py:10
google::protobuf::MapIterator
Definition: map_field.h:712
google::protobuf::FieldDescriptor::CPPTYPE_INT32
@ CPPTYPE_INT32
Definition: src/google/protobuf/descriptor.h:554
count
GLint GLsizei count
Definition: glcorearb.h:2830
google::protobuf::EnumDescriptor
Definition: src/google/protobuf/descriptor.h:918
false
#define false
Definition: cJSON.c:70
google::protobuf::io::Printer::TextGenerator::WriteIndent
void WriteIndent()
Definition: text_format.cc:1319
google::protobuf::TextFormat::FastFieldValuePrinter::~FastFieldValuePrinter
virtual ~FastFieldValuePrinter()
Definition: text_format.cc:1607
index
GLuint index
Definition: glcorearb.h:3055
google::protobuf::STLDeleteValues
void STLDeleteValues(T *v)
Definition: stl_util.h:110
a
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:3228
google::protobuf::TextFormat::MergeFromString
static bool MergeFromString(const std::string &input, Message *output)
Definition: text_format.cc:1501
google::protobuf::TextFormat::Parser::ParserImpl::SkipFieldMessage
bool SkipFieldMessage()
Definition: text_format.cc:685
google::protobuf::Reflection::ListFields
void ListFields(const Message &message, std::vector< const FieldDescriptor * > *output) const
Definition: generated_message_reflection.cc:1029
google::protobuf::FieldDescriptor::is_repeated
bool is_repeated() const
Definition: src/google/protobuf/descriptor.h:2067
Json::Int64
long long int Int64
Definition: json.h:240
google::protobuf::FieldDescriptor::cpp_type
CppType cpp_type() const
Definition: src/google/protobuf/descriptor.h:2139
number
double number
Definition: cJSON.h:326
google::protobuf::Reflection::SetFloat
void SetFloat(Message *message, const FieldDescriptor *field, float value) const
it
MapIter it
Definition: php/ext/google/protobuf/map.c:205
google::protobuf::TextFormat::PrintFieldValueToString
static void PrintFieldValueToString(const Message &message, const FieldDescriptor *field, int index, std::string *output)
Definition: text_format.cc:2408
google::protobuf::TextFormat::Parser::ParserImpl::ConsumeUnsignedInteger
bool ConsumeUnsignedInteger(uint64 *value, uint64 max_value)
Definition: text_format.cc:978
google
Definition: data_proto2_to_proto3_util.h:11
message
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glcorearb.h:2695
google::protobuf::DynamicMessageFactory::GetPrototype
const Message * GetPrototype(const Descriptor *type) override
Definition: dynamic_message.cc:653
google::protobuf::Reflection::GetUInt64
uint64 GetUInt64(const Message &message, const FieldDescriptor *field) const
google::protobuf::Reflection::GetRepeatedMessage
const Message & GetRepeatedMessage(const Message &message, const FieldDescriptor *field, int index) const
Definition: generated_message_reflection.cc:1597
google::protobuf.internal::MapFieldPrinterHelper
Definition: text_format.cc:2073
google::protobuf::TextFormat::Printer::Printer
Printer()
Definition: text_format.cc:1797
google::protobuf::strings::ZERO_PAD_8
@ ZERO_PAD_8
Definition: strutil.h:583
google::protobuf::Reflection::GetMessage
const Message & GetMessage(const Message &message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
Definition: generated_message_reflection.cc:1443
google::protobuf::MapValueRef
Definition: map_field.h:565
GOOGLE_DCHECK_EQ
#define GOOGLE_DCHECK_EQ
Definition: logging.h:196
google::protobuf::Reflection::MapEnd
MapIterator MapEnd(Message *message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1795
google::protobuf::Reflection::SetUInt32
void SetUInt32(Message *message, const FieldDescriptor *field, uint32 value) const


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59