| {{/* |
| // 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. |
| */}} |
| |
| {{ define "TableDeclaration" -}} |
| @dataclass |
| class {{ .PythonName }}: |
| {{- if .DocComments }} |
| """ |
| {{- range .DocComments }} |
| {{ . | escapeQuotes | trimSpace | indentNonEmpty4 }} |
| {{- end }} |
| """ |
| {{- end }} |
| {{- range .PythonMembers }} |
| {{- if .DocComments }} |
| """ |
| {{- range .DocComments }} |
| {{ . | escapeQuotes | trimSpace | indentNonEmpty4 }} |
| {{- end }} |
| """ |
| {{- end }} |
| {{ .PythonName }}: {{ .PythonType.PythonName }} | None |
| {{- end }} |
| |
| {{ if .PythonMembers -}} |
| def __init__( |
| self, |
| {{- range .PythonMembers }} |
| {{ .PythonName }}: {{ .PythonType.PythonName }} | None = None, |
| {{- end }} |
| ) -> None: |
| {{- range .PythonMembers }} |
| self.{{ .PythonName }} = {{ .PythonName }} |
| {{- end -}} |
| {{- end }} |
| |
| __fidl_kind__ = "table" |
| __fidl_type__ = "{{ .PythonName }}" |
| __fidl_raw_type__ = "{{ .Name }}" |
| |
| # TODO(https://fxbug.dev/394421154): We should probably remove this method when we |
| # start making breaking changes. |
| def __getitem__(self, item: str): # type: ignore |
| if not isinstance(item, str): |
| raise TypeError("Subscripted item must be a string") |
| return getattr(self, item) |
| |
| # TODO(https://fxbug.dev/394421154): We should probably return a more readable type. |
| def encode(self) -> tuple[bytes, list[tuple[int, int, int, int, int]]]: |
| return encode_fidl_object(self, "{{ .Library }}", "{{ .Name }}") |
| |
| @classmethod |
| def make_default(cls) -> typing.Self: |
| return cls() |
| |
| |
| {{ end }} |