blob: fdf00c4de0cddccd5efb2239b4135a2651540353 [file]
# WARNING: This file is machine generated by fidlgen.
from __future__ import annotations
from dataclasses import dataclass
import sys
import typing
import enum
import fidl
from fidl._client import EventHandlerBase, FidlClient # type: ignore[unused-ignore,unused-import]
from fidl._server import ServerBase # type: ignore[unused-ignore,unused-import]
from fidl._fidl_common import DomainError, FrameworkError, MethodInfo, FidlProtocolMarker, normalize_identifier # type: ignore[unused-ignore,unused-import]
from abc import abstractmethod, ABC # type: ignore[unused-ignore,unused-import]
import collections.abc # type: ignore[unused-ignore,unused-import]
_UNDEFINED: typing.Any = object()
@dataclass
class Int32Wrapper:
val: int
__fidl_kind__ = "struct"
__fidl_type__ = "Int32Wrapper"
__fidl_raw_type__ = "test.nullable/Int32Wrapper"
# 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)
def encode(self) -> tuple[bytes, list[typing.Any]]:
return fidl.encode_struct(self, type(self)._encode, 4)
@classmethod
def decode(cls, data: bytes, handles: list[typing.Any]) -> typing.Self:
return fidl.decode_struct(data, handles, cls._decode, 4)
def _encode(self, encoder: fidl.Encoder, _offset: int) -> None:
encoder.write_int32(self.val, _offset + 0)
@classmethod
def _decode(cls, decoder: fidl.Decoder, _offset: int) -> typing.Self:
val = decoder.read_int32(_offset + 0)
return cls(
val=val,
)
# 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(
**{
"val": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class SimpleProtocolAddRequest:
a: int
b: int
__fidl_kind__ = "struct"
__fidl_type__ = "SimpleProtocolAddRequest"
__fidl_raw_type__ = "test.nullable/SimpleProtocolAddRequest"
# 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)
def encode(self) -> tuple[bytes, list[typing.Any]]:
return fidl.encode_struct(self, type(self)._encode, 8)
@classmethod
def decode(cls, data: bytes, handles: list[typing.Any]) -> typing.Self:
return fidl.decode_struct(data, handles, cls._decode, 8)
def _encode(self, encoder: fidl.Encoder, _offset: int) -> None:
encoder.write_int32(self.a, _offset + 0)
encoder.write_int32(self.b, _offset + 4)
@classmethod
def _decode(cls, decoder: fidl.Decoder, _offset: int) -> typing.Self:
a = decoder.read_int32(_offset + 0)
b = decoder.read_int32(_offset + 4)
return cls(
a=a,
b=b,
)
# 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(
**{
"a": None, # type: ignore[arg-type,unused-ignore]
"b": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class SimpleProtocolAddResponse:
sum_: int
__fidl_kind__ = "struct"
__fidl_type__ = "SimpleProtocolAddResponse"
__fidl_raw_type__ = "test.nullable/SimpleProtocolAddResponse"
# 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)
def encode(self) -> tuple[bytes, list[typing.Any]]:
return fidl.encode_struct(self, type(self)._encode, 4)
@classmethod
def decode(cls, data: bytes, handles: list[typing.Any]) -> typing.Self:
return fidl.decode_struct(data, handles, cls._decode, 4)
def _encode(self, encoder: fidl.Encoder, _offset: int) -> None:
encoder.write_int32(self.sum_, _offset + 0)
@classmethod
def _decode(cls, decoder: fidl.Decoder, _offset: int) -> typing.Self:
sum_ = decoder.read_int32(_offset + 0)
return cls(
sum_=sum_,
)
# 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(
**{
"sum_": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class StructWithNullableHandle:
val: typing.Optional[int]
__fidl_kind__ = "struct"
__fidl_type__ = "StructWithNullableHandle"
__fidl_raw_type__ = "test.nullable/StructWithNullableHandle"
# 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)
def encode(self) -> tuple[bytes, list[typing.Any]]:
return fidl.encode_struct(self, type(self)._encode, 4)
@classmethod
def decode(cls, data: bytes, handles: list[typing.Any]) -> typing.Self:
return fidl.decode_struct(data, handles, cls._decode, 4)
def _encode(self, encoder: fidl.Encoder, _offset: int) -> None:
encoder.write_handle(
self.val, _offset + 0, obj_type=3, rights=2147483648
)
@classmethod
def _decode(cls, decoder: fidl.Decoder, _offset: int) -> typing.Self:
val = decoder.read_handle(_offset + 0, nullable=True)
return cls(
val=val,
)
# 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(
**{
"val": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class StructWithNullableProtocol:
val: typing.Optional[int]
__fidl_kind__ = "struct"
__fidl_type__ = "StructWithNullableProtocol"
__fidl_raw_type__ = "test.nullable/StructWithNullableProtocol"
# 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)
def encode(self) -> tuple[bytes, list[typing.Any]]:
return fidl.encode_struct(self, type(self)._encode, 4)
@classmethod
def decode(cls, data: bytes, handles: list[typing.Any]) -> typing.Self:
return fidl.decode_struct(data, handles, cls._decode, 4)
def _encode(self, encoder: fidl.Encoder, _offset: int) -> None:
encoder.write_handle(self.val, _offset + 0, obj_type=4, rights=61454)
@classmethod
def _decode(cls, decoder: fidl.Decoder, _offset: int) -> typing.Self:
val = decoder.read_handle(_offset + 0, nullable=True)
return cls(
val=val,
)
# 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(
**{
"val": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class StructWithNullableRequest:
val: typing.Optional[int]
__fidl_kind__ = "struct"
__fidl_type__ = "StructWithNullableRequest"
__fidl_raw_type__ = "test.nullable/StructWithNullableRequest"
# 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)
def encode(self) -> tuple[bytes, list[typing.Any]]:
return fidl.encode_struct(self, type(self)._encode, 4)
@classmethod
def decode(cls, data: bytes, handles: list[typing.Any]) -> typing.Self:
return fidl.decode_struct(data, handles, cls._decode, 4)
def _encode(self, encoder: fidl.Encoder, _offset: int) -> None:
encoder.write_handle(self.val, _offset + 0, obj_type=4, rights=61454)
@classmethod
def _decode(cls, decoder: fidl.Decoder, _offset: int) -> typing.Self:
val = decoder.read_handle(_offset + 0, nullable=True)
return cls(
val=val,
)
# 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(
**{
"val": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class StructWithNullableString:
val: typing.Optional[str]
__fidl_kind__ = "struct"
__fidl_type__ = "StructWithNullableString"
__fidl_raw_type__ = "test.nullable/StructWithNullableString"
# 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)
def encode(self) -> tuple[bytes, list[typing.Any]]:
return fidl.encode_struct(self, type(self)._encode, 16)
@classmethod
def decode(cls, data: bytes, handles: list[typing.Any]) -> typing.Self:
return fidl.decode_struct(data, handles, cls._decode, 16)
def _encode(self, encoder: fidl.Encoder, _offset: int) -> None:
encoder.write_string(self.val, _offset + 0)
@classmethod
def _decode(cls, decoder: fidl.Decoder, _offset: int) -> typing.Self:
val = decoder.read_string(_offset + 0, nullable=True)
return cls(
val=val,
)
# 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(
**{
"val": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class StructWithNullableStruct:
val: typing.Optional[Int32Wrapper]
__fidl_kind__ = "struct"
__fidl_type__ = "StructWithNullableStruct"
__fidl_raw_type__ = "test.nullable/StructWithNullableStruct"
# 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)
def encode(self) -> tuple[bytes, list[typing.Any]]:
return fidl.encode_struct(self, type(self)._encode, 8)
@classmethod
def decode(cls, data: bytes, handles: list[typing.Any]) -> typing.Self:
return fidl.decode_struct(data, handles, cls._decode, 8)
def _encode(self, encoder: fidl.Encoder, _offset: int) -> None:
encoder.write_optional_struct(
self.val, _offset + 0, Int32Wrapper._encode, 4
)
@classmethod
def _decode(cls, decoder: fidl.Decoder, _offset: int) -> typing.Self:
val = decoder.read_optional_struct(_offset + 0, Int32Wrapper._decode, 4)
return cls(
val=val,
)
# 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(
**{
"val": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class StructWithNullableUnion:
val: typing.Optional[SimpleUnion]
__fidl_kind__ = "struct"
__fidl_type__ = "StructWithNullableUnion"
__fidl_raw_type__ = "test.nullable/StructWithNullableUnion"
# 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)
def encode(self) -> tuple[bytes, list[typing.Any]]:
return fidl.encode_struct(self, type(self)._encode, 16)
@classmethod
def decode(cls, data: bytes, handles: list[typing.Any]) -> typing.Self:
return fidl.decode_struct(data, handles, cls._decode, 16)
def _encode(self, encoder: fidl.Encoder, _offset: int) -> None:
if self.val is not None:
SimpleUnion._encode(self.val, encoder, _offset + 0)
else:
encoder.write_inline(_offset + 0, b"\x00" * 16)
@classmethod
def _decode(cls, decoder: fidl.Decoder, _offset: int) -> typing.Self:
val = (
None
if decoder.read_uint64(_offset + 0) == 0
else SimpleUnion._decode(decoder, _offset + 0)
)
return cls(
val=val,
)
# 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(
**{
"val": None, # type: ignore[arg-type,unused-ignore]
}
)
@dataclass
class StructWithNullableVector:
val: typing.Optional[typing.Sequence[int]]
__fidl_kind__ = "struct"
__fidl_type__ = "StructWithNullableVector"
__fidl_raw_type__ = "test.nullable/StructWithNullableVector"
# 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)
def encode(self) -> tuple[bytes, list[typing.Any]]:
return fidl.encode_struct(self, type(self)._encode, 16)
@classmethod
def decode(cls, data: bytes, handles: list[typing.Any]) -> typing.Self:
return fidl.decode_struct(data, handles, cls._decode, 16)
def _encode(self, encoder: fidl.Encoder, _offset: int) -> None:
encoder.write_vector(
self.val,
_offset + 0,
lambda val, enc, off: enc.write_int32(val, off),
4,
)
@classmethod
def _decode(cls, decoder: fidl.Decoder, _offset: int) -> typing.Self:
val = decoder.read_vector(
_offset + 0, lambda dec, off: dec.read_int32(off), 4, nullable=True
)
return cls(
val=val,
)
# 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(
**{
"val": None, # type: ignore[arg-type,unused-ignore]
}
)
class SimpleUnion:
_a: typing.Optional[int]
_b: typing.Optional[float]
__fidl_kind__ = "union"
__fidl_type__ = "SimpleUnion"
__fidl_raw_type__ = "test.nullable/SimpleUnion"
_is_result = False
def __eq__(self, other: object) -> bool:
if not isinstance(other, type(self)):
return False
if self.a != other.a:
return False
if self.b != other.b:
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.a:
variant = f"a={self.a!r}"
if self.b:
variant = f"b={self.b!r}"
return f"<'{self.__fidl_type__}' object({variant})>"
def __init__(
self,
a: typing.Optional[int] = _UNDEFINED,
b: typing.Optional[float] = _UNDEFINED,
_empty: typing.Optional[tuple[()]] = None,
):
object.__init__(self)
if _empty is not None:
return
number_of_variants = 0
variants = []
if a is not _UNDEFINED:
if a is not None:
self._a = a
variants.append("a")
number_of_variants += 1
if b is not _UNDEFINED:
if b is not None:
self._b = b
variants.append("b")
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 a(self) -> int | None:
return getattr(self, "_a", None)
@property
def b(self) -> float | None:
return getattr(self, "_b", 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)
def encode(self) -> tuple[bytes, list[typing.Any]]:
return fidl.encode_struct(self, type(self)._encode, 16)
@classmethod
def decode(cls, data: bytes, handles: list[typing.Any]) -> typing.Self:
return fidl.decode_struct(data, handles, cls._decode, 16)
def _encode(self, encoder: fidl.Encoder, _offset: int) -> None:
if hasattr(self, "_a"):
encoder.write_uint64(1, _offset)
encoder.write_envelope(
getattr(self, "_a"),
_offset + 8,
lambda val, enc, off: enc.write_int32(val, off),
4,
True,
)
return
if hasattr(self, "_b"):
encoder.write_uint64(2, _offset)
encoder.write_envelope(
getattr(self, "_b"),
_offset + 8,
lambda val, enc, off: enc.write_float32(val, off),
4,
True,
)
return
encoder.write_inline(_offset, b"\x00" * 16)
@classmethod
def _decode(cls, decoder: fidl.Decoder, _offset: int) -> typing.Self:
ordinal = decoder.read_uint64(_offset)
if ordinal == 0:
return cls(_empty=())
if ordinal == 1:
val = decoder.read_envelope(
_offset + 8,
lambda dec, off: dec.read_int32(off),
4,
)
return cls(a=val)
if ordinal == 2:
val = decoder.read_envelope(
_offset + 8,
lambda dec, off: dec.read_float32(off),
4,
)
return cls(b=val)
# Skip unknown envelope
decoder.skip_envelope(_offset + 8)
raise ValueError(f"Unknown union ordinal {ordinal}")
@classmethod
def make_default(cls) -> typing.Self:
return cls(_empty=())
class SimpleProtocolServer(ServerBase, ABC):
__fidl_kind__ = "server"
library = "test.nullable"
method_map: typing.Dict[int, MethodInfo] = {
9142761280038437494: MethodInfo(
name="add",
request_ident="test.nullable/SimpleProtocolAddRequest",
requires_response=True,
empty_response=False,
has_result=False,
response_identifier="test.nullable/SimpleProtocolAddResponse",
),
}
AddResponse: typing.TypeAlias = SimpleProtocolAddResponse
@abstractmethod
def add(
self,
request: SimpleProtocolAddRequest,
) -> (
collections.abc.Coroutine[typing.Any, typing.Any, AddResponse]
| AddResponse
):
...
class SimpleProtocolClient(FidlClient):
__fidl_kind__ = "client"
library = "test.nullable"
def add(
self,
*,
a: int,
b: int,
) -> collections.abc.Coroutine[
typing.Any, typing.Any, SimpleProtocolAddResponse
]:
msg = SimpleProtocolAddRequest(
a,
b,
)
ret = self._send_two_way_fidl_request(
9142761280038437494,
"test.nullable",
msg,
SimpleProtocolAddResponse,
)
return ret
class SimpleProtocolEventHandler(EventHandlerBase, ABC):
__fidl_kind__ = "event_handler"
library = "test.nullable"
method_map: typing.Dict[int, MethodInfo] = {}
SimpleProtocolMarker = FidlProtocolMarker(
"(nondiscoverable) test.nullable/SimpleProtocol"
)
fidl.register_method(
9142761280038437494,
SimpleProtocolAddRequest,
SimpleProtocolAddResponse,
)