schema.utils.proto_enum_converter.ProtoEnumConverter

Class for converting between proto enums and strings.

enum_message The proto enum message definition.
enum_display_name The loggable proto enum message name.
mapping The mapping between the proto enum name and the string representation.
enum_unspecified The enum value that corresponds to unspecified.
default_when_unspecified The default value that should be returned when the proto enum is unspecified.

Methods

from_proto

View source

Converts a proto enum to its string representation.

Args
proto_enum The enum value to convert to its string representation

Returns
The string representation of the given proto_enum or the default value when the proto enum is unspecified.

Raises
ValueError when given proto enum is not found in the mapping.

to_proto

View source

Converts a string to its corresponding proto enum.

Args
string_value The string to convert to a proto enum.

Returns
The corresponding proto enum or enum_unspecified when the enum message doesn't exist.

Raises
ValueError when given string is not found in the mapping.