| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // output stream. | 68 // output stream. |
| 69 static bool Print(const Message& message, io::ZeroCopyOutputStream* output); | 69 static bool Print(const Message& message, io::ZeroCopyOutputStream* output); |
| 70 | 70 |
| 71 // Print the fields in an UnknownFieldSet. They are printed by tag number | 71 // Print the fields in an UnknownFieldSet. They are printed by tag number |
| 72 // only. Embedded messages are heuristically identified by attempting to | 72 // only. Embedded messages are heuristically identified by attempting to |
| 73 // parse them. | 73 // parse them. |
| 74 static bool PrintUnknownFields(const UnknownFieldSet& unknown_fields, | 74 static bool PrintUnknownFields(const UnknownFieldSet& unknown_fields, |
| 75 io::ZeroCopyOutputStream* output); | 75 io::ZeroCopyOutputStream* output); |
| 76 | 76 |
| 77 // Like Print(), but outputs directly to a string. | 77 // Like Print(), but outputs directly to a string. |
| 78 // Note: output will be cleared before prior to printing, and will |
| 79 // be left empty even if printing fails. |
| 78 static bool PrintToString(const Message& message, string* output); | 80 static bool PrintToString(const Message& message, string* output); |
| 79 | 81 |
| 80 // Like PrintUnknownFields(), but outputs directly to a string. | 82 // Like PrintUnknownFields(), but outputs directly to a string. |
| 81 static bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields, | 83 static bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields, |
| 82 string* output); | 84 string* output); |
| 83 | 85 |
| 84 // Outputs a textual representation of the value of the field supplied on | 86 // Outputs a textual representation of the value of the field supplied on |
| 85 // the message supplied. For non-repeated fields, an index of -1 must | 87 // the message supplied. For non-repeated fields, an index of -1 must |
| 86 // be supplied. Note that this method will print the default value for a | 88 // be supplied. Note that this method will print the default value for a |
| 87 // field if it is not set. | 89 // field if it is not set. |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 296 |
| 295 bool hide_unknown_fields_; | 297 bool hide_unknown_fields_; |
| 296 | 298 |
| 297 bool print_message_fields_in_index_order_; | 299 bool print_message_fields_in_index_order_; |
| 298 | 300 |
| 299 bool expand_any_; | 301 bool expand_any_; |
| 300 | 302 |
| 301 int64 truncate_string_field_longer_than_; | 303 int64 truncate_string_field_longer_than_; |
| 302 | 304 |
| 303 google::protobuf::scoped_ptr<const FieldValuePrinter> default_field_value_pr
inter_; | 305 google::protobuf::scoped_ptr<const FieldValuePrinter> default_field_value_pr
inter_; |
| 304 typedef map<const FieldDescriptor*, | 306 typedef std::map<const FieldDescriptor*, |
| 305 const FieldValuePrinter*> CustomPrinterMap; | 307 const FieldValuePrinter*> CustomPrinterMap; |
| 306 CustomPrinterMap custom_printers_; | 308 CustomPrinterMap custom_printers_; |
| 307 }; | 309 }; |
| 308 | 310 |
| 309 // Parses a text-format protocol message from the given input stream to | 311 // Parses a text-format protocol message from the given input stream to |
| 310 // the given message object. This function parses the human-readable format | 312 // the given message object. This function parses the human-readable format |
| 311 // written by Print(). Returns true on success. The message is cleared first, | 313 // written by Print(). Returns true on success. The message is cleared first, |
| 312 // even if the function fails -- See Merge() to avoid this behavior. | 314 // even if the function fails -- See Merge() to avoid this behavior. |
| 313 // | 315 // |
| 314 // Example input: "user {\n id: 123 extra { gender: MALE language: 'en' }\n}" | 316 // Example input: "user {\n id: 123 extra { gender: MALE language: 'en' }\n}" |
| 315 // | 317 // |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // Allow the text format parser to record information into the tree. | 386 // Allow the text format parser to record information into the tree. |
| 385 friend class TextFormat; | 387 friend class TextFormat; |
| 386 | 388 |
| 387 // Records the starting location of a single value for a field. | 389 // Records the starting location of a single value for a field. |
| 388 void RecordLocation(const FieldDescriptor* field, ParseLocation location); | 390 void RecordLocation(const FieldDescriptor* field, ParseLocation location); |
| 389 | 391 |
| 390 // Create and records a nested tree for a nested message field. | 392 // Create and records a nested tree for a nested message field. |
| 391 ParseInfoTree* CreateNested(const FieldDescriptor* field); | 393 ParseInfoTree* CreateNested(const FieldDescriptor* field); |
| 392 | 394 |
| 393 // Defines the map from the index-th field descriptor to its parse location. | 395 // Defines the map from the index-th field descriptor to its parse location. |
| 394 typedef map<const FieldDescriptor*, vector<ParseLocation> > LocationMap; | 396 typedef std::map<const FieldDescriptor*, |
| 397 std::vector<ParseLocation> > LocationMap; |
| 395 | 398 |
| 396 // Defines the map from the index-th field descriptor to the nested parse | 399 // Defines the map from the index-th field descriptor to the nested parse |
| 397 // info tree. | 400 // info tree. |
| 398 typedef map<const FieldDescriptor*, vector<ParseInfoTree*> > NestedMap; | 401 typedef std::map<const FieldDescriptor*, |
| 402 std::vector<ParseInfoTree*> > NestedMap; |
| 399 | 403 |
| 400 LocationMap locations_; | 404 LocationMap locations_; |
| 401 NestedMap nested_; | 405 NestedMap nested_; |
| 402 | 406 |
| 403 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ParseInfoTree); | 407 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ParseInfoTree); |
| 404 }; | 408 }; |
| 405 | 409 |
| 406 // For more control over parsing, use this class. | 410 // For more control over parsing, use this class. |
| 407 class LIBPROTOBUF_EXPORT Parser { | 411 class LIBPROTOBUF_EXPORT Parser { |
| 408 public: | 412 public: |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 512 |
| 509 inline TextFormat::ParseInfoTree* TextFormat::CreateNested( | 513 inline TextFormat::ParseInfoTree* TextFormat::CreateNested( |
| 510 ParseInfoTree* info_tree, const FieldDescriptor* field) { | 514 ParseInfoTree* info_tree, const FieldDescriptor* field) { |
| 511 return info_tree->CreateNested(field); | 515 return info_tree->CreateNested(field); |
| 512 } | 516 } |
| 513 | 517 |
| 514 } // namespace protobuf | 518 } // namespace protobuf |
| 515 | 519 |
| 516 } // namespace google | 520 } // namespace google |
| 517 #endif // GOOGLE_PROTOBUF_TEXT_FORMAT_H__ | 521 #endif // GOOGLE_PROTOBUF_TEXT_FORMAT_H__ |
| OLD | NEW |