| /// The type corresponding to the {{ non_canonical_name }} protocol. |
| {{ self.doc_string(protocol.attributes) -}} |
| #[derive(PartialEq, |
| {% if self.emit_debug_impls() -%} |
| Debug, |
| {%- endif %} |
| )] |
| pub struct {{ protocol_name }}; |
| |
| {% if let Some(discoverable_name) = self.discoverable_name() %} |
| impl ::fidl_next::Discoverable for {{ protocol_name }} { |
| const PROTOCOL_NAME: &'static str = "{{ discoverable_name }}"; |
| } |
| {% endif %} |
| |
| pub mod {{ module_name }} { |
| pub mod prelude { |
| pub use crate::{ |
| {{ protocol_name }}, |
| {{ client_handler_name }}, |
| {{ server_handler_name }}, |
| {{ module_name }}, |
| }; |
| {% for ident in self.prelude_method_type_idents() %} |
| pub use {{ self.natural_id(ident) }}; |
| {% endfor %} |
| } |
| |
| {% for method in protocol.methods %} |
| {% let method_name = filters::escape_camel(method.name) %} |
| pub struct {{ method_name }}; |
| |
| impl ::fidl_next::Method for {{ method_name }} { |
| const ORDINAL: u64 = {{ method.ordinal }}; |
| |
| type Protocol = crate::{{ protocol_name }}; |
| |
| {% if method.kind == ProtocolMethodKind::OneWay || method.kind == ProtocolMethodKind::TwoWay %} |
| {% if let Some(request) = method.maybe_request_payload %} |
| type Request = {{ self.static_wire_type(request) }}; |
| {% else %} |
| type Request = (); |
| {% endif %} |
| {% else %} |
| type Request = ::fidl_next::Never; |
| {% endif %} |
| |
| type Response = |
| {% match method.kind %} |
| {% when ProtocolMethodKind::OneWay %} |
| ::fidl_next::Never |
| {% when ProtocolMethodKind::TwoWay %} |
| {% if method.has_error %} |
| {% if !method.is_strict %} |
| ::fidl_next::WireFlexibleResult |
| {% else %} |
| ::fidl_next::WireResult |
| {% endif %} |
| < |
| 'static, |
| {% if let Some(success) = method.maybe_response_success_type.as_ref() %} |
| {{ self.static_wire_type(success) }}, |
| {% else %} |
| (), |
| {% endif %} |
| {% if let Some(error) = method.maybe_response_err_type.as_ref() %} |
| {{ self.static_wire_type(error) }}, |
| {% else %} |
| (), |
| {% endif %} |
| > |
| {% else if !method.is_strict %} |
| ::fidl_next::WireFlexible< |
| 'static, |
| {% if let Some(success) = method.maybe_response_success_type.as_ref() %} |
| {{ self.static_wire_type(success) }} |
| {% else %} |
| () |
| {% endif %} |
| > |
| {% else %} |
| {% if let Some(response) = method.maybe_response_payload.as_ref() %} |
| {{ self.static_wire_type(response) }} |
| {% else %} |
| () |
| {% endif %} |
| {% endif %} |
| {% when ProtocolMethodKind::Event %} |
| {% if let Some(response) = method.maybe_response_payload.as_ref() %} |
| {{ self.static_wire_type(response) }} |
| {% else %} |
| () |
| {% endif %} |
| {% endmatch %} |
| ; |
| } |
| {% endfor %} |
| |
| mod ___detail { |
| {% for method in protocol.methods %} |
| {% if let Some(args) = self.get_method_args_struct(method) %} |
| {% let method_type_name = filters::escape_camel(method.name) %} |
| {% let is_static = args.shape.is_static() %} |
| |
| pub struct {{ method_type_name }}< |
| {% for i in 0..args.members.len() %} |
| T{{ i }}, |
| {% endfor %} |
| > { |
| {% for (i, member) in args.members.iter().enumerate() %} |
| {{ member.name|snake }}: T{{ i }}, |
| {% endfor %} |
| } |
| |
| impl< |
| {% for i in 0..args.members.len() %} |
| T{{ i }}, |
| {% endfor %} |
| > ::fidl_next::Encodable for {{ method_type_name }}< |
| {% for i in 0..args.members.len() %} |
| T{{ i }}, |
| {% endfor %} |
| > |
| where |
| {% for (i, member) in args.members.iter().enumerate() %} |
| T{{ i }}: ::fidl_next::Encodable<Encoded = {{ self.static_wire_type(member.ty) }}>, |
| {% endfor %} |
| { |
| type Encoded = {{ self.static_wire_type(method.maybe_request_payload.as_ref().or(method.maybe_response_payload.as_ref()).unwrap()) }}; |
| } |
| |
| unsafe impl< |
| ___E, |
| {% for i in 0..args.members.len() %} |
| T{{ i }}, |
| {% endfor %} |
| > ::fidl_next::Encode<___E> for {{ method_type_name }}< |
| {% for i in 0..args.members.len() %} |
| T{{ i }}, |
| {% endfor %} |
| > |
| where |
| ___E: ::fidl_next::encoder::InternalHandleEncoder + ?Sized, |
| {% if !is_static %} |
| ___E: ::fidl_next::Encoder, |
| {% endif %} |
| {% if args.is_resource %} |
| ___E: {{ self.encode_trait_path() }}, |
| {% endif %} |
| {% for (i, member) in args.members.iter().enumerate() %} |
| T{{ i }}: ::fidl_next::Encode<___E, Encoded = {{ self.static_wire_type(member.ty) }}>, |
| {% endfor %} |
| { |
| #[inline] |
| fn encode( |
| self, |
| encoder_: &mut ___E, |
| out_: &mut ::core::mem::MaybeUninit<Self::Encoded>, |
| ) -> ::core::result::Result<(), ::fidl_next::EncodeError> { |
| ::fidl_next::munge! { |
| let Self::Encoded { |
| {% for member in args.members -%} |
| {{ member.name|snake }}, |
| {% endfor %} |
| } = out_; |
| } |
| |
| {% for member in args.members %} |
| {% let member_name = filters::escape_snake(member.name) %} |
| ::fidl_next::Encode::encode(self.{{ member_name }}, encoder_, {{ member_name }})?; |
| {% endfor %} |
| Ok(()) |
| } |
| } |
| {% endif %} |
| {% endfor %} |
| |
| unsafe impl<___T> ::fidl_next::Protocol<___T> for crate::{{ protocol_name }} |
| where |
| ___T: ::fidl_next::Transport, |
| { |
| type Client = {{ client_name }}<___T>; |
| type Server = {{ server_name }}<___T>; |
| } |
| |
| /// The client for the `{{ non_canonical_name }}` protocol. |
| #[repr(transparent)] |
| pub struct {{ client_name }}<___T: ::fidl_next::Transport> { |
| #[allow(dead_code)] |
| client: ::fidl_next::protocol::Client<___T>, |
| } |
| |
| impl<___T> {{ client_name }}<___T> |
| where |
| ___T: ::fidl_next::Transport, |
| { |
| {% for method in protocol.methods %} |
| {% let method_name = filters::escape_snake(method.name) %} |
| {% let method_type_name = filters::escape_camel(method.name) %} |
| |
| {% match method.kind %} |
| {% when ProtocolMethodKind::OneWay %} |
| {% if let Some(args) = self.get_method_args_struct(method) %} |
| {% let is_static = args.shape.is_static() %} |
| |
| {{ self.doc_string(method.attributes) -}} |
| pub fn {{ method_name }}( |
| &self, |
| {% for member in args.members %} |
| {{ member.name|snake }}: impl ::fidl_next::Encode< |
| <___T as ::fidl_next::Transport>::SendBuffer, |
| Encoded = {{ self.static_wire_type(member.ty) }}, |
| >, |
| {% endfor %} |
| ) -> ::fidl_next::SendFuture<'_, ___T> |
| where |
| <___T as ::fidl_next::Transport>::SendBuffer: ::fidl_next::encoder::InternalHandleEncoder, |
| {% if !is_static %} |
| <___T as ::fidl_next::Transport>::SendBuffer: ::fidl_next::Encoder, |
| {% endif %} |
| {% if args.is_resource %} |
| <___T as ::fidl_next::Transport>::SendBuffer: {{ self.encode_trait_path() }}, |
| {% endif %} |
| { |
| self.{{ method_name }}_with({{ method_type_name }} { |
| {% for member in args.members %} |
| {{ member.name|snake }}, |
| {% endfor %} |
| }) |
| } |
| {% endif %} |
| |
| {{ self.doc_string(method.attributes) -}} |
| {% if let Some(request) = method.maybe_request_payload %} |
| pub fn {{ method_name }}_with<___R>( |
| &self, |
| request: ___R, |
| ) -> ::fidl_next::SendFuture<'_, ___T> |
| where |
| ___R: ::fidl_next::Encode< |
| <___T as ::fidl_next::Transport>::SendBuffer, |
| Encoded = {{ self.static_wire_type(request) }}, |
| >, |
| { |
| ::fidl_next::SendFuture::from_untyped( |
| self.client.send_one_way({{ method.ordinal }}, request) |
| ) |
| } |
| {% else %} |
| pub fn {{ method_name }}( |
| &self, |
| ) -> ::fidl_next::SendFuture<'_, ___T> { |
| ::fidl_next::SendFuture::from_untyped( |
| self.client.send_one_way({{ method.ordinal }}, ()) |
| ) |
| } |
| {% endif %} |
| {% when ProtocolMethodKind::TwoWay %} |
| {% if let Some(args) = self.get_method_args_struct(method) %} |
| {% let is_static = args.shape.is_static() %} |
| |
| {{ self.doc_string(method.attributes) -}} |
| pub fn {{ method_name }}( |
| &self, |
| {% for member in args.members %} |
| {{ member.name|snake }}: impl ::fidl_next::Encode< |
| <___T as ::fidl_next::Transport>::SendBuffer, |
| Encoded = {{ self.static_wire_type(member.ty) }}, |
| >, |
| {% endfor %} |
| ) -> ::fidl_next::TwoWayFuture<'_, super::{{ method_type_name }}, ___T> |
| where |
| <___T as ::fidl_next::Transport>::SendBuffer: ::fidl_next::encoder::InternalHandleEncoder, |
| {% if !is_static %} |
| <___T as ::fidl_next::Transport>::SendBuffer: ::fidl_next::Encoder, |
| {% endif %} |
| {% if args.is_resource %} |
| <___T as ::fidl_next::Transport>::SendBuffer: {{ self.encode_trait_path() }}, |
| {% endif %} |
| { |
| self.{{ method_name }}_with({{ method_type_name }} { |
| {% for member in args.members %} |
| {{ member.name|snake }}, |
| {% endfor %} |
| }) |
| } |
| {% endif %} |
| |
| {{ self.doc_string(method.attributes) -}} |
| {% if let Some(request) = method.maybe_request_payload %} |
| pub fn {{ method_name }}_with<___R>( |
| &self, |
| request: ___R, |
| ) -> ::fidl_next::TwoWayFuture<'_, super::{{ method_type_name }}, ___T> |
| where |
| ___R: ::fidl_next::Encode< |
| <___T as ::fidl_next::Transport>::SendBuffer, |
| Encoded = {{ self.static_wire_type(request) }}, |
| >, |
| { |
| ::fidl_next::TwoWayFuture::from_untyped( |
| self.client.send_two_way({{ method.ordinal }}, request) |
| ) |
| } |
| {% else %} |
| pub fn {{ method_name }}( |
| &self, |
| ) -> ::fidl_next::TwoWayFuture<'_, super::{{ method_type_name }}, ___T> { |
| ::fidl_next::TwoWayFuture::from_untyped( |
| self.client.send_two_way({{ method.ordinal }}, ()) |
| ) |
| } |
| {% endif %} |
| {% when ProtocolMethodKind::Event %} |
| {% endmatch %} |
| {% endfor %} |
| } |
| |
| /// The server for the `{{ non_canonical_name }}` protocol. |
| #[repr(transparent)] |
| pub struct {{ server_name }}<___T: ::fidl_next::Transport> { |
| server: ::fidl_next::protocol::Server<___T>, |
| } |
| |
| impl<___T> {{ server_name }}<___T> |
| where |
| ___T: ::fidl_next::Transport, |
| { |
| {% for method in protocol.methods %} |
| {% let method_name = filters::escape_snake(method.name) %} |
| {% let method_type_name = filters::escape_camel(method.name) %} |
| |
| {% if method.kind == ProtocolMethodKind::Event %} |
| {% if let Some(args) = self.get_method_args_struct(method) %} |
| {% let is_static = args.shape.is_static() %} |
| |
| {{ self.doc_string(method.attributes) -}} |
| pub fn {{ method_name }}( |
| &self, |
| {% for member in args.members %} |
| {{ member.name|snake }}: impl ::fidl_next::Encode< |
| <___T as ::fidl_next::Transport>::SendBuffer, |
| Encoded = {{ self.static_wire_type(member.ty) }}, |
| >, |
| {% endfor %} |
| ) -> ::fidl_next::SendFuture<'_, ___T> |
| where |
| <___T as ::fidl_next::Transport>::SendBuffer: ::fidl_next::encoder::InternalHandleEncoder, |
| {% if !is_static %} |
| <___T as ::fidl_next::Transport>::SendBuffer: ::fidl_next::Encoder, |
| {% endif %} |
| {% if args.is_resource %} |
| <___T as ::fidl_next::Transport>::SendBuffer: {{ self.encode_trait_path() }}, |
| {% endif %} |
| { |
| self.{{ method_name }}_with({{ method_type_name }} { |
| {% for member in args.members %} |
| {{ member.name|snake }}, |
| {% endfor %} |
| }) |
| } |
| {% endif %} |
| |
| {{ self.doc_string(method.attributes) -}} |
| {% if method.maybe_response_payload.is_some() %} |
| {% let method_type_name = filters::escape_camel(method.name) %} |
| pub fn {{ method_name }}_with<___R>( |
| &self, |
| request: ___R, |
| ) -> ::fidl_next::SendFuture<'_, ___T> |
| where |
| ___R: ::fidl_next::Encode< |
| <___T as ::fidl_next::Transport>::SendBuffer, |
| Encoded = <super::{{ method_type_name }} as ::fidl_next::Method>::Response, |
| >, |
| { |
| ::fidl_next::SendFuture::from_untyped( |
| self.server.send_event({{ method.ordinal }}, request) |
| ) |
| } |
| {% else %} |
| pub fn {{ method_name }}( |
| &self, |
| ) -> ::fidl_next::SendFuture<'_, ___T> { |
| ::fidl_next::SendFuture::from_untyped( |
| self.server.send_event({{ method.ordinal }}, ()) |
| ) |
| } |
| {% endif %} |
| {% endif %} |
| {% endfor %} |
| } |
| } |
| } |
| |
| /// A client handler for the {{ non_canonical_name }} protocol. |
| /// |
| /// See [`{{ protocol_name }}`] for more details. |
| pub trait {{ client_handler_name }}< |
| #[cfg(not(feature = "fuchsia"))] |
| ___T: ::fidl_next::Transport, |
| #[cfg(feature = "fuchsia")] |
| ___T: ::fidl_next::Transport = ::fidl_next::fuchsia::zx::Channel, |
| > { |
| {% for method in protocol.methods %} |
| {% if method.kind == ProtocolMethodKind::Event %} |
| {% let method_name = filters::escape_snake(method.name) %} |
| {% let method_type_name = filters::escape_camel(method.name) %} |
| |
| {{ self.doc_string(method.attributes) -}} |
| fn {{ method_name }}( |
| &mut self, |
| {% if method.maybe_response_payload.is_some() %} |
| event: ::fidl_next::Response<{{ module_name }}::{{ method_type_name }}, ___T>, |
| {% endif %} |
| ) -> impl ::core::future::Future<Output = ()> + ::core::marker::Send; |
| {% endif %} |
| {% endfor %} |
| |
| {% if protocol.openness != ProtocolOpenness::Closed %} |
| fn on_unknown_interaction( |
| &mut self, |
| ordinal: u64, |
| ) -> impl ::core::future::Future< |
| Output = ::core::result::Result< |
| (), |
| ::fidl_next::ProtocolError<<___T as ::fidl_next::Transport>::Error>, |
| > |
| > + ::core::marker::Send { |
| ::core::future::ready(Err(::fidl_next::ProtocolError::InvalidOrdinal(ordinal))) |
| } |
| {% endif %} |
| } |
| |
| impl<___H, ___T> ::fidl_next::DispatchClientMessage<___H, ___T> for {{ protocol_name }} |
| where |
| ___H: {{ client_handler_name }}<___T> + ::core::marker::Send, |
| ___T: ::fidl_next::Transport, |
| {% for method in protocol.methods %} |
| {% if method.maybe_response_payload.is_some() %} |
| {% let method_type_name = filters::escape_camel(method.name) %} |
| <{{ module_name }}::{{ method_type_name }} as ::fidl_next::Method>::Response: |
| ::fidl_next::Decode<<___T as ::fidl_next::Transport>::RecvBuffer>, |
| {% endif %} |
| {% endfor %} |
| { |
| async fn on_event( |
| handler: &mut ___H, |
| ordinal: u64, |
| buffer: ___T::RecvBuffer, |
| ) -> ::core::result::Result<(), ::fidl_next::ProtocolError<___T::Error>> { |
| match ordinal { |
| {% for method in protocol.methods %} |
| {% let method_name = filters::escape_snake(method.name) %} |
| {% if method.kind == ProtocolMethodKind::Event %} |
| {{ method.ordinal }} => { |
| {% if method.maybe_response_payload.is_some() %} |
| match ::fidl_next::DecoderExt::decode(buffer) { |
| Ok(decoded) => { |
| handler.{{ method_name }}(decoded).await; |
| Ok(()) |
| } |
| Err(error) => Err(::fidl_next::ProtocolError::InvalidMessage { |
| ordinal: {{ method.ordinal }}, |
| error, |
| }), |
| } |
| {% else %} |
| handler.{{ method_name}}().await; |
| Ok(()) |
| {% endif %} |
| } |
| {% endif %} |
| {% endfor %} |
| {% if protocol.openness != ProtocolOpenness::Closed %} |
| ordinal => handler.on_unknown_interaction(ordinal).await, |
| {% else %} |
| ordinal => Err(::fidl_next::ProtocolError::InvalidOrdinal(ordinal)), |
| {% endif %} |
| } |
| } |
| } |
| |
| /// A server handler for the {{ non_canonical_name }} protocol. |
| /// |
| /// See [`{{ protocol_name }}`] for more details. |
| pub trait {{ server_handler_name }}< |
| #[cfg(not(feature = "fuchsia"))] |
| ___T: ::fidl_next::Transport, |
| #[cfg(feature = "fuchsia")] |
| ___T: ::fidl_next::Transport = ::fidl_next::fuchsia::zx::Channel, |
| > { |
| {% for method in protocol.methods %} |
| {% let method_name = filters::escape_snake(method.name) %} |
| {% let method_type_name = filters::escape_camel(method.name) %} |
| |
| {% match method.kind %} |
| {% when ProtocolMethodKind::OneWay %} |
| {{ self.doc_string(method.attributes) -}} |
| fn {{ method_name }}( |
| &mut self, |
| {% if let Some(request) = method.maybe_request_payload %} |
| request: ::fidl_next::Request<{{ module_name }}::{{ method_type_name }}, ___T>, |
| {% endif %} |
| ) -> impl ::core::future::Future<Output = ()> + ::core::marker::Send; |
| {% when ProtocolMethodKind::TwoWay %} |
| {{ self.doc_string(method.attributes) -}} |
| fn {{ method_name }}( |
| &mut self, |
| {% if let Some(request) = method.maybe_request_payload %} |
| request: ::fidl_next::Request<{{ module_name }}::{{ method_type_name }}, ___T>, |
| {% endif %} |
| responder: ::fidl_next::Responder<{{ module_name }}::{{ method_type_name }}, ___T>, |
| ) -> impl ::core::future::Future<Output = ()> + ::core::marker::Send; |
| {% when ProtocolMethodKind::Event %} |
| {% endmatch %} |
| {% endfor %} |
| |
| {% if protocol.openness != ProtocolOpenness::Closed %} |
| fn on_unknown_interaction( |
| &mut self, |
| ordinal: u64, |
| ) -> impl ::core::future::Future< |
| Output = ::core::result::Result< |
| (), |
| ::fidl_next::ProtocolError<<___T as ::fidl_next::Transport>::Error>, |
| > |
| > + ::core::marker::Send { |
| ::core::future::ready(Err(::fidl_next::ProtocolError::InvalidOrdinal(ordinal))) |
| } |
| {% endif %} |
| } |
| |
| impl<___H, ___T> ::fidl_next::DispatchServerMessage<___H, ___T> for {{ protocol_name }} |
| where |
| ___H: {{ server_handler_name }}<___T> + ::core::marker::Send, |
| ___T: ::fidl_next::Transport, |
| {% for method in protocol.methods %} |
| {% if method.maybe_request_payload.is_some() %} |
| {% let method_type_name = filters::escape_camel(method.name) %} |
| <{{ module_name }}::{{ method_type_name }} as ::fidl_next::Method>::Request: |
| ::fidl_next::Decode<<___T as ::fidl_next::Transport>::RecvBuffer>, |
| {% endif %} |
| {% endfor %} |
| { |
| async fn on_one_way( |
| handler: &mut ___H, |
| ordinal: u64, |
| buffer: ___T::RecvBuffer, |
| ) -> ::core::result::Result<(), ::fidl_next::ProtocolError<<___T as ::fidl_next::Transport>::Error>> { |
| match ordinal { |
| {% for method in protocol.methods %} |
| {% let method_name = filters::escape_snake(method.name) %} |
| {% if method.kind == ProtocolMethodKind::OneWay %} |
| {{ method.ordinal }} => { |
| {% if let Some(request) = method.maybe_request_payload %} |
| match ::fidl_next::DecoderExt::decode(buffer) { |
| Ok(decoded) => { |
| handler.{{ method_name }}(decoded).await; |
| Ok(()) |
| } |
| Err(error) => Err(::fidl_next::ProtocolError::InvalidMessage { |
| ordinal: {{ method.ordinal }}, |
| error, |
| }), |
| } |
| {% else %} |
| handler.{{ method_name}}().await; |
| Ok(()) |
| {% endif %} |
| } |
| {% endif %} |
| {% endfor %} |
| {% if protocol.openness != ProtocolOpenness::Closed %} |
| ordinal => handler.on_unknown_interaction(ordinal).await, |
| {% else %} |
| ordinal => Err(::fidl_next::ProtocolError::InvalidOrdinal(ordinal)), |
| {% endif %} |
| } |
| } |
| |
| async fn on_two_way( |
| handler: &mut ___H, |
| ordinal: u64, |
| buffer: ___T::RecvBuffer, |
| responder: ::fidl_next::protocol::Responder<___T>, |
| ) -> ::core::result::Result<(), ::fidl_next::ProtocolError<<___T as ::fidl_next::Transport>::Error>> { |
| match ordinal { |
| {% for method in protocol.methods %} |
| {% let method_name = filters::escape_snake(method.name) %} |
| {% if method.kind == ProtocolMethodKind::TwoWay %} |
| {{ method.ordinal }} => { |
| let responder = ::fidl_next::Responder::from_untyped(responder); |
| {% if let Some(request) = method.maybe_request_payload %} |
| match ::fidl_next::DecoderExt::decode(buffer) { |
| Ok(decoded) => { |
| handler.{{ method_name }}(decoded, responder).await; |
| Ok(()) |
| } |
| Err(error) => Err(::fidl_next::ProtocolError::InvalidMessage { |
| ordinal: {{ method.ordinal }}, |
| error, |
| }), |
| } |
| {% else %} |
| handler.{{ method_name}}(responder).await; |
| Ok(()) |
| {% endif %} |
| } |
| {% endif %} |
| {% endfor %} |
| {% if protocol.openness != ProtocolOpenness::Closed %} |
| ordinal => handler.on_unknown_interaction(ordinal).await, |
| {% else %} |
| ordinal => Err(::fidl_next::ProtocolError::InvalidOrdinal(ordinal)), |
| {% endif %} |
| } |
| } |
| } |