|
13 | 13 | from ...model.core import ContractId |
14 | 14 | from ...model.types import VariantType, RecordType, ListType, ContractIdType, \ |
15 | 15 | UnsupportedType, TemplateChoice, TypeReference, TypeEvaluationContext, SCALAR_TYPE_UNIT, \ |
16 | | - MapType, OptionalType |
| 16 | + MapType, OptionalType, EnumType |
17 | 17 | from ...model.writing import AbstractSerializer, CommandPayload |
18 | 18 | from ...util.prim_types import to_boolean, to_date, to_datetime, to_decimal, to_int, to_str, \ |
19 | 19 | decode_variant_dict |
@@ -244,6 +244,12 @@ def serialize_variant(self, context: TypeEvaluationContext, tt: VariantType, obj |
244 | 244 | _set_value(variant_message.value, ctor, value) |
245 | 245 | return 'variant', variant_message |
246 | 246 |
|
| 247 | + def serialize_enum(self, context: TypeEvaluationContext, tt: EnumType, obj: Any) -> R: |
| 248 | + from ..._gen.com.digitalasset.ledger.api.v1.value_pb2 import Enum |
| 249 | + enum_message = Enum() |
| 250 | + enum_message.constructor = obj |
| 251 | + return 'enum', enum_message |
| 252 | + |
247 | 253 | def serialize_unsupported( |
248 | 254 | self, context: TypeEvaluationContext, tt: UnsupportedType, obj: Any) -> R: |
249 | 255 | raise Exception(f'UnsupportedType {tt} is not serializable in gRPC') |
@@ -275,7 +281,7 @@ def _set_value(message: G.Value, ctor: 'Optional[str]', value) -> None: |
275 | 281 | message.MergeFrom(value) |
276 | 282 | elif ctor == 'unit': |
277 | 283 | message.unit.SetInParent() |
278 | | - elif ctor in ('record', 'variant', 'list', 'optional'): |
| 284 | + elif ctor in ('record', 'variant', 'list', 'optional', 'enum'): |
279 | 285 | getattr(message, ctor).MergeFrom(value) |
280 | 286 | else: |
281 | 287 | setattr(message, ctor, value) |
|
0 commit comments