Package google :: Package protobuf :: Module text_format
[frames] | no frames]

Module text_format

source code

Contains routines for printing protocol messages in text format.


Author: kenton@google.com (Kenton Varda)

Functions
 
MessageToString(message, as_utf8=False, as_one_line=False)
Convert protobuf message to text format.
source code
 
PrintMessage(message, out, indent=0, as_utf8=False, as_one_line=False) source code
 
PrintField(field, value, out, indent=0, as_utf8=False, as_one_line=False)
Print a single field name/value pair.
source code
 
PrintFieldValue(field, value, out, indent=0, as_utf8=False, as_one_line=False)
Print a single field value (not including name).
source code
 
Merge(text, message)
Merges an ASCII representation of a protocol message into a message.
source code
Function Details

MessageToString(message, as_utf8=False, as_one_line=False)

source code 
Convert protobuf message to text format.

Floating point values can be formatted compactly with 15 digits of
precision (which is the most that IEEE 754 "double" can guarantee)
using float_format='.15g'.

Args:
  message: The protocol buffers message.
  as_utf8: Produce text output in UTF8 format.
  as_one_line: Don't introduce newlines between fields.
  pointy_brackets: If True, use angle brackets instead of curly braces for
    nesting.
  use_index_order: If True, print fields of a proto message using the order
    defined in source code instead of the field number. By default, use the
    field number order.
  float_format: If set, use this to specify floating point number formatting
    (per the "Format Specification Mini-Language"); otherwise, str() is used.

Returns:
  A string of the text formatted protocol buffer message.

PrintField(field, value, out, indent=0, as_utf8=False, as_one_line=False)

source code 

Print a single field name/value pair. For repeated fields, the value should be a single element.

PrintFieldValue(field, value, out, indent=0, as_utf8=False, as_one_line=False)

source code 

Print a single field value (not including name). For repeated fields, the value should be a single element.

Merge(text, message)

source code 
Merges an ASCII representation of a protocol message into a message.

Args:
  text: Message ASCII representation.
  message: A protocol buffer message to merge into.

Raises:
  ParseError: On ASCII parsing problems.