aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/text_format.h
diff options
context:
space:
mode:
authorliujisi@google.com <liujisi@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2010-11-02 13:14:58 +0000
committerliujisi@google.com <liujisi@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2010-11-02 13:14:58 +0000
commit33165fe0d5c265c92f2a67fc2b437b567c24e294 (patch)
tree52def0850ddd2e976da238d1a437fbda79c96e44 /src/google/protobuf/text_format.h
parent80aa23df6c63750e8cdfdcf3996fbc37d63cac61 (diff)
downloadprotobuf-33165fe0d5c265c92f2a67fc2b437b567c24e294.tar.gz
protobuf-33165fe0d5c265c92f2a67fc2b437b567c24e294.tar.bz2
protobuf-33165fe0d5c265c92f2a67fc2b437b567c24e294.zip
Submit recent changes from internal branch. See CHANGES.txt for more details.
Diffstat (limited to 'src/google/protobuf/text_format.h')
-rw-r--r--src/google/protobuf/text_format.h47
1 files changed, 34 insertions, 13 deletions
diff --git a/src/google/protobuf/text_format.h b/src/google/protobuf/text_format.h
index e78e1042..03c04910 100644
--- a/src/google/protobuf/text_format.h
+++ b/src/google/protobuf/text_format.h
@@ -90,20 +90,20 @@ class LIBPROTOBUF_EXPORT TextFormat {
~Printer();
// Like TextFormat::Print
- bool Print(const Message& message, io::ZeroCopyOutputStream* output);
+ bool Print(const Message& message, io::ZeroCopyOutputStream* output) const;
// Like TextFormat::PrintUnknownFields
bool PrintUnknownFields(const UnknownFieldSet& unknown_fields,
- io::ZeroCopyOutputStream* output);
+ io::ZeroCopyOutputStream* output) const;
// Like TextFormat::PrintToString
- bool PrintToString(const Message& message, string* output);
+ bool PrintToString(const Message& message, string* output) const;
// Like TextFormat::PrintUnknownFieldsToString
bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields,
- string* output);
+ string* output) const;
// Like TextFormat::PrintFieldValueToString
void PrintFieldValueToString(const Message& message,
const FieldDescriptor* field,
int index,
- string* output);
+ string* output) const;
// Adjust the initial indent level of all output. Each indent level is
// equal to two spaces.
@@ -121,8 +121,7 @@ class LIBPROTOBUF_EXPORT TextFormat {
// field_name: [1, 2, 3, 4]
// instead of printing each value on its own line. Short format applies
// only to primitive values -- i.e. everything except strings and
- // sub-messages/groups. Note that at present this format is not recognized
- // by the parser.
+ // sub-messages/groups.
void SetUseShortRepeatedPrimitives(bool use_short_repeated_primitives) {
use_short_repeated_primitives_ = use_short_repeated_primitives;
}
@@ -143,26 +142,26 @@ class LIBPROTOBUF_EXPORT TextFormat {
// Internal Print method, used for writing to the OutputStream via
// the TextGenerator class.
void Print(const Message& message,
- TextGenerator& generator);
+ TextGenerator& generator) const;
// Print a single field.
void PrintField(const Message& message,
const Reflection* reflection,
const FieldDescriptor* field,
- TextGenerator& generator);
+ TextGenerator& generator) const;
// Print a repeated primitive field in short form.
void PrintShortRepeatedField(const Message& message,
const Reflection* reflection,
const FieldDescriptor* field,
- TextGenerator& generator);
+ TextGenerator& generator) const;
// Print the name of a field -- i.e. everything that comes before the
// ':' for a single name/value pair.
void PrintFieldName(const Message& message,
const Reflection* reflection,
const FieldDescriptor* field,
- TextGenerator& generator);
+ TextGenerator& generator) const;
// Outputs a textual representation of the value of the field supplied on
// the message supplied or the default value if not set.
@@ -170,13 +169,13 @@ class LIBPROTOBUF_EXPORT TextFormat {
const Reflection* reflection,
const FieldDescriptor* field,
int index,
- TextGenerator& generator);
+ TextGenerator& generator) const;
// Print the fields in an UnknownFieldSet. They are printed by tag number
// only. Embedded messages are heuristically identified by attempting to
// parse them.
void PrintUnknownFields(const UnknownFieldSet& unknown_fields,
- TextGenerator& generator);
+ TextGenerator& generator) const;
int initial_indent_level_;
@@ -207,6 +206,20 @@ class LIBPROTOBUF_EXPORT TextFormat {
const FieldDescriptor* field,
Message* message);
+ // Interface that TextFormat::Parser can use to find extensions.
+ // This class may be extended in the future to find more information
+ // like fields, etc.
+ class LIBPROTOBUF_EXPORT Finder {
+ public:
+ virtual ~Finder();
+
+ // Try to find an extension of *message by fully-qualified field
+ // name. Returns NULL if no extension is known for this name or number.
+ virtual const FieldDescriptor* FindExtension(
+ Message* message,
+ const string& name) const = 0;
+ };
+
// For more control over parsing, use this class.
class LIBPROTOBUF_EXPORT Parser {
public:
@@ -228,6 +241,13 @@ class LIBPROTOBUF_EXPORT TextFormat {
error_collector_ = error_collector;
}
+ // Set how parser finds extensions. If NULL (the default), the
+ // parser will use the standard Reflection object associated with
+ // the message being parsed.
+ void SetFinder(Finder* finder) {
+ finder_ = finder;
+ }
+
// Normally parsing fails if, after parsing, output->IsInitialized()
// returns false. Call AllowPartialMessage(true) to skip this check.
void AllowPartialMessage(bool allow) {
@@ -251,6 +271,7 @@ class LIBPROTOBUF_EXPORT TextFormat {
ParserImpl* parser_impl);
io::ErrorCollector* error_collector_;
+ Finder* finder_;
bool allow_partial_;
};