here.content.utils.proto module
here.content.utils.proto module
Utility to handle data encoded in protobuf format
here.content.utils.proto.decode_enum(msg: Message, field: str) str
Decode an enum field of a message to string.
Parameters:
-
msg – the protobuf message containing the field
-
field – the name of fields
Returns:
the resulting enum converted to string
Raises:
-
KeyError – in case the message doesn’t contain the expected field
-
ValueError – in case the value can not be mapped to an enum value
here.content.utils.proto.decode_enum_array(msg: Message, field: str, is_required: bool = True) List[str]
Decode an enum field of a message to string.
Parameters:
-
msg – the protobuf message containing the field
-
field – the name of fields
-
is_required – determines if the field is a required field
Returns:
the resulting enum values converted to a list of string
Raises:
-
KeyError – in case the field is required & message doesn’t contain the expected field
-
ValueError – in case the value can not be mapped to an enum value
-
TypeError – in case the value of the field is not iterable
here.content.utils.proto.decode_message(msg: Message, ignore: List[str] = []) DecodedMessage
Decode a protobuf message to a dictionary, recursively.
Parameters:
-
msg – the protobuf message to convert
-
ignore – the name of fields to ignore
Returns:
the resulting dictionary
here.content.utils.proto.has_field(msg: Message, field: str) bool
Checks whether field is present in the Message and returns boolean value instead of raising a ValueError.
Parameters:
-
msg – the protobuf message containing the field.
-
field – the name of field.
Returns:
whether field is present in the message.
here.content.utils.proto.has_field_attr(msg: Message, field: str) bool
Checks whether field is present in the Message and returns boolean value instead of raising a ValueError.
Parameters:
-
msg – the protobuf message containing the field.
-
field – the name of field.
Returns:
whether field is present in the message.
here.content.utils.proto.parse_linestring(msg) LineString
Parse an HMC line string with optional elevation.
here.content.utils.proto.parse_multi_polygon(msg) MultiPolygon
Parse an HMC multi polygon with optional elevation.
here.content.utils.proto.parse_point(msg) Point
Parse an HMC point with optional elevation.
here.content.utils.proto.parse_ref(msg) Ref
Parse a HMC reference.
here.content.utils.proto.value_or_None(msg: Message, field: str) Any
Returns the value of a field if the field exists.
Parameters:
-
msg – the protobuf message containing the field.
-
field – the name of field.
Returns:
value of the field if the field exists or None otherwise.