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: [email protected] (Joseph Schorr)
32// Based on original Protocol Buffers design by
33// Sanjay Ghemawat, Jeff Dean, and others.
34//
35// Utilities for printing and parsing protocol messages in a human-readable,
36// text-based format.
37
38#ifndef GOOGLE_PROTOBUF_TEXT_FORMAT_H__
39#define GOOGLE_PROTOBUF_TEXT_FORMAT_H__
40
41#include <map>
42#include <memory>
43#include <string>
44#include <vector>
45
46#include <google/protobuf/stubs/common.h>
47#include <google/protobuf/descriptor.h>
48#include <google/protobuf/message.h>
49#include <google/protobuf/message_lite.h>
50#include <google/protobuf/port.h>
51
52#include <google/protobuf/port_def.inc>
53
54#ifdef SWIG
55#error "You cannot SWIG proto headers"
56#endif
57
58namespace google {
59namespace protobuf {
60
61namespace io {
62class ErrorCollector; // tokenizer.h
63}
64
65// This class implements protocol buffer text format. Printing and parsing
66// protocol messages in text format is useful for debugging and human editing
67// of messages.
68//
69// This class is really a namespace that contains only static methods.
70class PROTOBUF_EXPORT TextFormat {
71 public:
72 // Outputs a textual representation of the given message to the given
73 // output stream. Returns false if printing fails.
74 static bool Print(const Message& message, io::ZeroCopyOutputStream* output);
75
76 // Print the fields in an UnknownFieldSet. They are printed by tag number
77 // only. Embedded messages are heuristically identified by attempting to
78 // parse them. Returns false if printing fails.
79 static bool PrintUnknownFields(const UnknownFieldSet& unknown_fields,
80 io::ZeroCopyOutputStream* output);
81
82 // Like Print(), but outputs directly to a string.
83 // Note: output will be cleared prior to printing, and will be left empty
84 // even if printing fails. Returns false if printing fails.
85 static bool PrintToString(const Message& message, std::string* output);
86
87 // Like PrintUnknownFields(), but outputs directly to a string. Returns
88 // false if printing fails.
89 static bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields,
90 std::string* output);
91
92 // Outputs a textual representation of the value of the field supplied on
93 // the message supplied. For non-repeated fields, an index of -1 must
94 // be supplied. Note that this method will print the default value for a
95 // field if it is not set.
96 static void PrintFieldValueToString(const Message& message,
97 const FieldDescriptor* field, int index,
98 std::string* output);
99
100 class PROTOBUF_EXPORT BaseTextGenerator {
101 public:
102 virtual ~BaseTextGenerator();
103
104 virtual void Indent() {}
105 virtual void Outdent() {}
106 // Returns the current indentation size in characters.
107 virtual size_t GetCurrentIndentationSize() const { return 0; }
108
109 // Print text to the output stream.
110 virtual void Print(const char* text, size_t size) = 0;
111
112 void PrintString(const std::string& str) { Print(str.data(), str.size()); }
113
114 template <size_t n>
115 void PrintLiteral(const char (&text)[n]) {
116 Print(text, n - 1); // n includes the terminating zero character.
117 }
118 };
119
120 // The default printer that converts scalar values from fields into their
121 // string representation.
122 // You can derive from this FastFieldValuePrinter if you want to have fields
123 // to be printed in a different way and register it at the Printer.
124 class PROTOBUF_EXPORT FastFieldValuePrinter {
125 public:
126 FastFieldValuePrinter();
127 virtual ~FastFieldValuePrinter();
128 virtual void PrintBool(bool val, BaseTextGenerator* generator) const;
129 virtual void PrintInt32(int32 val, BaseTextGenerator* generator) const;
130 virtual void PrintUInt32(uint32 val, BaseTextGenerator* generator) const;
131 virtual void PrintInt64(int64 val, BaseTextGenerator* generator) const;
132 virtual void PrintUInt64(uint64 val, BaseTextGenerator* generator) const;
133 virtual void PrintFloat(float val, BaseTextGenerator* generator) const;
134 virtual void PrintDouble(double val, BaseTextGenerator* generator) const;
135 virtual void PrintString(const std::string& val,
136 BaseTextGenerator* generator) const;
137 virtual void PrintBytes(const std::string& val,
138 BaseTextGenerator* generator) const;
139 virtual void PrintEnum(int32 val, const std::string& name,
140 BaseTextGenerator* generator) const;
141 virtual void PrintFieldName(const Message& message, int field_index,
142 int field_count, const Reflection* reflection,
143 const FieldDescriptor* field,
144 BaseTextGenerator* generator) const;
145 virtual void PrintFieldName(const Message& message,
146 const Reflection* reflection,
147 const FieldDescriptor* field,
148 BaseTextGenerator* generator) const;
149 virtual void PrintMessageStart(const Message& message, int field_index,
150 int field_count, bool single_line_mode,
151 BaseTextGenerator* generator) const;
152 virtual void PrintMessageEnd(const Message& message, int field_index,
153 int field_count, bool single_line_mode,
154 BaseTextGenerator* generator) const;
155
156 private:
157 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FastFieldValuePrinter);
158 };
159
160 // Deprecated: please use FastFieldValuePrinter instead.
161 class PROTOBUF_EXPORT FieldValuePrinter {
162 public:
163 FieldValuePrinter();
164 virtual ~FieldValuePrinter();
165 virtual std::string PrintBool(bool val) const;
166 virtual std::string PrintInt32(int32 val) const;
167 virtual std::string PrintUInt32(uint32 val) const;
168 virtual std::string PrintInt64(int64 val) const;
169 virtual std::string PrintUInt64(uint64 val) const;
170 virtual std::string PrintFloat(float val) const;
171 virtual std::string PrintDouble(double val) const;
172 virtual std::string PrintString(const std::string& val) const;
173 virtual std::string PrintBytes(const std::string& val) const;
174 virtual std::string PrintEnum(int32 val, const std::string& name) const;
175 virtual std::string PrintFieldName(const Message& message,
176 const Reflection* reflection,
177 const FieldDescriptor* field) const;
178 virtual std::string PrintMessageStart(const Message& message,
179 int field_index, int field_count,
180 bool single_line_mode) const;
181 virtual std::string PrintMessageEnd(const Message& message, int field_index,
182 int field_count,
183 bool single_line_mode) const;
184
185 private:
186 FastFieldValuePrinter delegate_;
187 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldValuePrinter);
188 };
189
190 class PROTOBUF_EXPORT MessagePrinter {
191 public:
192 MessagePrinter() {}
193 virtual ~MessagePrinter() {}
194 virtual void Print(const Message& message, bool single_line_mode,
195 BaseTextGenerator* generator) const = 0;
196
197 private:
198 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessagePrinter);
199 };
200
201 // Interface that Printers or Parsers can use to find extensions, or types
202 // referenced in Any messages.
203 class PROTOBUF_EXPORT Finder {
204 public:
205 virtual ~Finder();
206
207 // Try to find an extension of *message by fully-qualified field
208 // name. Returns NULL if no extension is known for this name or number.
209 // The base implementation uses the extensions already known by the message.
210 virtual const FieldDescriptor* FindExtension(Message* message,
211 const std::string& name) const;
212
213 // Similar to FindExtension, but uses a Descriptor and the extension number
214 // instead of using a Message and the name when doing the look up.
215 virtual const FieldDescriptor* FindExtensionByNumber(
216 const Descriptor* descriptor, int number) const;
217
218 // Find the message type for an Any proto.
219 // Returns NULL if no message is known for this name.
220 // The base implementation only accepts prefixes of type.googleprod.com/ or
221 // type.googleapis.com/, and searches the DescriptorPool of the parent
222 // message.
223 virtual const Descriptor* FindAnyType(const Message& message,
224 const std::string& prefix,
225 const std::string& name) const;
226
227 // Find the message factory for the given extension field. This can be used
228 // to generalize the Parser to add extension fields to a message in the same
229 // way as the "input" message for the Parser.
230 virtual MessageFactory* FindExtensionFactory(
231 const FieldDescriptor* field) const;
232 };
233
234 // Class for those users which require more fine-grained control over how
235 // a protobuffer message is printed out.
236 class PROTOBUF_EXPORT Printer {
237 public:
238 Printer();
239
240 // Like TextFormat::Print
241 bool Print(const Message& message, io::ZeroCopyOutputStream* output) const;
242 // Like TextFormat::PrintUnknownFields
243 bool PrintUnknownFields(const UnknownFieldSet& unknown_fields,
244 io::ZeroCopyOutputStream* output) const;
245 // Like TextFormat::PrintToString
246 bool PrintToString(const Message& message, std::string* output) const;
247 // Like TextFormat::PrintUnknownFieldsToString
248 bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields,
249 std::string* output) const;
250 // Like TextFormat::PrintFieldValueToString
251 void PrintFieldValueToString(const Message& message,
252 const FieldDescriptor* field, int index,
253 std::string* output) const;
254
255 // Adjust the initial indent level of all output. Each indent level is
256 // equal to two spaces.
257 void SetInitialIndentLevel(int indent_level) {
258 initial_indent_level_ = indent_level;
259 }
260
261 // If printing in single line mode, then the entire message will be output
262 // on a single line with no line breaks.
263 void SetSingleLineMode(bool single_line_mode) {
264 single_line_mode_ = single_line_mode;
265 }
266
267 bool IsInSingleLineMode() const { return single_line_mode_; }
268
269 // If use_field_number is true, uses field number instead of field name.
270 void SetUseFieldNumber(bool use_field_number) {
271 use_field_number_ = use_field_number;
272 }
273
274 // Set true to print repeated primitives in a format like:
275 // field_name: [1, 2, 3, 4]
276 // instead of printing each value on its own line. Short format applies
277 // only to primitive values -- i.e. everything except strings and
278 // sub-messages/groups.
279 void SetUseShortRepeatedPrimitives(bool use_short_repeated_primitives) {
280 use_short_repeated_primitives_ = use_short_repeated_primitives;
281 }
282
283 // Set true to output UTF-8 instead of ASCII. The only difference
284 // is that bytes >= 0x80 in string fields will not be escaped,
285 // because they are assumed to be part of UTF-8 multi-byte
286 // sequences. This will change the default FastFieldValuePrinter.
287 void SetUseUtf8StringEscaping(bool as_utf8);
288
289 // Set the default FastFieldValuePrinter that is used for all fields that
290 // don't have a field-specific printer registered.
291 // Takes ownership of the printer.
292 void SetDefaultFieldValuePrinter(const FastFieldValuePrinter* printer);
293
294 PROTOBUF_DEPRECATED_MSG("Please use FastFieldValuePrinter")
295 void SetDefaultFieldValuePrinter(const FieldValuePrinter* printer);
296
297 // Sets whether we want to hide unknown fields or not.
298 // Usually unknown fields are printed in a generic way that includes the
299 // tag number of the field instead of field name. However, sometimes it
300 // is useful to be able to print the message without unknown fields (e.g.
301 // for the python protobuf version to maintain consistency between its pure
302 // python and c++ implementations).
303 void SetHideUnknownFields(bool hide) { hide_unknown_fields_ = hide; }
304
305 // If print_message_fields_in_index_order is true, fields of a proto message
306 // will be printed using the order defined in source code instead of the
307 // field number, extensions will be printed at the end of the message
308 // and their relative order is determined by the extension number.
309 // By default, use the field number order.
310 void SetPrintMessageFieldsInIndexOrder(
311 bool print_message_fields_in_index_order) {
312 print_message_fields_in_index_order_ =
313 print_message_fields_in_index_order;
314 }
315
316 // If expand==true, expand google.protobuf.Any payloads. The output
317 // will be of form
318 // [type_url] { <value_printed_in_text> }
319 //
320 // If expand==false, print Any using the default printer. The output will
321 // look like
322 // type_url: "<type_url>" value: "serialized_content"
323 void SetExpandAny(bool expand) { expand_any_ = expand; }
324
325 // Set how parser finds message for Any payloads.
326 void SetFinder(const Finder* finder) { finder_ = finder; }
327
328 // If non-zero, we truncate all string fields that are longer than
329 // this threshold. This is useful when the proto message has very long
330 // strings, e.g., dump of encoded image file.
331 //
332 // NOTE(hfgong): Setting a non-zero value breaks round-trip safe
333 // property of TextFormat::Printer. That is, from the printed message, we
334 // cannot fully recover the original string field any more.
335 void SetTruncateStringFieldLongerThan(
336 const int64 truncate_string_field_longer_than) {
337 truncate_string_field_longer_than_ = truncate_string_field_longer_than;
338 }
339
340 // Register a custom field-specific FastFieldValuePrinter for fields
341 // with a particular FieldDescriptor.
342 // Returns "true" if the registration succeeded, or "false", if there is
343 // already a printer for that FieldDescriptor.
344 // Takes ownership of the printer on successful registration.
345 bool RegisterFieldValuePrinter(const FieldDescriptor* field,
346 const FastFieldValuePrinter* printer);
347
348 PROTOBUF_DEPRECATED_MSG("Please use FastFieldValuePrinter")
349 bool RegisterFieldValuePrinter(const FieldDescriptor* field,
350 const FieldValuePrinter* printer);
351
352 // Register a custom message-specific MessagePrinter for messages with a
353 // particular Descriptor.
354 // Returns "true" if the registration succeeded, or "false" if there is
355 // already a printer for that Descriptor.
356 bool RegisterMessagePrinter(const Descriptor* descriptor,
357 const MessagePrinter* printer);
358
359 private:
360 // Forward declaration of an internal class used to print the text
361 // output to the OutputStream (see text_format.cc for implementation).
362 class TextGenerator;
363
364 // Internal Print method, used for writing to the OutputStream via
365 // the TextGenerator class.
366 void Print(const Message& message, TextGenerator* generator) const;
367
368 // Print a single field.
369 void PrintField(const Message& message, const Reflection* reflection,
370 const FieldDescriptor* field,
371 TextGenerator* generator) const;
372
373 // Print a repeated primitive field in short form.
374 void PrintShortRepeatedField(const Message& message,
375 const Reflection* reflection,
376 const FieldDescriptor* field,
377 TextGenerator* generator) const;
378
379 // Print the name of a field -- i.e. everything that comes before the
380 // ':' for a single name/value pair.
381 void PrintFieldName(const Message& message, int field_index,
382 int field_count, const Reflection* reflection,
383 const FieldDescriptor* field,
384 TextGenerator* generator) const;
385
386 // Outputs a textual representation of the value of the field supplied on
387 // the message supplied or the default value if not set.
388 void PrintFieldValue(const Message& message, const Reflection* reflection,
389 const FieldDescriptor* field, int index,
390 TextGenerator* generator) const;
391
392 // Print the fields in an UnknownFieldSet. They are printed by tag number
393 // only. Embedded messages are heuristically identified by attempting to
394 // parse them.
395 void PrintUnknownFields(const UnknownFieldSet& unknown_fields,
396 TextGenerator* generator) const;
397
398 bool PrintAny(const Message& message, TextGenerator* generator) const;
399
400 const FastFieldValuePrinter* GetFieldPrinter(
401 const FieldDescriptor* field) const {
402 auto it = custom_printers_.find(field);
403 return it == custom_printers_.end() ? default_field_value_printer_.get()
404 : it->second.get();
405 }
406
407 int initial_indent_level_;
408 bool single_line_mode_;
409 bool use_field_number_;
410 bool use_short_repeated_primitives_;
411 bool hide_unknown_fields_;
412 bool print_message_fields_in_index_order_;
413 bool expand_any_;
414 int64 truncate_string_field_longer_than_;
415
416 std::unique_ptr<const FastFieldValuePrinter> default_field_value_printer_;
417 typedef std::map<const FieldDescriptor*,
418 std::unique_ptr<const FastFieldValuePrinter>>
419 CustomPrinterMap;
420 CustomPrinterMap custom_printers_;
421
422 typedef std::map<const Descriptor*, std::unique_ptr<const MessagePrinter>>
423 CustomMessagePrinterMap;
424 CustomMessagePrinterMap custom_message_printers_;
425
426 const Finder* finder_;
427 };
428
429 // Parses a text-format protocol message from the given input stream to
430 // the given message object. This function parses the human-readable format
431 // written by Print(). Returns true on success. The message is cleared first,
432 // even if the function fails -- See Merge() to avoid this behavior.
433 //
434 // Example input: "user {\n id: 123 extra { gender: MALE language: 'en' }\n}"
435 //
436 // One use for this function is parsing handwritten strings in test code.
437 // Another use is to parse the output from google::protobuf::Message::DebugString()
438 // (or ShortDebugString()), because these functions output using
439 // google::protobuf::TextFormat::Print().
440 //
441 // If you would like to read a protocol buffer serialized in the
442 // (non-human-readable) binary wire format, see
443 // google::protobuf::MessageLite::ParseFromString().
444 static bool Parse(io::ZeroCopyInputStream* input, Message* output);
445 // Like Parse(), but reads directly from a string.
446 static bool ParseFromString(const std::string& input, Message* output);
447
448 // Like Parse(), but the data is merged into the given message, as if
449 // using Message::MergeFrom().
450 static bool Merge(io::ZeroCopyInputStream* input, Message* output);
451 // Like Merge(), but reads directly from a string.
452 static bool MergeFromString(const std::string& input, Message* output);
453
454 // Parse the given text as a single field value and store it into the
455 // given field of the given message. If the field is a repeated field,
456 // the new value will be added to the end
457 static bool ParseFieldValueFromString(const std::string& input,
458 const FieldDescriptor* field,
459 Message* message);
460
461 // A location in the parsed text.
462 struct ParseLocation {
463 int line;
464 int column;
465
466 ParseLocation() : line(-1), column(-1) {}
467 ParseLocation(int line_param, int column_param)
468 : line(line_param), column(column_param) {}
469 };
470
471 // Data structure which is populated with the locations of each field
472 // value parsed from the text.
473 class PROTOBUF_EXPORT ParseInfoTree {
474 public:
475 ParseInfoTree() = default;
476 ParseInfoTree(const ParseInfoTree&) = delete;
477 ParseInfoTree& operator=(const ParseInfoTree&) = delete;
478
479 // Returns the parse location for index-th value of the field in the parsed
480 // text. If none exists, returns a location with line = -1. Index should be
481 // -1 for not-repeated fields.
482 ParseLocation GetLocation(const FieldDescriptor* field, int index) const;
483
484 // Returns the parse info tree for the given field, which must be a message
485 // type. The nested information tree is owned by the root tree and will be
486 // deleted when it is deleted.
487 ParseInfoTree* GetTreeForNested(const FieldDescriptor* field,
488 int index) const;
489
490 private:
491 // Allow the text format parser to record information into the tree.
492 friend class TextFormat;
493
494 // Records the starting location of a single value for a field.
495 void RecordLocation(const FieldDescriptor* field, ParseLocation location);
496
497 // Create and records a nested tree for a nested message field.
498 ParseInfoTree* CreateNested(const FieldDescriptor* field);
499
500 // Defines the map from the index-th field descriptor to its parse location.
501 typedef std::map<const FieldDescriptor*, std::vector<ParseLocation> >
502 LocationMap;
503
504 // Defines the map from the index-th field descriptor to the nested parse
505 // info tree.
506 typedef std::map<const FieldDescriptor*,
507 std::vector<std::unique_ptr<ParseInfoTree>>>
508 NestedMap;
509
510 LocationMap locations_;
511 NestedMap nested_;
512 };
513
514 // For more control over parsing, use this class.
515 class PROTOBUF_EXPORT Parser {
516 public:
517 Parser();
518 ~Parser();
519
520 // Like TextFormat::Parse().
521 bool Parse(io::ZeroCopyInputStream* input, Message* output);
522 // Like TextFormat::ParseFromString().
523 bool ParseFromString(const std::string& input, Message* output);
524 // Like TextFormat::Merge().
525 bool Merge(io::ZeroCopyInputStream* input, Message* output);
526 // Like TextFormat::MergeFromString().
527 bool MergeFromString(const std::string& input, Message* output);
528
529 // Set where to report parse errors. If NULL (the default), errors will
530 // be printed to stderr.
531 void RecordErrorsTo(io::ErrorCollector* error_collector) {
532 error_collector_ = error_collector;
533 }
534
535 // Set how parser finds extensions. If NULL (the default), the
536 // parser will use the standard Reflection object associated with
537 // the message being parsed.
538 void SetFinder(const Finder* finder) { finder_ = finder; }
539
540 // Sets where location information about the parse will be written. If NULL
541 // (the default), then no location will be written.
542 void WriteLocationsTo(ParseInfoTree* tree) { parse_info_tree_ = tree; }
543
544 // Normally parsing fails if, after parsing, output->IsInitialized()
545 // returns false. Call AllowPartialMessage(true) to skip this check.
546 void AllowPartialMessage(bool allow) { allow_partial_ = allow; }
547
548 // Allow field names to be matched case-insensitively.
549 // This is not advisable if there are fields that only differ in case, or
550 // if you want to enforce writing in the canonical form.
551 // This is 'false' by default.
552 void AllowCaseInsensitiveField(bool allow) {
553 allow_case_insensitive_field_ = allow;
554 }
555
556 // Like TextFormat::ParseFieldValueFromString
557 bool ParseFieldValueFromString(const std::string& input,
558 const FieldDescriptor* field,
559 Message* output);
560
561 // When an unknown extension is met, parsing will fail if this option is set
562 // to false (the default). If true, unknown extensions will be ignored and
563 // a warning message will be generated.
564 void AllowUnknownExtension(bool allow) { allow_unknown_extension_ = allow; }
565
566 // When an unknown field is met, parsing will fail if this option is set
567 // to false(the default). If true, unknown fields will be ignored and
568 // a warning message will be generated.
569 // Please aware that set this option true may hide some errors (e.g.
570 // spelling error on field name). Avoid to use this option if possible.
571 void AllowUnknownField(bool allow) { allow_unknown_field_ = allow; }
572
573
574 void AllowFieldNumber(bool allow) { allow_field_number_ = allow; }
575
576 // Sets maximum recursion depth which parser can use. This is effectively
577 // the maximum allowed nesting of proto messages.
578 void SetRecursionLimit(int limit) { recursion_limit_ = limit; }
579
580 private:
581 // Forward declaration of an internal class used to parse text
582 // representations (see text_format.cc for implementation).
583 class ParserImpl;
584
585 // Like TextFormat::Merge(). The provided implementation is used
586 // to do the parsing.
587 bool MergeUsingImpl(io::ZeroCopyInputStream* input, Message* output,
588 ParserImpl* parser_impl);
589
590 io::ErrorCollector* error_collector_;
591 const Finder* finder_;
592 ParseInfoTree* parse_info_tree_;
593 bool allow_partial_;
594 bool allow_case_insensitive_field_;
595 bool allow_unknown_field_;
596 bool allow_unknown_extension_;
597 bool allow_unknown_enum_;
598 bool allow_field_number_;
599 bool allow_relaxed_whitespace_;
600 bool allow_singular_overwrites_;
601 int recursion_limit_;
602 };
603
604
605 private:
606 // Hack: ParseInfoTree declares TextFormat as a friend which should extend
607 // the friendship to TextFormat::Parser::ParserImpl, but unfortunately some
608 // old compilers (e.g. GCC 3.4.6) don't implement this correctly. We provide
609 // helpers for ParserImpl to call methods of ParseInfoTree.
610 static inline void RecordLocation(ParseInfoTree* info_tree,
611 const FieldDescriptor* field,
612 ParseLocation location);
613 static inline ParseInfoTree* CreateNested(ParseInfoTree* info_tree,
614 const FieldDescriptor* field);
615
616 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TextFormat);
617};
618
619inline void TextFormat::RecordLocation(ParseInfoTree* info_tree,
620 const FieldDescriptor* field,
621 ParseLocation location) {
622 info_tree->RecordLocation(field, location);
623}
624
625inline TextFormat::ParseInfoTree* TextFormat::CreateNested(
626 ParseInfoTree* info_tree, const FieldDescriptor* field) {
627 return info_tree->CreateNested(field);
628}
629
630} // namespace protobuf
631} // namespace google
632
633#include <google/protobuf/port_undef.inc>
634
635#endif // GOOGLE_PROTOBUF_TEXT_FORMAT_H__
636