narupatools.core.protobuf

Protobuf utilities which support more options than the base Narupa converter.

Functions

dictionary_to_protobuf

Convert an arbitrary mapping to a protobuf Struct.

update_struct

Update a protobuf struct in place from a dictionary-like object.

narupatools.core.protobuf.dictionary_to_protobuf(mapping: Mapping[str, Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]])google.protobuf.struct_pb2.Struct

Convert an arbitrary mapping to a protobuf Struct.

Improved version of dict_to_struct(), that can serialize more complex types such as iterables, mappings and NumPy arrays.

Parameters

mapping – Dictionary to convert.

Returns

Struct containing copies of all the items of the dictionary.

narupatools.core.protobuf.update_struct(struct: google.protobuf.struct_pb2.Struct, mapping: Mapping[str, Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]])None

Update a protobuf struct in place from a dictionary-like object.

Parameters
  • struct – Struct to update.

  • mapping – Mapping to provide values to insert into struct.

Exceptions

ProtobufSerialisationError(obj)

Error raised when something cannot be serialized to protobuf.