narupa.utilities.protobuf_utilities module¶
-
narupa.utilities.protobuf_utilities.
deep_copy_serializable_dict
(dictionary: Dict[str, Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]]]) → Dict[str, Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]]]¶ Makes a deep copy of a dictionary by converting it to a protobuf Struct and back. Only protobuf serializable elements will be preserved.
-
narupa.utilities.protobuf_utilities.
dict_to_struct
(dictionary: Dict[str, Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]]]) → google.protobuf.struct_pb2.Struct¶ Converts a python dictionary to a protobuf
Struct
. The dictionary must consist of types that can be serialised.Parameters: dictionary – Dictionary to convert. Returns: Struct
containing copies of all the items of the dictionary.
-
narupa.utilities.protobuf_utilities.
list_value_to_list
(list: google.protobuf.struct_pb2.ListValue) → List[Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]]]¶ Converts a protobuf
ListValue
to a python dictionary.Parameters: list – ListValue
to convert.Returns: A list containing copies of all the items in the list value.
-
narupa.utilities.protobuf_utilities.
object_to_value
(obj: Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]]) → google.protobuf.struct_pb2.Value¶ Convert a python object in an equivalent protobuf Value. :param obj: A python object. :return: A protobuf Value equivalent to the given object.
-
narupa.utilities.protobuf_utilities.
struct_to_dict
(struct: google.protobuf.struct_pb2.Struct) → Dict[str, Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]]]¶ Converts a protobuf
Struct
to a python dictionary.Parameters: struct – Struct
to convert.Returns: A dictionary containing copies of all the items in the struct.
-
narupa.utilities.protobuf_utilities.
value_to_object
(value: google.protobuf.struct_pb2.Value) → Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]]¶ Converts a protobuf Value into an equivalent python object. :param value: A protobuf Value to convert. :return: A python object equivalent to the given protobuf Value.