Home | Trees | Indices | Help |
---|
|
Contains routines for printing protocol messages in JSON format. Simple usage example: # Create a proto object and serialize it to a json format string. message = my_proto_pb2.MyMessage(foo='bar') json_string = json_format.MessageToJson(message) # Parse a json format string to proto object. message = json_format.Parse(json_string, my_proto_pb2.MyMessage())
Author: jieluo@google.com (Jie Luo)
|
|||
Error Top-level module error for json_format. |
|||
SerializeToJsonError Thrown if serialization to JSON fails. |
|||
ParseError Thrown in case of parsing error. |
|||
_Printer JSON format printer for protocol message. |
|||
_Parser JSON format parser for protocol message. |
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
_TIMESTAMPFOMAT =
|
|||
_INT_TYPES =
|
|||
_INT64_TYPES =
|
|||
_FLOAT_TYPES =
|
|||
_INFINITY =
|
|||
_NEG_INFINITY =
|
|||
_NAN =
|
|||
_UNPAIRED_SURROGATE_PATTERN = re.compile(r'
|
|||
_VALID_EXTENSION_NAME = re.compile(r'\[
|
|||
_INT_OR_FLOAT =
|
|||
_WKTJSONMETHODS =
|
|||
__package__ =
|
|
Converts protobuf message to JSON format. Args: message: The protocol buffers message instance to serialize. including_default_value_fields: If True, singular primitive fields, repeated fields, and map fields will always be serialized. If False, only serialize non-empty fields. Singular message fields and oneof fields are not affected by this option. preserving_proto_field_name: If True, use the original proto field names as defined in the .proto file. If False, convert the field names to lowerCamelCase. indent: The JSON object will be pretty-printed with this indent level. An indent level of 0 or negative will only insert newlines. sort_keys: If True, then the output will be sorted by field names. use_integers_for_enums: If true, print integers instead of enum names. descriptor_pool: A Descriptor Pool for resolving types. If None use the default. Returns: A string containing the JSON formatted protocol buffer message. |
Converts protobuf message to a dictionary. When the dictionary is encoded to JSON, it conforms to proto3 JSON spec. Args: message: The protocol buffers message instance to serialize. including_default_value_fields: If True, singular primitive fields, repeated fields, and map fields will always be serialized. If False, only serialize non-empty fields. Singular message fields and oneof fields are not affected by this option. preserving_proto_field_name: If True, use the original proto field names as defined in the .proto file. If False, convert the field names to lowerCamelCase. use_integers_for_enums: If true, print integers instead of enum names. descriptor_pool: A Descriptor Pool for resolving types. If None use the default. Returns: A dict representation of the protocol buffer message. |
Parses a JSON representation of a protocol message into a message. Args: text: Message JSON representation. message: A protocol buffer message to merge into. ignore_unknown_fields: If True, do not raise errors for unknown fields. descriptor_pool: A Descriptor Pool for resolving types. If None use the default. Returns: The same message passed as argument. Raises:: ParseError: On JSON parsing problems. |
Parses a JSON dictionary representation into a message. Args: js_dict: Dict representation of a JSON message. message: A protocol buffer message to merge into. ignore_unknown_fields: If True, do not raise errors for unknown fields. descriptor_pool: A Descriptor Pool for resolving types. If None use the default. Returns: The same message passed as argument. |
Convert a single scalar field value. Args: value: A scalar value to convert the scalar field value. field: The descriptor of the field to convert. require_str: If True, the field value must be a str. Returns: The converted scalar field value Raises: ParseError: In case of convert problems. |
Convert an integer. Args: value: A scalar value to convert. Returns: The integer value. Raises: ParseError: If an integer couldn't be consumed. |
Convert a boolean value. Args: value: A scalar value to convert. require_str: If True, value must be a str. Returns: The bool parsed. Raises: ParseError: If a boolean value couldn't be consumed. |
|
_UNPAIRED_SURROGATE_PATTERN
|
_WKTJSONMETHODS
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Sep 6 13:21:35 2019 | http://epydoc.sourceforge.net |