mosstool.util.format_converter

Module Contents

Functions

pb2json

Convert a protobuf message to a JSON string.

pb2dict

Convert a protobuf message to a Python dictionary.

pb2coll

Convert a protobuf message to a MongoDB collection.

json2pb

Convert a JSON string to a protobuf message.

dict2pb

Convert a Python dictionary to a protobuf message.

coll2pb

Convert a MongoDB collection to a protobuf message.

Data

API

mosstool.util.format_converter.__all__

[‘pb2json’, ‘pb2dict’, ‘pb2coll’, ‘json2pb’, ‘dict2pb’, ‘coll2pb’]

mosstool.util.format_converter.pb2json(pb: google.protobuf.message.Message)

Convert a protobuf message to a JSON string.

Args:

  • pb: The protobuf message to be converted.

Returns:

  • The JSON string.

mosstool.util.format_converter.pb2dict(pb: google.protobuf.message.Message)

Convert a protobuf message to a Python dictionary.

Args:

  • pb: The protobuf message to be converted.

Returns:

  • The Python dict.

mosstool.util.format_converter.pb2coll(pb: google.protobuf.message.Message, coll: pymongo.collection.Collection, insert_chunk_size: int = 0, drop: bool = False)

Convert a protobuf message to a MongoDB collection.

Args:

  • pb: The protobuf message to be converted.

  • coll: The MongoDB collection to be inserted.

  • insert_chunk_size: The chunk size for inserting the collection. If it is 0, insert all the data at once.

  • drop: Drop the MongoDB collection or not. True for drop, False for not.

mosstool.util.format_converter.T

‘TypeVar(…)’

mosstool.util.format_converter.json2pb(json: str, pb: mosstool.util.format_converter.T) mosstool.util.format_converter.T

Convert a JSON string to a protobuf message.

Args:

  • json: The JSON string to be converted.

  • pb: The protobuf message to be filled.

Returns:

  • The protobuf message.

mosstool.util.format_converter.dict2pb(d: dict, pb: mosstool.util.format_converter.T) mosstool.util.format_converter.T

Convert a Python dictionary to a protobuf message.

Args:

  • d: The Python dict to be converted.

  • pb: The protobuf message to be filled.

Returns:

  • The protobuf message.

mosstool.util.format_converter.coll2pb(coll: pymongo.collection.Collection, pb: mosstool.util.format_converter.T) mosstool.util.format_converter.T

Convert a MongoDB collection to a protobuf message.

Args:

  • coll: The MongoDB collection to be converted.

  • pb: The protobuf message to be filled.

Returns:

  • The protobuf message.