My favorites | English | Sign in

Protocol Buffers

text_format.h

#include <google/protobuf/text_format.h>
namespace google::protobuf

Utilities for printing and parsing protocol messages in a human-readable, text-based format.

Classes in this file

This class implements protocol buffer text format.
For more control over parsing, use this class.
Class for those users which require more fine-grained control over how a protobuffer message is printed out.

class TextFormat

#include <google/protobuf/text_format.h>
namespace google::protobuf

This class implements protocol buffer text format.

Printing and parsing protocol messages in text format is useful for debugging and human editing of messages.

This class is really a namespace that contains only static methods.

Members

static bool
Print(const Message & message, io::ZeroCopyOutputStream * output)
Outputs a textual representation of the given message to the given output stream.
static bool
PrintUnknownFields(const UnknownFieldSet & unknown_fields, io::ZeroCopyOutputStream * output)
Print the fields in an UnknownFieldSet. more...
static bool
PrintToString(const Message & message, string * output)
Like Print(), but outputs directly to a string.
static bool
PrintUnknownFieldsToString(const UnknownFieldSet & unknown_fields, string * output)
Like PrintUnknownFields(), but outputs directly to a string.
static void
PrintFieldValueToString(const Message & message, const FieldDescriptor * field, int index, string * output)
Outputs a textual representation of the value of the field supplied on the message supplied. more...
static bool
Parse(io::ZeroCopyInputStream * input, Message * output)
Parses a text-format protocol message from the given input stream to the given message object. more...
static bool
ParseFromString(const string & input, Message * output)
Like Parse(), but reads directly from a string.
static bool
Merge(io::ZeroCopyInputStream * input, Message * output)
Like Parse(), but the data is merged into the given message, as if using Message::MergeFrom().
static bool
MergeFromString(const string & input, Message * output)
Like Merge(), but reads directly from a string.
static bool
ParseFieldValueFromString(const string & input, const FieldDescriptor * field, Message * message)
Parse the given text as a single field value and store it into the given field of the given message. more...

static bool TextFormat::PrintUnknownFields(
        const UnknownFieldSet & unknown_fields,
        io::ZeroCopyOutputStream * output)

Print the fields in an UnknownFieldSet.

They are printed by tag number only. Embedded messages are heuristically identified by attempting to parse them.


static void TextFormat::PrintFieldValueToString(
        const Message & message,
        const FieldDescriptor * field,
        int index,
        string * output)

Outputs a textual representation of the value of the field supplied on the message supplied.

For non-repeated fields, an index of -1 must be supplied. Note that this method will print the default value for a field if it is not set.


static bool TextFormat::Parse(
        io::ZeroCopyInputStream * input,
        Message * output)

Parses a text-format protocol message from the given input stream to the given message object.

This function parses the format written by Print().


static bool TextFormat::ParseFieldValueFromString(
        const string & input,
        const FieldDescriptor * field,
        Message * message)

Parse the given text as a single field value and store it into the given field of the given message.

If the field is a repeated field, the new value will be added to the end

class TextFormat::Parser

#include <google/protobuf/text_format.h>
namespace google::protobuf

For more control over parsing, use this class.

Members

Parser()
~Parser()
bool
Parse(io::ZeroCopyInputStream * input, Message * output)
bool
ParseFromString(const string & input, Message * output)
bool
Merge(io::ZeroCopyInputStream * input, Message * output)
bool
MergeFromString(const string & input, Message * output)
void
RecordErrorsTo(io::ErrorCollector * error_collector)
Set where to report parse errors. more...
void
AllowPartialMessage(bool allow)
Normally parsing fails if, after parsing, output->IsInitialized() returns false. more...
bool
ParseFieldValueFromString(const string & input, const FieldDescriptor * field, Message * output)

void Parser::RecordErrorsTo(
        io::ErrorCollector * error_collector)

Set where to report parse errors.

If NULL (the default), errors will be printed to stderr.


void Parser::AllowPartialMessage(
        bool allow)

Normally parsing fails if, after parsing, output->IsInitialized() returns false.

Call AllowPartialMessage(true) to skip this check.

class TextFormat::Printer

#include <google/protobuf/text_format.h>
namespace google::protobuf

Class for those users which require more fine-grained control over how a protobuffer message is printed out.

Members

Printer()
~Printer()
bool
Print(const Message & message, io::ZeroCopyOutputStream * output)
bool
PrintUnknownFields(const UnknownFieldSet & unknown_fields, io::ZeroCopyOutputStream * output)
bool
PrintToString(const Message & message, string * output)
bool
PrintUnknownFieldsToString(const UnknownFieldSet & unknown_fields, string * output)
void
PrintFieldValueToString(const Message & message, const FieldDescriptor * field, int index, string * output)
void
SetInitialIndentLevel(int indent_level)
Adjust the initial indent level of all output. more...
void
SetSingleLineMode(bool single_line_mode)
If printing in single line mode, then the entire message will be output on a single line with no line breaks.

void Printer::SetInitialIndentLevel(
        int indent_level)

Adjust the initial indent level of all output.

Each indent level is equal to two spaces.