| {{/* |
| // 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 "StructDeclaration" -}} |
| @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 }} |
| {{- end }} |
| |
| __fidl_kind__ = "struct" |
| __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 }}") |
| |
| # TODO(https://fxbug.dev/394421154): Assigning None (incorrectly) to each type is a consequence |
| # of needing to support creation of a "default object" before decoding. |
| @classmethod |
| def make_default(cls) -> typing.Self: |
| return cls(**{ |
| {{- range .PythonMembers }} |
| "{{ .PythonName }}": None, # type: ignore[arg-type,unused-ignore] |
| {{- end }} |
| }) |
| |
| |
| {{ end }} |