| {{/* |
| // Copyright 2025 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| */}} |
| |
| {{/* |
| // TODO(https://fxbug.dev/394421154): This should really be a class that inherits from enum.IntFlag, |
| // but doing so requires creating a new GIDL backend because the fuchsia-controller backend |
| // generates tests that use ints for the value of bits types. |
| */}} |
| {{ define "EnumDeclaration" -}} |
| class {{ .PythonName }}(enum.{{ if .Strictness }}IntEnum{{ else }}IntFlag{{ end }}): |
| {{- if .DocComments }} |
| """ |
| {{- range .DocComments }} |
| {{ . | escapeQuotes | trimSpace | indentNonEmpty4 }} |
| {{- end }} |
| """ |
| {{- end }} |
| {{ range .PythonMembers -}} |
| {{ .PythonName }} = {{ .PythonValue }} |
| {{ end }} |
| {{- if or .Empty (not .HasZero) -}} |
| EMPTY__ = 0 |
| {{ end -}} |
| |
| {{ if not .Strictness -}} |
| @property |
| def name(self) -> str: |
| name = super().name |
| return name if name is not None else f"UNKNOWN_{int(self)}" |
| {{- end }} |
| |
| |
| __fidl_kind__ = "enum" |
| __fidl_type__ = "{{ .PythonName }}" |
| __fidl_raw_type__ = "{{ .Name }}" |
| __strict__ = {{ if .Strictness }}True{{ else }}False{{ end }} |
| __fidl_inline_size__ = {{ .Type.NumberOfBytes }} |
| |
| def _encode(self: int, enc: fidl.Encoder, off: int) -> None: |
| enc.write_{{ .Type }}(int(self), off) |
| |
| @classmethod |
| def _decode(cls, dec: fidl.Decoder, off: int) -> typing.Self: |
| return cls(dec.read_{{ .Type }}(off)) |
| |
| @classmethod |
| def make_default(cls) -> typing.Self: |
| return cls(0) |
| |
| |
| |
| {{ end }} |