schema.utils.proto_enum_converter.ProtoEnumConverter
Stay organized with collections
Save and categorize content based on your preferences.
Class for converting between proto enums and strings.
schema.utils.proto_enum_converter.ProtoEnumConverter(
enum_message: Type[schema.utils.proto_enum_converter.EnumType],
enum_display_name: str,
mapping: bidict.bidict,
enum_unspecified: schema.utils.proto_enum_converter.EnumType,
default_when_unspecified: schema.utils.proto_enum_converter.DefaultType
)
Arguments |
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
from_proto(
proto_enum: schema.utils.proto_enum_converter.EnumType
) -> (str | schema.utils.proto_enum_converter.DefaultType)
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
to_proto(
string_value: (str | None)
) -> schema.utils.proto_enum_converter.EnumType
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.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-01-28 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-01-28 UTC."],[],[]]