blob: 006eab666de0a6ba319e7087cf76fbdcf3fd85eb [file] [log] [blame] [edit]
# WARNING: This file is machine generated by fidlgen.
from __future__ import annotations
from dataclasses import dataclass
from fidl_codec import add_ir_path, encode_fidl_object
import sys
import typing
import enum
import fidl
from fidl._ir import get_fidl_ir_map
_ir_path = get_fidl_ir_map()["test.requestflexibleenvelope"]
add_ir_path(_ir_path)
@dataclass
class ProtocolRequestFlexibleResponseStrictRequest:
s: FlexibleFoo
__fidl_kind__ = "struct"
__fidl_type__ = "ProtocolRequestFlexibleResponseStrictRequest"
__fidl_raw_type__ = "test.requestflexibleenvelope/ProtocolRequestFlexibleResponseStrictRequest"
# 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,
"test.requestflexibleenvelope",
"test.requestflexibleenvelope/ProtocolRequestFlexibleResponseStrictRequest",
)
# 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(
**{
"s": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class ProtocolRequestFlexibleResponseStrictResponse:
f: StrictFoo
__fidl_kind__ = "struct"
__fidl_type__ = "ProtocolRequestFlexibleResponseStrictResponse"
__fidl_raw_type__ = "test.requestflexibleenvelope/ProtocolRequestFlexibleResponseStrictResponse"
# 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,
"test.requestflexibleenvelope",
"test.requestflexibleenvelope/ProtocolRequestFlexibleResponseStrictResponse",
)
# 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(
**{
"f": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class ProtocolRequestStrictResponseFlexibleRequest:
s: StrictFoo
__fidl_kind__ = "struct"
__fidl_type__ = "ProtocolRequestStrictResponseFlexibleRequest"
__fidl_raw_type__ = "test.requestflexibleenvelope/ProtocolRequestStrictResponseFlexibleRequest"
# 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,
"test.requestflexibleenvelope",
"test.requestflexibleenvelope/ProtocolRequestStrictResponseFlexibleRequest",
)
# 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(
**{
"s": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class ProtocolRequestStrictResponseFlexibleResponse:
f: FlexibleFoo
__fidl_kind__ = "struct"
__fidl_type__ = "ProtocolRequestStrictResponseFlexibleResponse"
__fidl_raw_type__ = "test.requestflexibleenvelope/ProtocolRequestStrictResponseFlexibleResponse"
# 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,
"test.requestflexibleenvelope",
"test.requestflexibleenvelope/ProtocolRequestStrictResponseFlexibleResponse",
)
# 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(
**{
"f": None, # type: ignore[arg-type,unused-ignore]
}
)
class FlexibleFoo:
_s: typing.Optional[str]
_i: typing.Optional[int]
__fidl_kind__ = "union"
__fidl_type__ = "FlexibleFoo"
__fidl_raw_type__ = "test.requestflexibleenvelope/FlexibleFoo"
_is_result = False
def __eq__(self, other: object) -> bool:
if not isinstance(other, type(self)):
return False
if self.s != other.s:
return False
if self.i != other.i:
return False
return True
def __repr__(self) -> str:
"""Returns the union repr in the format <'foo.bar.baz/FooUnion' object({value})>
If {value} is not set, will write None."""
variant = ""
if self.s:
variant = f"s={self.s!r}"
if self.i:
variant = f"i={self.i!r}"
return f"<'{self.__fidl_type__}' object({variant})>"
def __init__(
self,
s: typing.Optional[str] = None,
i: typing.Optional[int] = None,
_empty: typing.Optional[tuple[()]] = None,
):
object.__init__(self)
if _empty is not None:
return
number_of_variants = 0
variants = []
if s is not None:
self._s = s
variants.append("s")
number_of_variants += 1
if i is not None:
self._i = i
variants.append("i")
number_of_variants += 1
if number_of_variants != 1:
raise TypeError(
f"Exactly one variant must be specified for {self.__fidl_raw_type__}: {variants}"
)
@property
def s(self) -> str | None:
return getattr(self, "_s", None)
@property
def i(self) -> int | None:
return getattr(self, "_i", None)
# 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,
"test.requestflexibleenvelope",
"test.requestflexibleenvelope/FlexibleFoo",
)
@classmethod
def make_default(cls) -> typing.Self:
return cls(_empty=())
class StrictFoo:
_s: typing.Optional[str]
_i: typing.Optional[int]
__fidl_kind__ = "union"
__fidl_type__ = "StrictFoo"
__fidl_raw_type__ = "test.requestflexibleenvelope/StrictFoo"
_is_result = False
def __eq__(self, other: object) -> bool:
if not isinstance(other, type(self)):
return False
if self.s != other.s:
return False
if self.i != other.i:
return False
return True
def __repr__(self) -> str:
"""Returns the union repr in the format <'foo.bar.baz/FooUnion' object({value})>
If {value} is not set, will write None."""
variant = ""
if self.s:
variant = f"s={self.s!r}"
if self.i:
variant = f"i={self.i!r}"
return f"<'{self.__fidl_type__}' object({variant})>"
def __init__(
self,
s: typing.Optional[str] = None,
i: typing.Optional[int] = None,
_empty: typing.Optional[tuple[()]] = None,
):
object.__init__(self)
if _empty is not None:
return
number_of_variants = 0
variants = []
if s is not None:
self._s = s
variants.append("s")
number_of_variants += 1
if i is not None:
self._i = i
variants.append("i")
number_of_variants += 1
if number_of_variants != 1:
raise TypeError(
f"Exactly one variant must be specified for {self.__fidl_raw_type__}: {variants}"
)
@property
def s(self) -> str | None:
return getattr(self, "_s", None)
@property
def i(self) -> int | None:
return getattr(self, "_i", None)
# 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,
"test.requestflexibleenvelope",
"test.requestflexibleenvelope/StrictFoo",
)
@classmethod
def make_default(cls) -> typing.Self:
return cls(_empty=())
from fidl._client import EventHandlerBase, FidlClient
from fidl._server import ServerBase
from fidl._fidl_common import (
DomainError,
FrameworkError,
MethodInfo,
FidlProtocolMarker,
normalize_identifier,
)
from abc import abstractmethod, ABC
class ProtocolServer(ServerBase, ABC):
__fidl_kind__ = "server"
library = "test.requestflexibleenvelope"
method_map: typing.Dict[int, MethodInfo] = {
700529454616207123: MethodInfo(
name="request_strict_response_flexible",
request_ident="test.requestflexibleenvelope/ProtocolRequestStrictResponseFlexibleRequest",
requires_response=True,
empty_response=False,
has_result=False,
response_identifier="test.requestflexibleenvelope/ProtocolRequestStrictResponseFlexibleResponse",
),
5191655763393883319: MethodInfo(
name="request_flexible_response_strict",
request_ident="test.requestflexibleenvelope/ProtocolRequestFlexibleResponseStrictRequest",
requires_response=True,
empty_response=False,
has_result=False,
response_identifier="test.requestflexibleenvelope/ProtocolRequestFlexibleResponseStrictResponse",
),
}
@staticmethod
def construct_response_object(
response_ident: str, response_obj: typing.Any
) -> typing.Any:
import fidl._construct
return fidl._construct.construct_response_object(
response_ident, response_obj
)
RequestStrictResponseFlexibleResponse: typing.TypeAlias = (
ProtocolRequestStrictResponseFlexibleResponse
)
@abstractmethod
def request_strict_response_flexible(
self,
request: ProtocolRequestStrictResponseFlexibleRequest,
) -> (
typing.Coroutine[
typing.Any, typing.Any, RequestStrictResponseFlexibleResponse
]
| RequestStrictResponseFlexibleResponse
):
...
RequestFlexibleResponseStrictResponse: typing.TypeAlias = (
ProtocolRequestFlexibleResponseStrictResponse
)
@abstractmethod
def request_flexible_response_strict(
self,
request: ProtocolRequestFlexibleResponseStrictRequest,
) -> (
typing.Coroutine[
typing.Any, typing.Any, RequestFlexibleResponseStrictResponse
]
| RequestFlexibleResponseStrictResponse
):
...
class ProtocolClient(FidlClient):
__fidl_kind__ = "client"
library = "test.requestflexibleenvelope"
@staticmethod
def construct_response_object(
response_ident: str, response_obj: typing.Any
) -> typing.Any:
import fidl._construct
return fidl._construct.construct_response_object(
response_ident, response_obj
)
def request_strict_response_flexible(
self,
*,
s: StrictFoo,
) -> typing.Coroutine[
typing.Any, typing.Any, ProtocolRequestStrictResponseFlexibleResponse
]:
msg = ProtocolRequestStrictResponseFlexibleRequest(
s,
)
return self._send_two_way_fidl_request(
700529454616207123,
"test.requestflexibleenvelope",
msg,
normalize_identifier(
"test.requestflexibleenvelope/ProtocolRequestStrictResponseFlexibleResponse"
),
)
def request_flexible_response_strict(
self,
*,
s: FlexibleFoo,
) -> typing.Coroutine[
typing.Any, typing.Any, ProtocolRequestFlexibleResponseStrictResponse
]:
msg = ProtocolRequestFlexibleResponseStrictRequest(
s,
)
return self._send_two_way_fidl_request(
5191655763393883319,
"test.requestflexibleenvelope",
msg,
normalize_identifier(
"test.requestflexibleenvelope/ProtocolRequestFlexibleResponseStrictResponse"
),
)
class ProtocolEventHandler(EventHandlerBase, ABC):
__fidl_kind__ = "event_handler"
library = "test.requestflexibleenvelope"
method_map: typing.Dict[int, MethodInfo] = {}
@staticmethod
def construct_response_object(
response_ident: str, response_obj: typing.Any
) -> typing.Any:
import fidl._construct
return fidl._construct.construct_response_object(
response_ident, response_obj
)
ProtocolMarker = FidlProtocolMarker(
"(nondiscoverable) test.requestflexibleenvelope/Protocol"
)