fidl_next_bind/
decoded.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use fidl_next_codec::{Decoded, FromWire, IntoNatural, Wire};
6use fidl_next_protocol::Transport;
7
8use crate::HasTransport;
9
10use super::Method;
11
12/// A received FIDL message that will be handled by a client or server handler.
13pub struct Request<M: Method, T: Transport = <<M as Method>::Protocol as HasTransport>::Transport> {
14    decoded: Decoded<M::Request, T::RecvBuffer>,
15}
16
17impl<M: Method, T: Transport> Request<M, T> {
18    /// Creates a new `Request` from a decoded buffer.
19    pub fn from_decoded(decoded: Decoded<M::Request, T::RecvBuffer>) -> Self {
20        Self { decoded }
21    }
22
23    /// Returns the payload of the request.
24    pub fn payload(self) -> <M::Request as IntoNatural>::Natural
25    where
26        M::Request: Wire + IntoNatural,
27        <M::Request as IntoNatural>::Natural: for<'de> FromWire<<M::Request as Wire>::Owned<'de>>,
28    {
29        self.decoded.take()
30    }
31
32    /// Returns the payload of the request as a wire type.
33    pub fn wire_payload(self) -> Decoded<M::Request, T::RecvBuffer> {
34        self.decoded
35    }
36}