#![warn(clippy::all)]
#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
use bitflags::bitflags;
use fidl::client::QueryResponseFut;
use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
use fidl::endpoints::{ControlHandle as _, Responder as _};
use futures::future::{self, MaybeDone, TryFutureExt};
use zx_status;
pub const POWER_STATE_CHARGING: u8 = 4;
pub const POWER_STATE_CRITICAL: u8 = 8;
pub const POWER_STATE_DISCHARGING: u8 = 2;
pub const POWER_STATE_ONLINE: u8 = 1;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(u32)]
pub enum BatteryUnit {
Mw = 0,
Ma = 1,
}
impl BatteryUnit {
#[inline]
pub fn from_primitive(prim: u32) -> Option<Self> {
match prim {
0 => Some(Self::Mw),
1 => Some(Self::Ma),
_ => None,
}
}
#[inline]
pub const fn into_primitive(self) -> u32 {
self as u32
}
#[deprecated = "Strict enums should not use `is_unknown`"]
#[inline]
pub fn is_unknown(&self) -> bool {
false
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(u8)]
pub enum PowerType {
Ac = 0,
Battery = 1,
}
impl PowerType {
#[inline]
pub fn from_primitive(prim: u8) -> Option<Self> {
match prim {
0 => Some(Self::Ac),
1 => Some(Self::Battery),
_ => None,
}
}
#[inline]
pub const fn into_primitive(self) -> u8 {
self as u8
}
#[deprecated = "Strict enums should not use `is_unknown`"]
#[inline]
pub fn is_unknown(&self) -> bool {
false
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct BatteryInfo {
pub unit: BatteryUnit,
pub design_capacity: u32,
pub last_full_capacity: u32,
pub design_voltage: u32,
pub capacity_warning: u32,
pub capacity_low: u32,
pub capacity_granularity_low_warning: u32,
pub capacity_granularity_warning_full: u32,
pub present_rate: i32,
pub remaining_capacity: u32,
pub present_voltage: u32,
pub battery_spec: BatterySpec,
}
impl fidl::Persistable for BatteryInfo {}
#[derive(Clone, Debug, PartialEq)]
pub struct SourceGetBatteryInfoResponse {
pub status: i32,
pub info: BatteryInfo,
}
impl fidl::Persistable for SourceGetBatteryInfoResponse {}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct SourceGetPowerInfoResponse {
pub status: i32,
pub info: SourceInfo,
}
impl fidl::Persistable for SourceGetPowerInfoResponse {}
#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct SourceGetStateChangeEventResponse {
pub status: i32,
pub handle: fidl::Event,
}
impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
for SourceGetStateChangeEventResponse
{
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct SourceInfo {
pub type_: PowerType,
pub state: u8,
}
impl fidl::Persistable for SourceInfo {}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct BatterySpec {
pub max_charging_current_ua: Option<i32>,
pub max_charnging_voltage_uv: Option<i32>,
pub design_capacity_uah: Option<i32>,
#[doc(hidden)]
pub __source_breaking: fidl::marker::SourceBreaking,
}
impl fidl::Persistable for BatterySpec {}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct SourceMarker;
impl fidl::endpoints::ProtocolMarker for SourceMarker {
type Proxy = SourceProxy;
type RequestStream = SourceRequestStream;
#[cfg(target_os = "fuchsia")]
type SynchronousProxy = SourceSynchronousProxy;
const DEBUG_NAME: &'static str = "(anonymous) Source";
}
pub trait SourceProxyInterface: Send + Sync {
type GetPowerInfoResponseFut: std::future::Future<Output = Result<(i32, SourceInfo), fidl::Error>>
+ Send;
fn r#get_power_info(&self) -> Self::GetPowerInfoResponseFut;
type GetStateChangeEventResponseFut: std::future::Future<Output = Result<(i32, fidl::Event), fidl::Error>>
+ Send;
fn r#get_state_change_event(&self) -> Self::GetStateChangeEventResponseFut;
type GetBatteryInfoResponseFut: std::future::Future<Output = Result<(i32, BatteryInfo), fidl::Error>>
+ Send;
fn r#get_battery_info(&self) -> Self::GetBatteryInfoResponseFut;
}
#[derive(Debug)]
#[cfg(target_os = "fuchsia")]
pub struct SourceSynchronousProxy {
client: fidl::client::sync::Client,
}
#[cfg(target_os = "fuchsia")]
impl fidl::endpoints::SynchronousProxy for SourceSynchronousProxy {
type Proxy = SourceProxy;
type Protocol = SourceMarker;
fn from_channel(inner: fidl::Channel) -> Self {
Self::new(inner)
}
fn into_channel(self) -> fidl::Channel {
self.client.into_channel()
}
fn as_channel(&self) -> &fidl::Channel {
self.client.as_channel()
}
}
#[cfg(target_os = "fuchsia")]
impl SourceSynchronousProxy {
pub fn new(channel: fidl::Channel) -> Self {
let protocol_name = <SourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
}
pub fn into_channel(self) -> fidl::Channel {
self.client.into_channel()
}
pub fn wait_for_event(
&self,
deadline: zx::MonotonicInstant,
) -> Result<SourceEvent, fidl::Error> {
SourceEvent::decode(self.client.wait_for_event(deadline)?)
}
pub fn r#get_power_info(
&self,
___deadline: zx::MonotonicInstant,
) -> Result<(i32, SourceInfo), fidl::Error> {
let _response =
self.client.send_query::<fidl::encoding::EmptyPayload, SourceGetPowerInfoResponse>(
(),
0x2dd7eb1cce18665d,
fidl::encoding::DynamicFlags::empty(),
___deadline,
)?;
Ok((_response.status, _response.info))
}
pub fn r#get_state_change_event(
&self,
___deadline: zx::MonotonicInstant,
) -> Result<(i32, fidl::Event), fidl::Error> {
let _response = self
.client
.send_query::<fidl::encoding::EmptyPayload, SourceGetStateChangeEventResponse>(
(),
0x67842daecf5e7f5e,
fidl::encoding::DynamicFlags::empty(),
___deadline,
)?;
Ok((_response.status, _response.handle))
}
pub fn r#get_battery_info(
&self,
___deadline: zx::MonotonicInstant,
) -> Result<(i32, BatteryInfo), fidl::Error> {
let _response =
self.client.send_query::<fidl::encoding::EmptyPayload, SourceGetBatteryInfoResponse>(
(),
0x686f3c82ad2b91cd,
fidl::encoding::DynamicFlags::empty(),
___deadline,
)?;
Ok((_response.status, _response.info))
}
}
#[derive(Debug, Clone)]
pub struct SourceProxy {
client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
}
impl fidl::endpoints::Proxy for SourceProxy {
type Protocol = SourceMarker;
fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
Self::new(inner)
}
fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
self.client.into_channel().map_err(|client| Self { client })
}
fn as_channel(&self) -> &::fidl::AsyncChannel {
self.client.as_channel()
}
}
impl SourceProxy {
pub fn new(channel: ::fidl::AsyncChannel) -> Self {
let protocol_name = <SourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
Self { client: fidl::client::Client::new(channel, protocol_name) }
}
pub fn take_event_stream(&self) -> SourceEventStream {
SourceEventStream { event_receiver: self.client.take_event_receiver() }
}
pub fn r#get_power_info(
&self,
) -> fidl::client::QueryResponseFut<
(i32, SourceInfo),
fidl::encoding::DefaultFuchsiaResourceDialect,
> {
SourceProxyInterface::r#get_power_info(self)
}
pub fn r#get_state_change_event(
&self,
) -> fidl::client::QueryResponseFut<
(i32, fidl::Event),
fidl::encoding::DefaultFuchsiaResourceDialect,
> {
SourceProxyInterface::r#get_state_change_event(self)
}
pub fn r#get_battery_info(
&self,
) -> fidl::client::QueryResponseFut<
(i32, BatteryInfo),
fidl::encoding::DefaultFuchsiaResourceDialect,
> {
SourceProxyInterface::r#get_battery_info(self)
}
}
impl SourceProxyInterface for SourceProxy {
type GetPowerInfoResponseFut = fidl::client::QueryResponseFut<
(i32, SourceInfo),
fidl::encoding::DefaultFuchsiaResourceDialect,
>;
fn r#get_power_info(&self) -> Self::GetPowerInfoResponseFut {
fn _decode(
mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
) -> Result<(i32, SourceInfo), fidl::Error> {
let _response = fidl::client::decode_transaction_body::<
SourceGetPowerInfoResponse,
fidl::encoding::DefaultFuchsiaResourceDialect,
0x2dd7eb1cce18665d,
>(_buf?)?;
Ok((_response.status, _response.info))
}
self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, (i32, SourceInfo)>(
(),
0x2dd7eb1cce18665d,
fidl::encoding::DynamicFlags::empty(),
_decode,
)
}
type GetStateChangeEventResponseFut = fidl::client::QueryResponseFut<
(i32, fidl::Event),
fidl::encoding::DefaultFuchsiaResourceDialect,
>;
fn r#get_state_change_event(&self) -> Self::GetStateChangeEventResponseFut {
fn _decode(
mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
) -> Result<(i32, fidl::Event), fidl::Error> {
let _response = fidl::client::decode_transaction_body::<
SourceGetStateChangeEventResponse,
fidl::encoding::DefaultFuchsiaResourceDialect,
0x67842daecf5e7f5e,
>(_buf?)?;
Ok((_response.status, _response.handle))
}
self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, (i32, fidl::Event)>(
(),
0x67842daecf5e7f5e,
fidl::encoding::DynamicFlags::empty(),
_decode,
)
}
type GetBatteryInfoResponseFut = fidl::client::QueryResponseFut<
(i32, BatteryInfo),
fidl::encoding::DefaultFuchsiaResourceDialect,
>;
fn r#get_battery_info(&self) -> Self::GetBatteryInfoResponseFut {
fn _decode(
mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
) -> Result<(i32, BatteryInfo), fidl::Error> {
let _response = fidl::client::decode_transaction_body::<
SourceGetBatteryInfoResponse,
fidl::encoding::DefaultFuchsiaResourceDialect,
0x686f3c82ad2b91cd,
>(_buf?)?;
Ok((_response.status, _response.info))
}
self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, (i32, BatteryInfo)>(
(),
0x686f3c82ad2b91cd,
fidl::encoding::DynamicFlags::empty(),
_decode,
)
}
}
pub struct SourceEventStream {
event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
}
impl std::marker::Unpin for SourceEventStream {}
impl futures::stream::FusedStream for SourceEventStream {
fn is_terminated(&self) -> bool {
self.event_receiver.is_terminated()
}
}
impl futures::Stream for SourceEventStream {
type Item = Result<SourceEvent, fidl::Error>;
fn poll_next(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Self::Item>> {
match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
&mut self.event_receiver,
cx
)?) {
Some(buf) => std::task::Poll::Ready(Some(SourceEvent::decode(buf))),
None => std::task::Poll::Ready(None),
}
}
}
#[derive(Debug)]
pub enum SourceEvent {}
impl SourceEvent {
fn decode(
mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
) -> Result<SourceEvent, fidl::Error> {
let (bytes, _handles) = buf.split_mut();
let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
debug_assert_eq!(tx_header.tx_id, 0);
match tx_header.ordinal {
_ => Err(fidl::Error::UnknownOrdinal {
ordinal: tx_header.ordinal,
protocol_name: <SourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
}),
}
}
}
pub struct SourceRequestStream {
inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
is_terminated: bool,
}
impl std::marker::Unpin for SourceRequestStream {}
impl futures::stream::FusedStream for SourceRequestStream {
fn is_terminated(&self) -> bool {
self.is_terminated
}
}
impl fidl::endpoints::RequestStream for SourceRequestStream {
type Protocol = SourceMarker;
type ControlHandle = SourceControlHandle;
fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
}
fn control_handle(&self) -> Self::ControlHandle {
SourceControlHandle { inner: self.inner.clone() }
}
fn into_inner(
self,
) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
{
(self.inner, self.is_terminated)
}
fn from_inner(
inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
is_terminated: bool,
) -> Self {
Self { inner, is_terminated }
}
}
impl futures::Stream for SourceRequestStream {
type Item = Result<SourceRequest, fidl::Error>;
fn poll_next(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Self::Item>> {
let this = &mut *self;
if this.inner.check_shutdown(cx) {
this.is_terminated = true;
return std::task::Poll::Ready(None);
}
if this.is_terminated {
panic!("polled SourceRequestStream after completion");
}
fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
|bytes, handles| {
match this.inner.channel().read_etc(cx, bytes, handles) {
std::task::Poll::Ready(Ok(())) => {}
std::task::Poll::Pending => return std::task::Poll::Pending,
std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
this.is_terminated = true;
return std::task::Poll::Ready(None);
}
std::task::Poll::Ready(Err(e)) => {
return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
e.into(),
))))
}
}
let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
std::task::Poll::Ready(Some(match header.ordinal {
0x2dd7eb1cce18665d => {
header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
let mut req = fidl::new_empty!(
fidl::encoding::EmptyPayload,
fidl::encoding::DefaultFuchsiaResourceDialect
);
fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
let control_handle = SourceControlHandle { inner: this.inner.clone() };
Ok(SourceRequest::GetPowerInfo {
responder: SourceGetPowerInfoResponder {
control_handle: std::mem::ManuallyDrop::new(control_handle),
tx_id: header.tx_id,
},
})
}
0x67842daecf5e7f5e => {
header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
let mut req = fidl::new_empty!(
fidl::encoding::EmptyPayload,
fidl::encoding::DefaultFuchsiaResourceDialect
);
fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
let control_handle = SourceControlHandle { inner: this.inner.clone() };
Ok(SourceRequest::GetStateChangeEvent {
responder: SourceGetStateChangeEventResponder {
control_handle: std::mem::ManuallyDrop::new(control_handle),
tx_id: header.tx_id,
},
})
}
0x686f3c82ad2b91cd => {
header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
let mut req = fidl::new_empty!(
fidl::encoding::EmptyPayload,
fidl::encoding::DefaultFuchsiaResourceDialect
);
fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
let control_handle = SourceControlHandle { inner: this.inner.clone() };
Ok(SourceRequest::GetBatteryInfo {
responder: SourceGetBatteryInfoResponder {
control_handle: std::mem::ManuallyDrop::new(control_handle),
tx_id: header.tx_id,
},
})
}
_ => Err(fidl::Error::UnknownOrdinal {
ordinal: header.ordinal,
protocol_name:
<SourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
}),
}))
},
)
}
}
#[derive(Debug)]
pub enum SourceRequest {
GetPowerInfo { responder: SourceGetPowerInfoResponder },
GetStateChangeEvent { responder: SourceGetStateChangeEventResponder },
GetBatteryInfo { responder: SourceGetBatteryInfoResponder },
}
impl SourceRequest {
#[allow(irrefutable_let_patterns)]
pub fn into_get_power_info(self) -> Option<(SourceGetPowerInfoResponder)> {
if let SourceRequest::GetPowerInfo { responder } = self {
Some((responder))
} else {
None
}
}
#[allow(irrefutable_let_patterns)]
pub fn into_get_state_change_event(self) -> Option<(SourceGetStateChangeEventResponder)> {
if let SourceRequest::GetStateChangeEvent { responder } = self {
Some((responder))
} else {
None
}
}
#[allow(irrefutable_let_patterns)]
pub fn into_get_battery_info(self) -> Option<(SourceGetBatteryInfoResponder)> {
if let SourceRequest::GetBatteryInfo { responder } = self {
Some((responder))
} else {
None
}
}
pub fn method_name(&self) -> &'static str {
match *self {
SourceRequest::GetPowerInfo { .. } => "get_power_info",
SourceRequest::GetStateChangeEvent { .. } => "get_state_change_event",
SourceRequest::GetBatteryInfo { .. } => "get_battery_info",
}
}
}
#[derive(Debug, Clone)]
pub struct SourceControlHandle {
inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
}
impl fidl::endpoints::ControlHandle for SourceControlHandle {
fn shutdown(&self) {
self.inner.shutdown()
}
fn shutdown_with_epitaph(&self, status: zx_status::Status) {
self.inner.shutdown_with_epitaph(status)
}
fn is_closed(&self) -> bool {
self.inner.channel().is_closed()
}
fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
self.inner.channel().on_closed()
}
#[cfg(target_os = "fuchsia")]
fn signal_peer(
&self,
clear_mask: zx::Signals,
set_mask: zx::Signals,
) -> Result<(), zx_status::Status> {
use fidl::Peered;
self.inner.channel().signal_peer(clear_mask, set_mask)
}
}
impl SourceControlHandle {}
#[must_use = "FIDL methods require a response to be sent"]
#[derive(Debug)]
pub struct SourceGetPowerInfoResponder {
control_handle: std::mem::ManuallyDrop<SourceControlHandle>,
tx_id: u32,
}
impl std::ops::Drop for SourceGetPowerInfoResponder {
fn drop(&mut self) {
self.control_handle.shutdown();
unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
}
}
impl fidl::endpoints::Responder for SourceGetPowerInfoResponder {
type ControlHandle = SourceControlHandle;
fn control_handle(&self) -> &SourceControlHandle {
&self.control_handle
}
fn drop_without_shutdown(mut self) {
unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
std::mem::forget(self);
}
}
impl SourceGetPowerInfoResponder {
pub fn send(self, mut status: i32, mut info: &SourceInfo) -> Result<(), fidl::Error> {
let _result = self.send_raw(status, info);
if _result.is_err() {
self.control_handle.shutdown();
}
self.drop_without_shutdown();
_result
}
pub fn send_no_shutdown_on_err(
self,
mut status: i32,
mut info: &SourceInfo,
) -> Result<(), fidl::Error> {
let _result = self.send_raw(status, info);
self.drop_without_shutdown();
_result
}
fn send_raw(&self, mut status: i32, mut info: &SourceInfo) -> Result<(), fidl::Error> {
self.control_handle.inner.send::<SourceGetPowerInfoResponse>(
(status, info),
self.tx_id,
0x2dd7eb1cce18665d,
fidl::encoding::DynamicFlags::empty(),
)
}
}
#[must_use = "FIDL methods require a response to be sent"]
#[derive(Debug)]
pub struct SourceGetStateChangeEventResponder {
control_handle: std::mem::ManuallyDrop<SourceControlHandle>,
tx_id: u32,
}
impl std::ops::Drop for SourceGetStateChangeEventResponder {
fn drop(&mut self) {
self.control_handle.shutdown();
unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
}
}
impl fidl::endpoints::Responder for SourceGetStateChangeEventResponder {
type ControlHandle = SourceControlHandle;
fn control_handle(&self) -> &SourceControlHandle {
&self.control_handle
}
fn drop_without_shutdown(mut self) {
unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
std::mem::forget(self);
}
}
impl SourceGetStateChangeEventResponder {
pub fn send(self, mut status: i32, mut handle: fidl::Event) -> Result<(), fidl::Error> {
let _result = self.send_raw(status, handle);
if _result.is_err() {
self.control_handle.shutdown();
}
self.drop_without_shutdown();
_result
}
pub fn send_no_shutdown_on_err(
self,
mut status: i32,
mut handle: fidl::Event,
) -> Result<(), fidl::Error> {
let _result = self.send_raw(status, handle);
self.drop_without_shutdown();
_result
}
fn send_raw(&self, mut status: i32, mut handle: fidl::Event) -> Result<(), fidl::Error> {
self.control_handle.inner.send::<SourceGetStateChangeEventResponse>(
(status, handle),
self.tx_id,
0x67842daecf5e7f5e,
fidl::encoding::DynamicFlags::empty(),
)
}
}
#[must_use = "FIDL methods require a response to be sent"]
#[derive(Debug)]
pub struct SourceGetBatteryInfoResponder {
control_handle: std::mem::ManuallyDrop<SourceControlHandle>,
tx_id: u32,
}
impl std::ops::Drop for SourceGetBatteryInfoResponder {
fn drop(&mut self) {
self.control_handle.shutdown();
unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
}
}
impl fidl::endpoints::Responder for SourceGetBatteryInfoResponder {
type ControlHandle = SourceControlHandle;
fn control_handle(&self) -> &SourceControlHandle {
&self.control_handle
}
fn drop_without_shutdown(mut self) {
unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
std::mem::forget(self);
}
}
impl SourceGetBatteryInfoResponder {
pub fn send(self, mut status: i32, mut info: &BatteryInfo) -> Result<(), fidl::Error> {
let _result = self.send_raw(status, info);
if _result.is_err() {
self.control_handle.shutdown();
}
self.drop_without_shutdown();
_result
}
pub fn send_no_shutdown_on_err(
self,
mut status: i32,
mut info: &BatteryInfo,
) -> Result<(), fidl::Error> {
let _result = self.send_raw(status, info);
self.drop_without_shutdown();
_result
}
fn send_raw(&self, mut status: i32, mut info: &BatteryInfo) -> Result<(), fidl::Error> {
self.control_handle.inner.send::<SourceGetBatteryInfoResponse>(
(status, info),
self.tx_id,
0x686f3c82ad2b91cd,
fidl::encoding::DynamicFlags::empty(),
)
}
}
mod internal {
use super::*;
unsafe impl fidl::encoding::TypeMarker for BatteryUnit {
type Owned = Self;
#[inline(always)]
fn inline_align(_context: fidl::encoding::Context) -> usize {
std::mem::align_of::<u32>()
}
#[inline(always)]
fn inline_size(_context: fidl::encoding::Context) -> usize {
std::mem::size_of::<u32>()
}
#[inline(always)]
fn encode_is_copy() -> bool {
true
}
#[inline(always)]
fn decode_is_copy() -> bool {
false
}
}
impl fidl::encoding::ValueTypeMarker for BatteryUnit {
type Borrowed<'a> = Self;
#[inline(always)]
fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
*value
}
}
unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for BatteryUnit {
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<Self>(offset);
encoder.write_num(self.into_primitive(), offset);
Ok(())
}
}
impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BatteryUnit {
#[inline(always)]
fn new_empty() -> Self {
Self::Mw
}
#[inline]
unsafe fn decode(
&mut self,
decoder: &mut fidl::encoding::Decoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
decoder.debug_check_bounds::<Self>(offset);
let prim = decoder.read_num::<u32>(offset);
*self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
Ok(())
}
}
unsafe impl fidl::encoding::TypeMarker for PowerType {
type Owned = Self;
#[inline(always)]
fn inline_align(_context: fidl::encoding::Context) -> usize {
std::mem::align_of::<u8>()
}
#[inline(always)]
fn inline_size(_context: fidl::encoding::Context) -> usize {
std::mem::size_of::<u8>()
}
#[inline(always)]
fn encode_is_copy() -> bool {
true
}
#[inline(always)]
fn decode_is_copy() -> bool {
false
}
}
impl fidl::encoding::ValueTypeMarker for PowerType {
type Borrowed<'a> = Self;
#[inline(always)]
fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
*value
}
}
unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for PowerType {
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<Self>(offset);
encoder.write_num(self.into_primitive(), offset);
Ok(())
}
}
impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PowerType {
#[inline(always)]
fn new_empty() -> Self {
Self::Ac
}
#[inline]
unsafe fn decode(
&mut self,
decoder: &mut fidl::encoding::Decoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
decoder.debug_check_bounds::<Self>(offset);
let prim = decoder.read_num::<u8>(offset);
*self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
Ok(())
}
}
impl fidl::encoding::ValueTypeMarker for BatteryInfo {
type Borrowed<'a> = &'a Self;
fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
value
}
}
unsafe impl fidl::encoding::TypeMarker for BatteryInfo {
type Owned = Self;
#[inline(always)]
fn inline_align(_context: fidl::encoding::Context) -> usize {
8
}
#[inline(always)]
fn inline_size(_context: fidl::encoding::Context) -> usize {
64
}
}
unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<BatteryInfo, D>
for &BatteryInfo
{
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<BatteryInfo>(offset);
fidl::encoding::Encode::<BatteryInfo, D>::encode(
(
<BatteryUnit as fidl::encoding::ValueTypeMarker>::borrow(&self.unit),
<u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.design_capacity),
<u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.last_full_capacity),
<u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.design_voltage),
<u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.capacity_warning),
<u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.capacity_low),
<u32 as fidl::encoding::ValueTypeMarker>::borrow(
&self.capacity_granularity_low_warning,
),
<u32 as fidl::encoding::ValueTypeMarker>::borrow(
&self.capacity_granularity_warning_full,
),
<i32 as fidl::encoding::ValueTypeMarker>::borrow(&self.present_rate),
<u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.remaining_capacity),
<u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.present_voltage),
<BatterySpec as fidl::encoding::ValueTypeMarker>::borrow(&self.battery_spec),
),
encoder,
offset,
_depth,
)
}
}
unsafe impl<
D: fidl::encoding::ResourceDialect,
T0: fidl::encoding::Encode<BatteryUnit, D>,
T1: fidl::encoding::Encode<u32, D>,
T2: fidl::encoding::Encode<u32, D>,
T3: fidl::encoding::Encode<u32, D>,
T4: fidl::encoding::Encode<u32, D>,
T5: fidl::encoding::Encode<u32, D>,
T6: fidl::encoding::Encode<u32, D>,
T7: fidl::encoding::Encode<u32, D>,
T8: fidl::encoding::Encode<i32, D>,
T9: fidl::encoding::Encode<u32, D>,
T10: fidl::encoding::Encode<u32, D>,
T11: fidl::encoding::Encode<BatterySpec, D>,
> fidl::encoding::Encode<BatteryInfo, D>
for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
{
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<'_, D>,
offset: usize,
depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<BatteryInfo>(offset);
unsafe {
let ptr = encoder.buf.as_mut_ptr().add(offset).offset(40);
(ptr as *mut u64).write_unaligned(0);
}
self.0.encode(encoder, offset + 0, depth)?;
self.1.encode(encoder, offset + 4, depth)?;
self.2.encode(encoder, offset + 8, depth)?;
self.3.encode(encoder, offset + 12, depth)?;
self.4.encode(encoder, offset + 16, depth)?;
self.5.encode(encoder, offset + 20, depth)?;
self.6.encode(encoder, offset + 24, depth)?;
self.7.encode(encoder, offset + 28, depth)?;
self.8.encode(encoder, offset + 32, depth)?;
self.9.encode(encoder, offset + 36, depth)?;
self.10.encode(encoder, offset + 40, depth)?;
self.11.encode(encoder, offset + 48, depth)?;
Ok(())
}
}
impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BatteryInfo {
#[inline(always)]
fn new_empty() -> Self {
Self {
unit: fidl::new_empty!(BatteryUnit, D),
design_capacity: fidl::new_empty!(u32, D),
last_full_capacity: fidl::new_empty!(u32, D),
design_voltage: fidl::new_empty!(u32, D),
capacity_warning: fidl::new_empty!(u32, D),
capacity_low: fidl::new_empty!(u32, D),
capacity_granularity_low_warning: fidl::new_empty!(u32, D),
capacity_granularity_warning_full: fidl::new_empty!(u32, D),
present_rate: fidl::new_empty!(i32, D),
remaining_capacity: fidl::new_empty!(u32, D),
present_voltage: fidl::new_empty!(u32, D),
battery_spec: fidl::new_empty!(BatterySpec, D),
}
}
#[inline]
unsafe fn decode(
&mut self,
decoder: &mut fidl::encoding::Decoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
decoder.debug_check_bounds::<Self>(offset);
let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(40) };
let padval = unsafe { (ptr as *const u64).read_unaligned() };
let mask = 0xffffffff00000000u64;
let maskedval = padval & mask;
if maskedval != 0 {
return Err(fidl::Error::NonZeroPadding {
padding_start: offset + 40 + ((mask as u64).trailing_zeros() / 8) as usize,
});
}
fidl::decode!(BatteryUnit, D, &mut self.unit, decoder, offset + 0, _depth)?;
fidl::decode!(u32, D, &mut self.design_capacity, decoder, offset + 4, _depth)?;
fidl::decode!(u32, D, &mut self.last_full_capacity, decoder, offset + 8, _depth)?;
fidl::decode!(u32, D, &mut self.design_voltage, decoder, offset + 12, _depth)?;
fidl::decode!(u32, D, &mut self.capacity_warning, decoder, offset + 16, _depth)?;
fidl::decode!(u32, D, &mut self.capacity_low, decoder, offset + 20, _depth)?;
fidl::decode!(
u32,
D,
&mut self.capacity_granularity_low_warning,
decoder,
offset + 24,
_depth
)?;
fidl::decode!(
u32,
D,
&mut self.capacity_granularity_warning_full,
decoder,
offset + 28,
_depth
)?;
fidl::decode!(i32, D, &mut self.present_rate, decoder, offset + 32, _depth)?;
fidl::decode!(u32, D, &mut self.remaining_capacity, decoder, offset + 36, _depth)?;
fidl::decode!(u32, D, &mut self.present_voltage, decoder, offset + 40, _depth)?;
fidl::decode!(BatterySpec, D, &mut self.battery_spec, decoder, offset + 48, _depth)?;
Ok(())
}
}
impl fidl::encoding::ValueTypeMarker for SourceGetBatteryInfoResponse {
type Borrowed<'a> = &'a Self;
fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
value
}
}
unsafe impl fidl::encoding::TypeMarker for SourceGetBatteryInfoResponse {
type Owned = Self;
#[inline(always)]
fn inline_align(_context: fidl::encoding::Context) -> usize {
8
}
#[inline(always)]
fn inline_size(_context: fidl::encoding::Context) -> usize {
72
}
}
unsafe impl<D: fidl::encoding::ResourceDialect>
fidl::encoding::Encode<SourceGetBatteryInfoResponse, D> for &SourceGetBatteryInfoResponse
{
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<SourceGetBatteryInfoResponse>(offset);
fidl::encoding::Encode::<SourceGetBatteryInfoResponse, D>::encode(
(
<i32 as fidl::encoding::ValueTypeMarker>::borrow(&self.status),
<BatteryInfo as fidl::encoding::ValueTypeMarker>::borrow(&self.info),
),
encoder,
offset,
_depth,
)
}
}
unsafe impl<
D: fidl::encoding::ResourceDialect,
T0: fidl::encoding::Encode<i32, D>,
T1: fidl::encoding::Encode<BatteryInfo, D>,
> fidl::encoding::Encode<SourceGetBatteryInfoResponse, D> for (T0, T1)
{
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<'_, D>,
offset: usize,
depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<SourceGetBatteryInfoResponse>(offset);
unsafe {
let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
(ptr as *mut u64).write_unaligned(0);
}
self.0.encode(encoder, offset + 0, depth)?;
self.1.encode(encoder, offset + 8, depth)?;
Ok(())
}
}
impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
for SourceGetBatteryInfoResponse
{
#[inline(always)]
fn new_empty() -> Self {
Self { status: fidl::new_empty!(i32, D), info: fidl::new_empty!(BatteryInfo, D) }
}
#[inline]
unsafe fn decode(
&mut self,
decoder: &mut fidl::encoding::Decoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
decoder.debug_check_bounds::<Self>(offset);
let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
let padval = unsafe { (ptr as *const u64).read_unaligned() };
let mask = 0xffffffff00000000u64;
let maskedval = padval & mask;
if maskedval != 0 {
return Err(fidl::Error::NonZeroPadding {
padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
});
}
fidl::decode!(i32, D, &mut self.status, decoder, offset + 0, _depth)?;
fidl::decode!(BatteryInfo, D, &mut self.info, decoder, offset + 8, _depth)?;
Ok(())
}
}
impl fidl::encoding::ValueTypeMarker for SourceGetPowerInfoResponse {
type Borrowed<'a> = &'a Self;
fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
value
}
}
unsafe impl fidl::encoding::TypeMarker for SourceGetPowerInfoResponse {
type Owned = Self;
#[inline(always)]
fn inline_align(_context: fidl::encoding::Context) -> usize {
4
}
#[inline(always)]
fn inline_size(_context: fidl::encoding::Context) -> usize {
8
}
}
unsafe impl<D: fidl::encoding::ResourceDialect>
fidl::encoding::Encode<SourceGetPowerInfoResponse, D> for &SourceGetPowerInfoResponse
{
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<SourceGetPowerInfoResponse>(offset);
fidl::encoding::Encode::<SourceGetPowerInfoResponse, D>::encode(
(
<i32 as fidl::encoding::ValueTypeMarker>::borrow(&self.status),
<SourceInfo as fidl::encoding::ValueTypeMarker>::borrow(&self.info),
),
encoder,
offset,
_depth,
)
}
}
unsafe impl<
D: fidl::encoding::ResourceDialect,
T0: fidl::encoding::Encode<i32, D>,
T1: fidl::encoding::Encode<SourceInfo, D>,
> fidl::encoding::Encode<SourceGetPowerInfoResponse, D> for (T0, T1)
{
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<'_, D>,
offset: usize,
depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<SourceGetPowerInfoResponse>(offset);
unsafe {
let ptr = encoder.buf.as_mut_ptr().add(offset).offset(4);
(ptr as *mut u32).write_unaligned(0);
}
self.0.encode(encoder, offset + 0, depth)?;
self.1.encode(encoder, offset + 4, depth)?;
Ok(())
}
}
impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
for SourceGetPowerInfoResponse
{
#[inline(always)]
fn new_empty() -> Self {
Self { status: fidl::new_empty!(i32, D), info: fidl::new_empty!(SourceInfo, D) }
}
#[inline]
unsafe fn decode(
&mut self,
decoder: &mut fidl::encoding::Decoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
decoder.debug_check_bounds::<Self>(offset);
let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(4) };
let padval = unsafe { (ptr as *const u32).read_unaligned() };
let mask = 0xffff0000u32;
let maskedval = padval & mask;
if maskedval != 0 {
return Err(fidl::Error::NonZeroPadding {
padding_start: offset + 4 + ((mask as u64).trailing_zeros() / 8) as usize,
});
}
fidl::decode!(i32, D, &mut self.status, decoder, offset + 0, _depth)?;
fidl::decode!(SourceInfo, D, &mut self.info, decoder, offset + 4, _depth)?;
Ok(())
}
}
impl fidl::encoding::ResourceTypeMarker for SourceGetStateChangeEventResponse {
type Borrowed<'a> = &'a mut Self;
fn take_or_borrow<'a>(
value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
) -> Self::Borrowed<'a> {
value
}
}
unsafe impl fidl::encoding::TypeMarker for SourceGetStateChangeEventResponse {
type Owned = Self;
#[inline(always)]
fn inline_align(_context: fidl::encoding::Context) -> usize {
4
}
#[inline(always)]
fn inline_size(_context: fidl::encoding::Context) -> usize {
8
}
}
unsafe impl
fidl::encoding::Encode<
SourceGetStateChangeEventResponse,
fidl::encoding::DefaultFuchsiaResourceDialect,
> for &mut SourceGetStateChangeEventResponse
{
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<
'_,
fidl::encoding::DefaultFuchsiaResourceDialect,
>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<SourceGetStateChangeEventResponse>(offset);
fidl::encoding::Encode::<
SourceGetStateChangeEventResponse,
fidl::encoding::DefaultFuchsiaResourceDialect,
>::encode(
(
<i32 as fidl::encoding::ValueTypeMarker>::borrow(&self.status),
<fidl::encoding::HandleType<
fidl::Event,
{ fidl::ObjectType::EVENT.into_raw() },
16384,
> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
&mut self.handle
),
),
encoder,
offset,
_depth,
)
}
}
unsafe impl<
T0: fidl::encoding::Encode<i32, fidl::encoding::DefaultFuchsiaResourceDialect>,
T1: fidl::encoding::Encode<
fidl::encoding::HandleType<
fidl::Event,
{ fidl::ObjectType::EVENT.into_raw() },
16384,
>,
fidl::encoding::DefaultFuchsiaResourceDialect,
>,
>
fidl::encoding::Encode<
SourceGetStateChangeEventResponse,
fidl::encoding::DefaultFuchsiaResourceDialect,
> for (T0, T1)
{
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<
'_,
fidl::encoding::DefaultFuchsiaResourceDialect,
>,
offset: usize,
depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<SourceGetStateChangeEventResponse>(offset);
self.0.encode(encoder, offset + 0, depth)?;
self.1.encode(encoder, offset + 4, depth)?;
Ok(())
}
}
impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
for SourceGetStateChangeEventResponse
{
#[inline(always)]
fn new_empty() -> Self {
Self {
status: fidl::new_empty!(i32, fidl::encoding::DefaultFuchsiaResourceDialect),
handle: fidl::new_empty!(fidl::encoding::HandleType<fidl::Event, { fidl::ObjectType::EVENT.into_raw() }, 16384>, fidl::encoding::DefaultFuchsiaResourceDialect),
}
}
#[inline]
unsafe fn decode(
&mut self,
decoder: &mut fidl::encoding::Decoder<
'_,
fidl::encoding::DefaultFuchsiaResourceDialect,
>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
decoder.debug_check_bounds::<Self>(offset);
fidl::decode!(
i32,
fidl::encoding::DefaultFuchsiaResourceDialect,
&mut self.status,
decoder,
offset + 0,
_depth
)?;
fidl::decode!(fidl::encoding::HandleType<fidl::Event, { fidl::ObjectType::EVENT.into_raw() }, 16384>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.handle, decoder, offset + 4, _depth)?;
Ok(())
}
}
impl fidl::encoding::ValueTypeMarker for SourceInfo {
type Borrowed<'a> = &'a Self;
fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
value
}
}
unsafe impl fidl::encoding::TypeMarker for SourceInfo {
type Owned = Self;
#[inline(always)]
fn inline_align(_context: fidl::encoding::Context) -> usize {
1
}
#[inline(always)]
fn inline_size(_context: fidl::encoding::Context) -> usize {
2
}
}
unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<SourceInfo, D>
for &SourceInfo
{
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<SourceInfo>(offset);
fidl::encoding::Encode::<SourceInfo, D>::encode(
(
<PowerType as fidl::encoding::ValueTypeMarker>::borrow(&self.type_),
<u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.state),
),
encoder,
offset,
_depth,
)
}
}
unsafe impl<
D: fidl::encoding::ResourceDialect,
T0: fidl::encoding::Encode<PowerType, D>,
T1: fidl::encoding::Encode<u8, D>,
> fidl::encoding::Encode<SourceInfo, D> for (T0, T1)
{
#[inline]
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<'_, D>,
offset: usize,
depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<SourceInfo>(offset);
self.0.encode(encoder, offset + 0, depth)?;
self.1.encode(encoder, offset + 1, depth)?;
Ok(())
}
}
impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SourceInfo {
#[inline(always)]
fn new_empty() -> Self {
Self { type_: fidl::new_empty!(PowerType, D), state: fidl::new_empty!(u8, D) }
}
#[inline]
unsafe fn decode(
&mut self,
decoder: &mut fidl::encoding::Decoder<'_, D>,
offset: usize,
_depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
decoder.debug_check_bounds::<Self>(offset);
fidl::decode!(PowerType, D, &mut self.type_, decoder, offset + 0, _depth)?;
fidl::decode!(u8, D, &mut self.state, decoder, offset + 1, _depth)?;
Ok(())
}
}
impl BatterySpec {
#[inline(always)]
fn max_ordinal_present(&self) -> u64 {
if let Some(_) = self.design_capacity_uah {
return 3;
}
if let Some(_) = self.max_charnging_voltage_uv {
return 2;
}
if let Some(_) = self.max_charging_current_ua {
return 1;
}
0
}
}
impl fidl::encoding::ValueTypeMarker for BatterySpec {
type Borrowed<'a> = &'a Self;
fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
value
}
}
unsafe impl fidl::encoding::TypeMarker for BatterySpec {
type Owned = Self;
#[inline(always)]
fn inline_align(_context: fidl::encoding::Context) -> usize {
8
}
#[inline(always)]
fn inline_size(_context: fidl::encoding::Context) -> usize {
16
}
}
unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<BatterySpec, D>
for &BatterySpec
{
unsafe fn encode(
self,
encoder: &mut fidl::encoding::Encoder<'_, D>,
offset: usize,
mut depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
encoder.debug_check_bounds::<BatterySpec>(offset);
let max_ordinal: u64 = self.max_ordinal_present();
encoder.write_num(max_ordinal, offset);
encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
if max_ordinal == 0 {
return Ok(());
}
depth.increment()?;
let envelope_size = 8;
let bytes_len = max_ordinal as usize * envelope_size;
#[allow(unused_variables)]
let offset = encoder.out_of_line_offset(bytes_len);
let mut _prev_end_offset: usize = 0;
if 1 > max_ordinal {
return Ok(());
}
let cur_offset: usize = (1 - 1) * envelope_size;
encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
fidl::encoding::encode_in_envelope_optional::<i32, D>(
self.max_charging_current_ua
.as_ref()
.map(<i32 as fidl::encoding::ValueTypeMarker>::borrow),
encoder,
offset + cur_offset,
depth,
)?;
_prev_end_offset = cur_offset + envelope_size;
if 2 > max_ordinal {
return Ok(());
}
let cur_offset: usize = (2 - 1) * envelope_size;
encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
fidl::encoding::encode_in_envelope_optional::<i32, D>(
self.max_charnging_voltage_uv
.as_ref()
.map(<i32 as fidl::encoding::ValueTypeMarker>::borrow),
encoder,
offset + cur_offset,
depth,
)?;
_prev_end_offset = cur_offset + envelope_size;
if 3 > max_ordinal {
return Ok(());
}
let cur_offset: usize = (3 - 1) * envelope_size;
encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
fidl::encoding::encode_in_envelope_optional::<i32, D>(
self.design_capacity_uah
.as_ref()
.map(<i32 as fidl::encoding::ValueTypeMarker>::borrow),
encoder,
offset + cur_offset,
depth,
)?;
_prev_end_offset = cur_offset + envelope_size;
Ok(())
}
}
impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BatterySpec {
#[inline(always)]
fn new_empty() -> Self {
Self::default()
}
unsafe fn decode(
&mut self,
decoder: &mut fidl::encoding::Decoder<'_, D>,
offset: usize,
mut depth: fidl::encoding::Depth,
) -> fidl::Result<()> {
decoder.debug_check_bounds::<Self>(offset);
let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
None => return Err(fidl::Error::NotNullable),
Some(len) => len,
};
if len == 0 {
return Ok(());
};
depth.increment()?;
let envelope_size = 8;
let bytes_len = len * envelope_size;
let offset = decoder.out_of_line_offset(bytes_len)?;
let mut _next_ordinal_to_read = 0;
let mut next_offset = offset;
let end_offset = offset + bytes_len;
_next_ordinal_to_read += 1;
if next_offset >= end_offset {
return Ok(());
}
while _next_ordinal_to_read < 1 {
fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
_next_ordinal_to_read += 1;
next_offset += envelope_size;
}
let next_out_of_line = decoder.next_out_of_line();
let handles_before = decoder.remaining_handles();
if let Some((inlined, num_bytes, num_handles)) =
fidl::encoding::decode_envelope_header(decoder, next_offset)?
{
let member_inline_size =
<i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
if inlined != (member_inline_size <= 4) {
return Err(fidl::Error::InvalidInlineBitInEnvelope);
}
let inner_offset;
let mut inner_depth = depth.clone();
if inlined {
decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
inner_offset = next_offset;
} else {
inner_offset = decoder.out_of_line_offset(member_inline_size)?;
inner_depth.increment()?;
}
let val_ref =
self.max_charging_current_ua.get_or_insert_with(|| fidl::new_empty!(i32, D));
fidl::decode!(i32, D, val_ref, decoder, inner_offset, inner_depth)?;
if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
{
return Err(fidl::Error::InvalidNumBytesInEnvelope);
}
if handles_before != decoder.remaining_handles() + (num_handles as usize) {
return Err(fidl::Error::InvalidNumHandlesInEnvelope);
}
}
next_offset += envelope_size;
_next_ordinal_to_read += 1;
if next_offset >= end_offset {
return Ok(());
}
while _next_ordinal_to_read < 2 {
fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
_next_ordinal_to_read += 1;
next_offset += envelope_size;
}
let next_out_of_line = decoder.next_out_of_line();
let handles_before = decoder.remaining_handles();
if let Some((inlined, num_bytes, num_handles)) =
fidl::encoding::decode_envelope_header(decoder, next_offset)?
{
let member_inline_size =
<i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
if inlined != (member_inline_size <= 4) {
return Err(fidl::Error::InvalidInlineBitInEnvelope);
}
let inner_offset;
let mut inner_depth = depth.clone();
if inlined {
decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
inner_offset = next_offset;
} else {
inner_offset = decoder.out_of_line_offset(member_inline_size)?;
inner_depth.increment()?;
}
let val_ref =
self.max_charnging_voltage_uv.get_or_insert_with(|| fidl::new_empty!(i32, D));
fidl::decode!(i32, D, val_ref, decoder, inner_offset, inner_depth)?;
if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
{
return Err(fidl::Error::InvalidNumBytesInEnvelope);
}
if handles_before != decoder.remaining_handles() + (num_handles as usize) {
return Err(fidl::Error::InvalidNumHandlesInEnvelope);
}
}
next_offset += envelope_size;
_next_ordinal_to_read += 1;
if next_offset >= end_offset {
return Ok(());
}
while _next_ordinal_to_read < 3 {
fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
_next_ordinal_to_read += 1;
next_offset += envelope_size;
}
let next_out_of_line = decoder.next_out_of_line();
let handles_before = decoder.remaining_handles();
if let Some((inlined, num_bytes, num_handles)) =
fidl::encoding::decode_envelope_header(decoder, next_offset)?
{
let member_inline_size =
<i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
if inlined != (member_inline_size <= 4) {
return Err(fidl::Error::InvalidInlineBitInEnvelope);
}
let inner_offset;
let mut inner_depth = depth.clone();
if inlined {
decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
inner_offset = next_offset;
} else {
inner_offset = decoder.out_of_line_offset(member_inline_size)?;
inner_depth.increment()?;
}
let val_ref =
self.design_capacity_uah.get_or_insert_with(|| fidl::new_empty!(i32, D));
fidl::decode!(i32, D, val_ref, decoder, inner_offset, inner_depth)?;
if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
{
return Err(fidl::Error::InvalidNumBytesInEnvelope);
}
if handles_before != decoder.remaining_handles() + (num_handles as usize) {
return Err(fidl::Error::InvalidNumHandlesInEnvelope);
}
}
next_offset += envelope_size;
while next_offset < end_offset {
_next_ordinal_to_read += 1;
fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
next_offset += envelope_size;
}
Ok(())
}
}
}