| {{/* |
| // 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 "BitsDeclaration" -}} |
| class {{ .PythonName }}(enum.IntFlag): |
| {{- if .DocComments }} |
| """ |
| {{- range .DocComments }} |
| {{ . | escapeQuotes | trimSpace | indentNonEmpty4 }} |
| {{- end }} |
| """ |
| {{- end }} |
| {{ range .PythonMembers -}} |
| {{ .PythonName }} = {{ .PythonValue }} |
| {{ end }} |
| {{- if .Empty -}} |
| EMPTY__ = 0 |
| {{ end -}} |
| |
| __fidl_kind__ = "bits" |
| __fidl_type__ = "{{ .PythonName }}" |
| __fidl_raw_type__ = "{{ .Name }}" |
| __strict__ = {{ if .Strictness }}True{{ else }}False{{ end }} |
| __fidl_inline_size__ = {{ .Type.PrimitiveSubtype.NumberOfBytes }} |
| |
| def _encode(self: int, enc: fidl.Encoder, off: int) -> None: |
| enc.write_{{ .Type.PrimitiveSubtype }}(int(self), off) |
| |
| @classmethod |
| def _decode(cls, dec: fidl.Decoder, off: int) -> typing.Self: |
| return cls(dec.read_{{ .Type.PrimitiveSubtype }}(off)) |
| |
| @classmethod |
| def make_default(cls) -> typing.Self: |
| return cls(value=0) |
| |
| |
| |
| {{ end }} |